OSDN Git Service

PR libstdc++/50862
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / std / condition_variable
index ef22a1d..e17f326 100644 (file)
@@ -203,10 +203,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       void
       wait(_Lock& __lock)
       {
-        unique_lock<mutex> __my_lock(_M_mutex);
-        __lock.unlock();
-        _M_cond.wait(__my_lock);
-        __lock.lock();
+       // scoped unlock - unlocks in ctor, re-locks in dtor
+       struct _Unlock {
+         explicit _Unlock(_Lock& __lk) : _M_lock(__lk) { __lk.unlock(); }
+         ~_Unlock() { _M_lock.lock(); }
+         _Lock& _M_lock;
+       };
+
+       unique_lock<mutex> __my_lock(_M_mutex);
+       _Unlock __unlock(__lock);
+       // _M_mutex must be unlocked before re-locking __lock so move
+       // ownership of _M_mutex lock to an object with shorter lifetime.
+       unique_lock<mutex> __my_lock2(std::move(__my_lock));
+       _M_cond.wait(__my_lock2);
       }
       
 
@@ -254,10 +263,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       wait_for(_Lock& __lock,
               const chrono::duration<_Rep, _Period>& __rtime, _Predicate __p)
       { return wait_until(__lock, __clock_t::now() + __rtime, std::move(__p)); }
-
-    native_handle_type
-    native_handle()
-    { return _M_cond.native_handle(); }
   };
 
   // @} group condition_variables