30#ifndef _GLIBCXX_MUTEX_H
31#define _GLIBCXX_MUTEX_H 1
33#pragma GCC system_header
35#if __cplusplus < 201103L
43namespace std _GLIBCXX_VISIBILITY(default)
45_GLIBCXX_BEGIN_NAMESPACE_VERSION
55#ifdef _GLIBCXX_HAS_GTHREADS
62 typedef __gthread_mutex_t __native_type;
64#ifdef __GTHREAD_MUTEX_INIT
65 __native_type _M_mutex = __GTHREAD_MUTEX_INIT;
67 constexpr __mutex_base() noexcept = default;
69 __native_type _M_mutex;
71 __mutex_base() noexcept
74 __GTHREAD_MUTEX_INIT_FUNCTION(&_M_mutex);
77 ~__mutex_base() noexcept { __gthread_mutex_destroy(&_M_mutex); }
80 __mutex_base(
const __mutex_base&) =
delete;
81 __mutex_base& operator=(
const __mutex_base&) =
delete;
96 class mutex :
private __mutex_base
101#ifdef __GTHREAD_MUTEX_INIT
104 mutex()
noexcept =
default;
113 int __e = __gthread_mutex_lock(&_M_mutex);
117 __throw_system_error(__e);
124 return !__gthread_mutex_trylock(&_M_mutex);
131 __gthread_mutex_unlock(&_M_mutex);
135 native_handle()
noexcept
136 {
return &_M_mutex; }
149#ifndef __GTHREAD_COND_INIT
156 int __e __attribute__((__unused__)) = __gthread_cond_destroy(&_M_cond);
157 __glibcxx_assert(__e != EBUSY);
160 __condvar(
const __condvar&) =
delete;
161 __condvar& operator=(
const __condvar&) =
delete;
163 __gthread_cond_t* native_handle() noexcept {
return &_M_cond; }
169 int __e __attribute__((__unused__))
170 = __gthread_cond_wait(&_M_cond, __m.native_handle());
171 __glibcxx_assert(__e == 0);
175 wait_until(mutex& __m, timespec& __abs_time)
177 __gthread_cond_timedwait(&_M_cond, __m.native_handle(), &__abs_time);
180#ifdef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
182 wait_until(mutex& __m, clockid_t __clock, timespec& __abs_time)
184 pthread_cond_clockwait(&_M_cond, __m.native_handle(), __clock,
190 notify_one() noexcept
192 int __e __attribute__((__unused__)) = __gthread_cond_signal(&_M_cond);
193 __glibcxx_assert(__e == 0);
197 notify_all() noexcept
199 int __e __attribute__((__unused__)) = __gthread_cond_broadcast(&_M_cond);
200 __glibcxx_assert(__e == 0);
204#ifdef __GTHREAD_COND_INIT
205 __gthread_cond_t _M_cond = __GTHREAD_COND_INIT;
207 __gthread_cond_t _M_cond;
241 template<
typename _Mutex>
245 typedef _Mutex mutex_type;
248 { _M_device.lock(); }
254 { _M_device.unlock(); }
260 mutex_type& _M_device;
264_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.
An allocator that uses global new, as per C++03 [20.4.1].
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.