30#ifndef _GLIBCXX_MUTEX_H
31#define _GLIBCXX_MUTEX_H 1
34#pragma GCC system_header
37#if __cplusplus < 201103L
45namespace std _GLIBCXX_VISIBILITY(default)
47_GLIBCXX_BEGIN_NAMESPACE_VERSION
57#ifdef _GLIBCXX_HAS_GTHREADS
64 typedef __gthread_mutex_t __native_type;
66#ifdef __GTHREAD_MUTEX_INIT
67 __native_type _M_mutex = __GTHREAD_MUTEX_INIT;
69 constexpr __mutex_base() noexcept = default;
71 __native_type _M_mutex;
73 __mutex_base() noexcept
76 __GTHREAD_MUTEX_INIT_FUNCTION(&_M_mutex);
79 ~__mutex_base() noexcept { __gthread_mutex_destroy(&_M_mutex); }
82 __mutex_base(
const __mutex_base&) =
delete;
83 __mutex_base& operator=(
const __mutex_base&) =
delete;
98 class mutex :
private __mutex_base
101 typedef __native_type* native_handle_type;
103#ifdef __GTHREAD_MUTEX_INIT
106 mutex()
noexcept =
default;
109 mutex(
const mutex&) =
delete;
110 mutex& operator=(
const mutex&) =
delete;
115 int __e = __gthread_mutex_lock(&_M_mutex);
119 __throw_system_error(__e);
127 return !__gthread_mutex_trylock(&_M_mutex);
134 __gthread_mutex_unlock(&_M_mutex);
138 native_handle()
noexcept
139 {
return &_M_mutex; }
147 using timespec = __gthread_time_t;
152#ifndef __GTHREAD_COND_INIT
153 __GTHREAD_COND_INIT_FUNCTION(&_M_cond);
159 int __e __attribute__((__unused__)) = __gthread_cond_destroy(&_M_cond);
160 __glibcxx_assert(__e != EBUSY);
163 __condvar(
const __condvar&) =
delete;
164 __condvar& operator=(
const __condvar&) =
delete;
166 __gthread_cond_t* native_handle() noexcept {
return &_M_cond; }
172 int __e __attribute__((__unused__))
173 = __gthread_cond_wait(&_M_cond, __m.native_handle());
174 __glibcxx_assert(__e == 0);
178 wait_until(mutex& __m, timespec& __abs_time)
180 __gthread_cond_timedwait(&_M_cond, __m.native_handle(), &__abs_time);
183#ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
185 wait_until(mutex& __m, clockid_t __clock, timespec& __abs_time)
187 pthread_cond_clockwait(&_M_cond, __m.native_handle(), __clock,
193 notify_one() noexcept
195 int __e __attribute__((__unused__)) = __gthread_cond_signal(&_M_cond);
196 __glibcxx_assert(__e == 0);
200 notify_all() noexcept
202 int __e __attribute__((__unused__)) = __gthread_cond_broadcast(&_M_cond);
203 __glibcxx_assert(__e == 0);
207#ifdef __GTHREAD_COND_INIT
208 __gthread_cond_t _M_cond = __GTHREAD_COND_INIT;
210 __gthread_cond_t _M_cond;
218 struct defer_lock_t {
explicit defer_lock_t() =
default; };
221 struct try_to_lock_t {
explicit try_to_lock_t() =
default; };
225 struct adopt_lock_t {
explicit adopt_lock_t() =
default; };
244 template<
typename _Mutex>
248 typedef _Mutex mutex_type;
251 explicit lock_guard(mutex_type& __m) : _M_device(__m)
252 { _M_device.lock(); }
255 lock_guard(mutex_type& __m,
adopt_lock_t) noexcept : _M_device(__m)
259 { _M_device.unlock(); }
261 lock_guard(
const lock_guard&) =
delete;
262 lock_guard& operator=(
const lock_guard&) =
delete;
265 mutex_type& _M_device;
269_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.