libstdc++: Encapsulate __gthread_cond_t as std::__condvar
authorJonathan Wakely <jwakely@redhat.com>
Wed, 25 Nov 2020 14:24:21 +0000 (14:24 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 25 Nov 2020 18:24:13 +0000 (18:24 +0000)
commit7d2a98a7273c423842a3935de64b15a6d6cb33bc
treeeb05723431613f512c017bcaabb585d9855a8fd9
parentf76cad692a62d44ed32d010200bad74f36c73092
libstdc++: Encapsulate __gthread_cond_t as std::__condvar

This introduces a new internal utility, std::__condvar, which is a
simplified form of std::condition_variable. It has no dependency on
<chrono> or std::unique_lock, which allows it to be used in
<bits/atomic_wait.h>.

This avoids repeating the #ifdef __GTHREAD_COND_INIT preprocessor
conditions and associated logic for initializing a __gthread_cond_t
correctly. It also encapsulates most of the __gthread_cond_xxx functions
as member functions of __condvar.

libstdc++-v3/ChangeLog:

* include/bits/atomic_timed_wait.h (__cond_wait_until_impl):
Do not define when _GLIBCXX_HAVE_LINUX_FUTEX is defined. Use
__condvar and mutex instead of __gthread_cond_t and
unique_lock<mutex>.
(__cond_wait_until): Likewise. Fix test for return value of
__cond_wait_until_impl.
(__timed_waiters::_M_do_wait_until): Use __condvar instead
of __gthread_cond_t.
* include/bits/atomic_wait.h: Remove <bits/unique_lock.h>
include. Only include <bits/std_mutex.h> if not using futexes.
(__platform_wait_max_value): Remove unused variable.
(__waiters::lock_t): Use lock_guard instead of unique_lock.
(__waiters::_M_cv): Use __condvar instead of __gthread_cond_t.
(__waiters::_M_do_wait(__platform_wait_t)): Likewise.
(__waiters::_M_notify()): Likewise. Use notify_one() if not
asked to notify all.
* include/bits/std_mutex.h (__condvar): New type.
* include/std/condition_variable (condition_variable::_M_cond)
(condition_variable::wait_until): Use __condvar instead of
__gthread_cond_t.
* src/c++11/condition_variable.cc (condition_variable): Define
default constructor and destructor as defaulted.
(condition_variable::wait, condition_variable::notify_one)
(condition_variable::notify_all): Forward to corresponding
member function of __condvar.
libstdc++-v3/include/bits/atomic_timed_wait.h
libstdc++-v3/include/bits/atomic_wait.h
libstdc++-v3/include/bits/std_mutex.h
libstdc++-v3/include/std/condition_variable
libstdc++-v3/src/c++11/condition_variable.cc