diff options
author | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-07-21 19:21:03 +0000 |
---|---|---|
committer | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-07-21 19:21:03 +0000 |
commit | 429d379090af06b3f1dd9a027beb080b8ae68241 (patch) | |
tree | faa1ebb885d503c2570ad7b5b434d21adfd16316 /libstdc++-v3/include | |
parent | 4556c7f2f7df8120d675da54ab43b0c2503349ce (diff) | |
download | ppe42-gcc-429d379090af06b3f1dd9a027beb080b8ae68241.tar.gz ppe42-gcc-429d379090af06b3f1dd9a027beb080b8ae68241.zip |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@201112 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include')
-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 5284655139a..76a6e94e9d7 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 |