diff options
author | Jonathan Wakely <jwakely.gcc@gmail.com> | 2013-07-21 19:21:03 +0000 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2013-07-21 20:21:03 +0100 |
commit | 3429db0fb07ae6f0fb09f72667f5dc0e818df349 (patch) | |
tree | faa1ebb885d503c2570ad7b5b434d21adfd16316 /libstdc++-v3/include/std/condition_variable | |
parent | d4aef883b7470379c369588dbea57315e1c67a4c (diff) | |
download | gcc-3429db0fb07ae6f0fb09f72667f5dc0e818df349.zip gcc-3429db0fb07ae6f0fb09f72667f5dc0e818df349.tar.gz gcc-3429db0fb07ae6f0fb09f72667f5dc0e818df349.tar.bz2 |
re PR libstdc++/54352 (relaxed data race rules for ~condition_variable_any)
PR libstdc++/54352
* include/std/condition_variable (condition_variable_any): Move into
inline namespace _V2 and replace mutex member with shared_ptr<mutex>.
* src/c++11/condition_variable.cc (condition_variable_any): Move
definitions to ...
* src/c++11/compatibility-condvar.cc (condition_variable_any): Here.
* src/Makefile.am: Add new source file.
* src/Makefile.in: Regenerate.
From-SVN: r201112
Diffstat (limited to 'libstdc++-v3/include/std/condition_variable')
-rw-r--r-- | libstdc++-v3/include/std/condition_variable | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/libstdc++-v3/include/std/condition_variable b/libstdc++-v3/include/std/condition_variable index 5284655..76a6e94 100644 --- a/libstdc++-v3/include/std/condition_variable +++ b/libstdc++-v3/include/std/condition_variable @@ -36,7 +36,12 @@ #else #include <chrono> -#include <mutex> // unique_lock +#include <mutex> +#include <ext/concurrence.h> +#include <bits/alloc_traits.h> +#include <bits/allocator.h> +#include <bits/unique_ptr.h> +#include <bits/shared_ptr.h> #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) @@ -165,13 +170,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } }; + inline namespace _V2 { + /// condition_variable_any // Like above, but mutex is not required to have try_lock. class condition_variable_any { typedef chrono::system_clock __clock_t; condition_variable _M_cond; - mutex _M_mutex; + shared_ptr<mutex> _M_mutex; // scoped unlock - unlocks in ctor, re-locks in dtor template<typename _Lock> @@ -194,9 +201,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; public: - - condition_variable_any() noexcept; - ~condition_variable_any() noexcept; + condition_variable_any() : _M_mutex(std::make_shared<mutex>()) { } + ~condition_variable_any() = default; condition_variable_any(const condition_variable_any&) = delete; condition_variable_any& operator=(const condition_variable_any&) = delete; @@ -204,14 +210,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION void notify_one() noexcept { - lock_guard<mutex> __lock(_M_mutex); + lock_guard<mutex> __lock(*_M_mutex); _M_cond.notify_one(); } void notify_all() noexcept { - lock_guard<mutex> __lock(_M_mutex); + lock_guard<mutex> __lock(*_M_mutex); _M_cond.notify_all(); } @@ -219,10 +225,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION void wait(_Lock& __lock) { - unique_lock<mutex> __my_lock(_M_mutex); + shared_ptr<mutex> __mutex = _M_mutex; + unique_lock<mutex> __my_lock(*__mutex); _Unlock<_Lock> __unlock(__lock); - // _M_mutex must be unlocked before re-locking __lock so move - // ownership of _M_mutex lock to an object with shorter lifetime. + // *__mutex must be unlocked before re-locking __lock so move + // ownership of *__mutex lock to an object with shorter lifetime. unique_lock<mutex> __my_lock2(std::move(__my_lock)); _M_cond.wait(__my_lock2); } @@ -241,10 +248,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION wait_until(_Lock& __lock, const chrono::time_point<_Clock, _Duration>& __atime) { - unique_lock<mutex> __my_lock(_M_mutex); + shared_ptr<mutex> __mutex = _M_mutex; + unique_lock<mutex> __my_lock(*__mutex); _Unlock<_Lock> __unlock(__lock); - // _M_mutex must be unlocked before re-locking __lock so move - // ownership of _M_mutex lock to an object with shorter lifetime. + // *__mutex must be unlocked before re-locking __lock so move + // ownership of *__mutex lock to an object with shorter lifetime. unique_lock<mutex> __my_lock2(std::move(__my_lock)); return _M_cond.wait_until(__my_lock2, __atime); } @@ -275,6 +283,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return wait_until(__lock, __clock_t::now() + __rtime, std::move(__p)); } }; + } // end inline namespace + // @} group condition_variables _GLIBCXX_END_NAMESPACE_VERSION } // namespace |