30#ifndef _GLIBCXX_MUTEX_H
31#define _GLIBCXX_MUTEX_H 1
34#pragma GCC system_header
37#if __cplusplus < 201103L
46namespace std _GLIBCXX_VISIBILITY(default)
48_GLIBCXX_BEGIN_NAMESPACE_VERSION
58#ifdef _GLIBCXX_HAS_GTHREADS
65 typedef __gthread_mutex_t __native_type;
67#ifdef __GTHREAD_MUTEX_INIT
68 __native_type _M_mutex = __GTHREAD_MUTEX_INIT;
70 constexpr __mutex_base() noexcept = default;
72 __native_type _M_mutex;
74 __mutex_base() noexcept
77 __GTHREAD_MUTEX_INIT_FUNCTION(&_M_mutex);
80 ~__mutex_base() noexcept { __gthread_mutex_destroy(&_M_mutex); }
83 __mutex_base(
const __mutex_base&) =
delete;
84 __mutex_base& operator=(
const __mutex_base&) =
delete;
99 class mutex :
private __mutex_base
102 typedef __native_type* native_handle_type;
104#ifdef __GTHREAD_MUTEX_INIT
107 mutex()
noexcept =
default;
116 int __e = __gthread_mutex_lock(&_M_mutex);
120 __throw_system_error(__e);
128 return !__gthread_mutex_trylock(&_M_mutex);
135 __gthread_mutex_unlock(&_M_mutex);
139 native_handle()
noexcept
140 {
return &_M_mutex; }
148 using timespec = __gthread_time_t;
153#ifndef __GTHREAD_COND_INIT
154 __GTHREAD_COND_INIT_FUNCTION(&_M_cond);
160 int __e __attribute__((__unused__)) = __gthread_cond_destroy(&_M_cond);
161 __glibcxx_assert(__e != EBUSY);
164 __condvar(
const __condvar&) =
delete;
165 __condvar& operator=(
const __condvar&) =
delete;
167 __gthread_cond_t* native_handle() noexcept {
return &_M_cond; }
173 int __e __attribute__((__unused__))
174 = __gthread_cond_wait(&_M_cond, __m.native_handle());
175 __glibcxx_assert(__e == 0);
179 wait_until(mutex& __m, timespec& __abs_time)
181 __gthread_cond_timedwait(&_M_cond, __m.native_handle(), &__abs_time);
184#ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
186 wait_until(mutex& __m, clockid_t __clock, timespec& __abs_time)
188 pthread_cond_clockwait(&_M_cond, __m.native_handle(), __clock,
194 notify_one() noexcept
196 int __e __attribute__((__unused__)) = __gthread_cond_signal(&_M_cond);
197 __glibcxx_assert(__e == 0);
201 notify_all() noexcept
203 int __e __attribute__((__unused__)) = __gthread_cond_broadcast(&_M_cond);
204 __glibcxx_assert(__e == 0);
208#ifdef __GTHREAD_COND_INIT
209 __gthread_cond_t _M_cond = __GTHREAD_COND_INIT;
211 __gthread_cond_t _M_cond;
217#pragma GCC diagnostic push
218#pragma GCC diagnostic ignored "-Wc++17-extensions"
221 template<
typename _Clock,
typename _Dur>
222 [[__nodiscard__]] _GLIBCXX14_CONSTEXPR
inline
224 __to_timeout_gthread_time_t(
const time_point<_Clock, _Dur>& __t)
226 auto __ts = chrono::__to_timeout_timespec(__t.time_since_epoch());
227 if constexpr (is_same<::timespec, __gthread_time_t>::value)
229 else if constexpr (is_convertible<::timespec, __gthread_time_t>::value)
231 else if constexpr (is_scalar<__gthread_time_t>::value)
232 return static_cast<__gthread_time_t
>(__ts.tv_sec);
234 return __gthread_time_t{ __ts.tv_sec, __ts.tv_nsec };
236#pragma GCC diagnostic pop
268 template<
typename _Mutex>
272 typedef _Mutex mutex_type;
275 explicit lock_guard(mutex_type& __m) : _M_device(__m)
276 { _M_device.lock(); }
283 { _M_device.unlock(); }
289 mutex_type& _M_device;
293_GLIBCXX_END_NAMESPACE_VERSION
constexpr try_to_lock_t try_to_lock
Tag used to prevent a scoped lock from blocking if a mutex is locked.
constexpr adopt_lock_t adopt_lock
Tag used to make a scoped lock take ownership of a locked mutex.
constexpr defer_lock_t defer_lock
Tag used to prevent a scoped lock from acquiring ownership of a mutex.
ISO C++ entities toplevel namespace is std.
Do not acquire ownership of the mutex.
Try to acquire ownership of the mutex without blocking.
Assume the calling thread has already obtained mutex ownership and manage it.
A simple scoped lock type.