30 #ifndef _GLIBCXX_MUTEX_H 31 #define _GLIBCXX_MUTEX_H 1 33 #pragma GCC system_header 35 #if __cplusplus < 201103L 41 #include <bits/gthr.h> 44 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 46 namespace std _GLIBCXX_VISIBILITY(default)
48 _GLIBCXX_BEGIN_NAMESPACE_VERSION
58 #ifdef _GLIBCXX_HAS_GTHREADS 63 typedef __gthread_mutex_t __native_type;
65 #ifdef __GTHREAD_MUTEX_INIT 66 __native_type _M_mutex = __GTHREAD_MUTEX_INIT;
68 constexpr __mutex_base() noexcept = default;
70 __native_type _M_mutex;
72 __mutex_base() noexcept
75 __GTHREAD_MUTEX_INIT_FUNCTION(&_M_mutex);
78 ~__mutex_base() noexcept { __gthread_mutex_destroy(&_M_mutex); }
81 __mutex_base(
const __mutex_base&) =
delete;
82 __mutex_base& operator=(
const __mutex_base&) =
delete;
86 class mutex :
private __mutex_base
89 typedef __native_type* native_handle_type;
91 #ifdef __GTHREAD_MUTEX_INIT 94 mutex() noexcept =
default;
103 int __e = __gthread_mutex_lock(&_M_mutex);
107 __throw_system_error(__e);
114 return !__gthread_mutex_trylock(&_M_mutex);
121 __gthread_mutex_unlock(&_M_mutex);
125 native_handle() noexcept
126 {
return &_M_mutex; }
129 #endif // _GLIBCXX_HAS_GTHREADS 155 template<
typename _Mutex>
159 typedef _Mutex mutex_type;
161 explicit lock_guard(mutex_type& __m) : _M_device(__m)
162 { _M_device.lock(); }
168 { _M_device.unlock(); }
174 mutex_type& _M_device;
184 template<
typename _Mutex>
188 typedef _Mutex mutex_type;
191 : _M_device(0), _M_owns(
false)
215 template<
typename _Clock,
typename _Duration>
219 _M_owns(_M_device->try_lock_until(__atime))
222 template<
typename _Rep,
typename _Period>
226 _M_owns(_M_device->try_lock_for(__rtime))
239 : _M_device(__u._M_device), _M_owns(__u._M_owns)
262 __throw_system_error(
int(errc::operation_not_permitted));
264 __throw_system_error(
int(errc::resource_deadlock_would_occur));
276 __throw_system_error(
int(errc::operation_not_permitted));
278 __throw_system_error(
int(errc::resource_deadlock_would_occur));
281 _M_owns = _M_device->try_lock();
286 template<
typename _Clock,
typename _Duration>
291 __throw_system_error(
int(errc::operation_not_permitted));
293 __throw_system_error(
int(errc::resource_deadlock_would_occur));
296 _M_owns = _M_device->try_lock_until(__atime);
301 template<
typename _Rep,
typename _Period>
306 __throw_system_error(
int(errc::operation_not_permitted));
308 __throw_system_error(
int(errc::resource_deadlock_would_occur));
311 _M_owns = _M_device->try_lock_for(__rtime);
320 __throw_system_error(
int(errc::operation_not_permitted));
331 std::swap(_M_device, __u._M_device);
332 std::swap(_M_owns, __u._M_owns);
338 mutex_type* __ret = _M_device;
345 owns_lock()
const noexcept
348 explicit operator bool()
const noexcept
349 {
return owns_lock(); }
352 mutex()
const noexcept
353 {
return _M_device; }
356 mutex_type* _M_device;
361 template<
typename _Mutex>
367 _GLIBCXX_END_NAMESPACE_VERSION
369 #endif // _GLIBCXX_USE_C99_STDINT_TR1 373 #endif // _GLIBCXX_MUTEX_H
Assume the calling thread has already obtained mutex ownership and manage it.
_GLIBCXX17_INLINE constexpr defer_lock_t defer_lock
Tag used to prevent a scoped lock from acquiring ownership of a mutex.
A movable scoped lock type.
Try to acquire ownership of the mutex without blocking.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
ISO C++ entities toplevel namespace is std.
_GLIBCXX17_INLINE constexpr adopt_lock_t adopt_lock
Tag used to make a scoped lock take ownership of a locked mutex.
A simple scoped lock type.
_GLIBCXX17_INLINE constexpr try_to_lock_t try_to_lock
Tag used to prevent a scoped lock from blocking if a mutex is locked.
Do not acquire ownership of the mutex.