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 | |
parent | e882a286d9ae615196afc52d72bed83549c24534 (diff) | |
download | gcc-742a7b1562e0c792fb303b9c3512d29ee437a850.tar.gz |
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')
12 files changed, 152 insertions, 23 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 65422238034..33d77900808 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,27 @@ +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. + 2010-01-28 François Dumont <francois.cppdevs@free.fr> * include/bits/stl_algobase.h (struct __iter_base): Add. diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver index 447b63ede49..4b5f6d0d246 100644 --- a/libstdc++-v3/config/abi/pre/gnu.ver +++ b/libstdc++-v3/config/abi/pre/gnu.ver @@ -1113,6 +1113,10 @@ GLIBCXX_3.4.14 { # std::time_get::_M_extract_wday_or_month _ZNKSt8time_getI[cw]St19istreambuf_iteratorI[cw]St11char_traitsI[cw]EEE24_M_extract_wday_or_month*; + # condition_variable_any::notify_* + _ZNSt22condition_variable_any10notify_allEv; + _ZNSt22condition_variable_any10notify_oneEv; + } GLIBCXX_3.4.13; # Symbols in the support library (libsupc++) have their own tag. 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, diff --git a/libstdc++-v3/src/condition_variable.cc b/libstdc++-v3/src/condition_variable.cc index 4fb2f179dfd..b4203799253 100644 --- a/libstdc++-v3/src/condition_variable.cc +++ b/libstdc++-v3/src/condition_variable.cc @@ -96,6 +96,28 @@ namespace std { __gthread_cond_destroy(&_M_cond); } + + void + condition_variable_any::notify_one() + { + int __e = __gthread_cond_signal(&_M_cond); + + // XXX not in spec + // EINVAL + if (__e) + __throw_system_error(__e); + } + + void + condition_variable_any::notify_all() + { + int __e = __gthread_cond_broadcast(&_M_cond); + + // XXX not in spec + // EINVAL + if (__e) + __throw_system_error(__e); + } } #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1 diff --git a/libstdc++-v3/testsuite/30_threads/condition_variable/cons/assign_neg.cc b/libstdc++-v3/testsuite/30_threads/condition_variable/cons/assign_neg.cc index 04e492b3f43..9e9ad8a7b03 100644 --- a/libstdc++-v3/testsuite/30_threads/condition_variable/cons/assign_neg.cc +++ b/libstdc++-v3/testsuite/30_threads/condition_variable/cons/assign_neg.cc @@ -32,4 +32,4 @@ void test01() } // { dg-error "used here" "" { target *-*-* } 31 } -// { dg-error "deleted function" "" { target *-*-* } 67 } +// { dg-error "deleted function" "" { target *-*-* } 70 } diff --git a/libstdc++-v3/testsuite/30_threads/condition_variable/cons/copy_neg.cc b/libstdc++-v3/testsuite/30_threads/condition_variable/cons/copy_neg.cc index 0d066282f1f..5765351554e 100644 --- a/libstdc++-v3/testsuite/30_threads/condition_variable/cons/copy_neg.cc +++ b/libstdc++-v3/testsuite/30_threads/condition_variable/cons/copy_neg.cc @@ -31,4 +31,4 @@ void test01() } // { dg-error "used here" "" { target *-*-* } 30 } -// { dg-error "deleted function" "" { target *-*-* } 66 } +// { dg-error "deleted function" "" { target *-*-* } 69 } diff --git a/libstdc++-v3/testsuite/30_threads/condition_variable/members/1.cc b/libstdc++-v3/testsuite/30_threads/condition_variable/members/1.cc index 4dea137064f..127960a625d 100644 --- a/libstdc++-v3/testsuite/30_threads/condition_variable/members/1.cc +++ b/libstdc++-v3/testsuite/30_threads/condition_variable/members/1.cc @@ -40,8 +40,8 @@ int main() std::unique_lock<std::mutex> l(m); auto then = std::chrono::system_clock::now(); - bool result = c1.wait_for(l, ms); - VERIFY( !result ); + std::cv_status result = c1.wait_for(l, ms); + VERIFY( result == std::cv_status::timeout ); VERIFY( (std::chrono::system_clock::now() - then) >= ms ); VERIFY( l.owns_lock() ); } diff --git a/libstdc++-v3/testsuite/30_threads/condition_variable/members/2.cc b/libstdc++-v3/testsuite/30_threads/condition_variable/members/2.cc index fe176668aa0..ab2e8776b84 100644 --- a/libstdc++-v3/testsuite/30_threads/condition_variable/members/2.cc +++ b/libstdc++-v3/testsuite/30_threads/condition_variable/members/2.cc @@ -40,8 +40,8 @@ int main() std::unique_lock<std::mutex> l(m); auto then = std::chrono::monotonic_clock::now(); - bool result = c1.wait_until(l, then + ms); - VERIFY( !result ); + std::cv_status result = c1.wait_until(l, then + ms); + VERIFY( result == std::cv_status::timeout ); VERIFY( (std::chrono::monotonic_clock::now() - then) >= ms ); VERIFY( l.owns_lock() ); } diff --git a/libstdc++-v3/testsuite/30_threads/condition_variable_any/cons/assign_neg.cc b/libstdc++-v3/testsuite/30_threads/condition_variable_any/cons/assign_neg.cc index 473f32639b3..5e3e30231b4 100644 --- a/libstdc++-v3/testsuite/30_threads/condition_variable_any/cons/assign_neg.cc +++ b/libstdc++-v3/testsuite/30_threads/condition_variable_any/cons/assign_neg.cc @@ -3,7 +3,7 @@ // { dg-require-cstdint "" } // { dg-require-gthreads "" } -// 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 @@ -32,4 +32,4 @@ void test01() } // { dg-error "used here" "" { target *-*-* } 31 } -// { dg-error "deleted function" "" { target *-*-* } 175 } +// { dg-error "deleted function" "" { target *-*-* } 178 } diff --git a/libstdc++-v3/testsuite/30_threads/condition_variable_any/cons/copy_neg.cc b/libstdc++-v3/testsuite/30_threads/condition_variable_any/cons/copy_neg.cc index 1d06c2ded3c..2b61c1b9621 100644 --- a/libstdc++-v3/testsuite/30_threads/condition_variable_any/cons/copy_neg.cc +++ b/libstdc++-v3/testsuite/30_threads/condition_variable_any/cons/copy_neg.cc @@ -3,7 +3,7 @@ // { dg-require-cstdint "" } // { dg-require-gthreads "" } -// 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 @@ -31,4 +31,4 @@ void test01() } // { dg-error "used here" "" { target *-*-* } 30 } -// { dg-error "deleted function" "" { target *-*-* } 174 } +// { dg-error "deleted function" "" { target *-*-* } 177 } diff --git a/libstdc++-v3/testsuite/30_threads/condition_variable_any/requirements/standard_layout.cc b/libstdc++-v3/testsuite/30_threads/condition_variable_any/requirements/standard_layout.cc new file mode 100644 index 00000000000..74e57ab354a --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/condition_variable_any/requirements/standard_layout.cc @@ -0,0 +1,30 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } + +// Copyright (C) 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 +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <condition_variable> +#include <testsuite_common_types.h> + +void test01() +{ + __gnu_test::standard_layout test; + test.operator()<std::condition_variable_any>(); +} diff --git a/libstdc++-v3/testsuite/30_threads/condition_variable_any/requirements/typedefs.cc b/libstdc++-v3/testsuite/30_threads/condition_variable_any/requirements/typedefs.cc new file mode 100644 index 00000000000..8a6fd82ccf6 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/condition_variable_any/requirements/typedefs.cc @@ -0,0 +1,30 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } + +// Copyright (C) 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 +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <condition_variable> + +void test01() +{ + // Check for required typedefs + typedef std::condition_variable_any test_type; + typedef test_type::native_handle_type type; +} |