File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -92,16 +92,22 @@ namespace dlib
9292 void wait (
9393 ) const
9494 {
95- std::unique_lock<std::mutex> cs (m.cs , std::defer_lock );
95+ std::unique_lock<std::mutex> cs (m.cs , std::adopt_lock );
9696 cv.wait (cs);
97+ // Make sure we don't actually modify the mutex. Since the calling code will have locked
98+ // it and it should remain locked.
99+ cs.release ();
97100 }
98101
99102 bool wait_or_timeout (
100103 unsigned long milliseconds
101104 ) const
102105 {
103- std::unique_lock<std::mutex> cs (m.cs , std::defer_lock );
106+ std::unique_lock<std::mutex> cs (m.cs , std::adopt_lock );
104107 auto status = cv.wait_until (cs, std::chrono::system_clock::now () + std::chrono::milliseconds (milliseconds));
108+ // Make sure we don't actually modify the mutex. Since the calling code will have locked
109+ // it and it should remain locked.
110+ cs.release ();
105111 return status == std::cv_status::no_timeout;
106112 }
107113
You can’t perform that action at this time.
0 commit comments