diff options
| author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-01-29 16:59:55 +0000 |
|---|---|---|
| committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-01-29 16:59:55 +0000 |
| commit | 742a7b1562e0c792fb303b9c3512d29ee437a850 (patch) | |
| tree | 04295ecc625cf3eb700770cbad2552ec3a84a2e3 /libstdc++-v3/include/std/condition_variable | |
| parent | e882a286d9ae615196afc52d72bed83549c24534 (diff) | |
| download | ppe42-gcc-742a7b1562e0c792fb303b9c3512d29ee437a850.tar.gz ppe42-gcc-742a7b1562e0c792fb303b9c3512d29ee437a850.zip | |
2010-01-29 Paolo Carlini <paolo.carlini@oracle.com>
* include/std/condition_variable (enum class cv_status): Add and
use it throughout, per N3000.
(condition_variable_any::wait<>(_Lock&), wait<>(_Lock&, _Predicate),
wait_until<>(_Lock&, const chrono::time_point<>&, _Predicate)):
Provide definitions.
* src/condition_variable.cc (condition_variable_any::notify_one,
condition_variable_any::notify_all): Likewise.
* config/abi/pre/gnu.ver: Export.
* testsuite/30_threads/condition_variable_any/requirements/
typedefs.cc: New.
* testsuite/30_threads/condition_variable_any/requirements/
standard_layout.cc: Likewise.
* testsuite/30_threads/condition_variable/members/1.cc: Adjust.
* testsuite/30_threads/condition_variable/members/2.cc: Likewise.
* testsuite/30_threads/condition_variable/cons/assign_neg.cc: Adjust
dg-error line numbers.
* testsuite/30_threads/condition_variable/cons/copy_neg.cc: Likewise.
* testsuite/30_threads/condition_variable_any/cons/assign_neg.cc:
Likewise.
* testsuite/30_threads/condition_variable_any/cons/copy_neg.cc:
Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@156358 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/std/condition_variable')
| -rw-r--r-- | libstdc++-v3/include/std/condition_variable | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/libstdc++-v3/include/std/condition_variable b/libstdc++-v3/include/std/condition_variable index f87eb1b8d1a..ea4570ee9a3 100644 --- a/libstdc++-v3/include/std/condition_variable +++ b/libstdc++-v3/include/std/condition_variable @@ -1,6 +1,6 @@ // <condition_variable> -*- C++ -*- -// Copyright (C) 2008, 2009 Free Software Foundation, Inc. +// Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -50,6 +50,9 @@ namespace std * @{ */ + /// cv_status + enum class cv_status { no_timeout, timeout }; + /// condition_variable class condition_variable { @@ -84,13 +87,13 @@ namespace std } template<typename _Duration> - bool + cv_status wait_until(unique_lock<mutex>& __lock, const chrono::time_point<__clock_t, _Duration>& __atime) { return __wait_until_impl(__lock, __atime); } template<typename _Clock, typename _Duration> - bool + cv_status wait_until(unique_lock<mutex>& __lock, const chrono::time_point<_Clock, _Duration>& __atime) { @@ -110,14 +113,13 @@ namespace std _Predicate __p) { while (!__p()) - if (!wait_until(__lock, __atime)) + if (wait_until(__lock, __atime) == cv_status::timeout) return __p(); - return true; } template<typename _Rep, typename _Period> - bool + cv_status wait_for(unique_lock<mutex>& __lock, const chrono::duration<_Rep, _Period>& __rtime) { return wait_until(__lock, __clock_t::now() + __rtime); } @@ -135,7 +137,7 @@ namespace std private: template<typename _Clock, typename _Duration> - bool + cv_status __wait_until_impl(unique_lock<mutex>& __lock, const chrono::time_point<_Clock, _Duration>& __atime) { @@ -154,7 +156,8 @@ namespace std __gthread_cond_timedwait(&_M_cond, __lock.mutex()->native_handle(), &__ts); - return _Clock::now() < __atime; + return (_Clock::now() < __atime + ? cv_status::no_timeout : cv_status::timeout); } }; @@ -182,14 +185,24 @@ namespace std template<typename _Lock> void - wait(_Lock& __lock); + wait(_Lock& __lock) + { + int __e = __gthread_cond_wait(&_M_cond, + __lock.mutex()->native_handle()); + if (__e) + __throw_system_error(__e); + } template<typename _Lock, typename _Predicate> void - wait(_Lock& __lock, _Predicate __p); + wait(_Lock& __lock, _Predicate __p) + { + while (!__p()) + wait(__lock); + } template<typename _Lock, typename _Clock, typename _Duration> - bool + cv_status wait_until(_Lock& __lock, const chrono::time_point<_Clock, _Duration>& __atime); @@ -198,10 +211,16 @@ namespace std bool wait_until(_Lock& __lock, const chrono::time_point<_Clock, _Duration>& __atime, - _Predicate __p); + _Predicate __p) + { + while (!__p()) + if (wait_until(__lock, __atime) == cv_status::timeout) + return __p(); + return true; + } template<typename _Lock, typename _Rep, typename _Period> - bool + cv_status wait_for(_Lock& __lock, const chrono::duration<_Rep, _Period>& __rtime); template<typename _Lock, typename _Rep, |

