mutex 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. // <mutex> -*- C++ -*-
  2. // Copyright (C) 2003-2019 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file include/mutex
  21. * This is a Standard C++ Library header.
  22. */
  23. #ifndef _GLIBCXX_MUTEX
  24. #define _GLIBCXX_MUTEX 1
  25. #pragma GCC system_header
  26. #if __cplusplus < 201103L
  27. # include <bits/c++0x_warning.h>
  28. #else
  29. #include <tuple>
  30. #include <chrono>
  31. #include <exception>
  32. #include <type_traits>
  33. #include <system_error>
  34. #include <bits/std_mutex.h>
  35. #include <bits/unique_lock.h>
  36. #if ! _GTHREAD_USE_MUTEX_TIMEDLOCK
  37. # include <condition_variable>
  38. # include <thread>
  39. #endif
  40. #ifndef _GLIBCXX_HAVE_TLS
  41. # include <bits/std_function.h>
  42. #endif
  43. namespace std _GLIBCXX_VISIBILITY(default)
  44. {
  45. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  46. /**
  47. * @ingroup mutexes
  48. * @{
  49. */
  50. #ifdef _GLIBCXX_HAS_GTHREADS
  51. // Common base class for std::recursive_mutex and std::recursive_timed_mutex
  52. class __recursive_mutex_base
  53. {
  54. protected:
  55. typedef __gthread_recursive_mutex_t __native_type;
  56. __recursive_mutex_base(const __recursive_mutex_base&) = delete;
  57. __recursive_mutex_base& operator=(const __recursive_mutex_base&) = delete;
  58. #ifdef __GTHREAD_RECURSIVE_MUTEX_INIT
  59. __native_type _M_mutex = __GTHREAD_RECURSIVE_MUTEX_INIT;
  60. __recursive_mutex_base() = default;
  61. #else
  62. __native_type _M_mutex;
  63. __recursive_mutex_base()
  64. {
  65. // XXX EAGAIN, ENOMEM, EPERM, EBUSY(may), EINVAL(may)
  66. __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION(&_M_mutex);
  67. }
  68. ~__recursive_mutex_base()
  69. { __gthread_recursive_mutex_destroy(&_M_mutex); }
  70. #endif
  71. };
  72. /// The standard recursive mutex type.
  73. class recursive_mutex : private __recursive_mutex_base
  74. {
  75. public:
  76. typedef __native_type* native_handle_type;
  77. recursive_mutex() = default;
  78. ~recursive_mutex() = default;
  79. recursive_mutex(const recursive_mutex&) = delete;
  80. recursive_mutex& operator=(const recursive_mutex&) = delete;
  81. void
  82. lock()
  83. {
  84. int __e = __gthread_recursive_mutex_lock(&_M_mutex);
  85. // EINVAL, EAGAIN, EBUSY, EINVAL, EDEADLK(may)
  86. if (__e)
  87. __throw_system_error(__e);
  88. }
  89. bool
  90. try_lock() noexcept
  91. {
  92. // XXX EINVAL, EAGAIN, EBUSY
  93. return !__gthread_recursive_mutex_trylock(&_M_mutex);
  94. }
  95. void
  96. unlock()
  97. {
  98. // XXX EINVAL, EAGAIN, EBUSY
  99. __gthread_recursive_mutex_unlock(&_M_mutex);
  100. }
  101. native_handle_type
  102. native_handle() noexcept
  103. { return &_M_mutex; }
  104. };
  105. #if _GTHREAD_USE_MUTEX_TIMEDLOCK
  106. template<typename _Derived>
  107. class __timed_mutex_impl
  108. {
  109. protected:
  110. typedef chrono::high_resolution_clock __clock_t;
  111. template<typename _Rep, typename _Period>
  112. bool
  113. _M_try_lock_for(const chrono::duration<_Rep, _Period>& __rtime)
  114. {
  115. using chrono::steady_clock;
  116. auto __rt = chrono::duration_cast<steady_clock::duration>(__rtime);
  117. if (ratio_greater<steady_clock::period, _Period>())
  118. ++__rt;
  119. return _M_try_lock_until(steady_clock::now() + __rt);
  120. }
  121. template<typename _Duration>
  122. bool
  123. _M_try_lock_until(const chrono::time_point<__clock_t,
  124. _Duration>& __atime)
  125. {
  126. auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
  127. auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
  128. __gthread_time_t __ts = {
  129. static_cast<std::time_t>(__s.time_since_epoch().count()),
  130. static_cast<long>(__ns.count())
  131. };
  132. return static_cast<_Derived*>(this)->_M_timedlock(__ts);
  133. }
  134. template<typename _Clock, typename _Duration>
  135. bool
  136. _M_try_lock_until(const chrono::time_point<_Clock, _Duration>& __atime)
  137. {
  138. auto __rtime = __atime - _Clock::now();
  139. return _M_try_lock_until(__clock_t::now() + __rtime);
  140. }
  141. };
  142. /// The standard timed mutex type.
  143. class timed_mutex
  144. : private __mutex_base, public __timed_mutex_impl<timed_mutex>
  145. {
  146. public:
  147. typedef __native_type* native_handle_type;
  148. timed_mutex() = default;
  149. ~timed_mutex() = default;
  150. timed_mutex(const timed_mutex&) = delete;
  151. timed_mutex& operator=(const timed_mutex&) = delete;
  152. void
  153. lock()
  154. {
  155. int __e = __gthread_mutex_lock(&_M_mutex);
  156. // EINVAL, EAGAIN, EBUSY, EINVAL, EDEADLK(may)
  157. if (__e)
  158. __throw_system_error(__e);
  159. }
  160. bool
  161. try_lock() noexcept
  162. {
  163. // XXX EINVAL, EAGAIN, EBUSY
  164. return !__gthread_mutex_trylock(&_M_mutex);
  165. }
  166. template <class _Rep, class _Period>
  167. bool
  168. try_lock_for(const chrono::duration<_Rep, _Period>& __rtime)
  169. { return _M_try_lock_for(__rtime); }
  170. template <class _Clock, class _Duration>
  171. bool
  172. try_lock_until(const chrono::time_point<_Clock, _Duration>& __atime)
  173. { return _M_try_lock_until(__atime); }
  174. void
  175. unlock()
  176. {
  177. // XXX EINVAL, EAGAIN, EBUSY
  178. __gthread_mutex_unlock(&_M_mutex);
  179. }
  180. native_handle_type
  181. native_handle() noexcept
  182. { return &_M_mutex; }
  183. private:
  184. friend class __timed_mutex_impl<timed_mutex>;
  185. bool
  186. _M_timedlock(const __gthread_time_t& __ts)
  187. { return !__gthread_mutex_timedlock(&_M_mutex, &__ts); }
  188. };
  189. /// recursive_timed_mutex
  190. class recursive_timed_mutex
  191. : private __recursive_mutex_base,
  192. public __timed_mutex_impl<recursive_timed_mutex>
  193. {
  194. public:
  195. typedef __native_type* native_handle_type;
  196. recursive_timed_mutex() = default;
  197. ~recursive_timed_mutex() = default;
  198. recursive_timed_mutex(const recursive_timed_mutex&) = delete;
  199. recursive_timed_mutex& operator=(const recursive_timed_mutex&) = delete;
  200. void
  201. lock()
  202. {
  203. int __e = __gthread_recursive_mutex_lock(&_M_mutex);
  204. // EINVAL, EAGAIN, EBUSY, EINVAL, EDEADLK(may)
  205. if (__e)
  206. __throw_system_error(__e);
  207. }
  208. bool
  209. try_lock() noexcept
  210. {
  211. // XXX EINVAL, EAGAIN, EBUSY
  212. return !__gthread_recursive_mutex_trylock(&_M_mutex);
  213. }
  214. template <class _Rep, class _Period>
  215. bool
  216. try_lock_for(const chrono::duration<_Rep, _Period>& __rtime)
  217. { return _M_try_lock_for(__rtime); }
  218. template <class _Clock, class _Duration>
  219. bool
  220. try_lock_until(const chrono::time_point<_Clock, _Duration>& __atime)
  221. { return _M_try_lock_until(__atime); }
  222. void
  223. unlock()
  224. {
  225. // XXX EINVAL, EAGAIN, EBUSY
  226. __gthread_recursive_mutex_unlock(&_M_mutex);
  227. }
  228. native_handle_type
  229. native_handle() noexcept
  230. { return &_M_mutex; }
  231. private:
  232. friend class __timed_mutex_impl<recursive_timed_mutex>;
  233. bool
  234. _M_timedlock(const __gthread_time_t& __ts)
  235. { return !__gthread_recursive_mutex_timedlock(&_M_mutex, &__ts); }
  236. };
  237. #else // !_GTHREAD_USE_MUTEX_TIMEDLOCK
  238. /// timed_mutex
  239. class timed_mutex
  240. {
  241. mutex _M_mut;
  242. condition_variable _M_cv;
  243. bool _M_locked = false;
  244. public:
  245. timed_mutex() = default;
  246. ~timed_mutex() { __glibcxx_assert( !_M_locked ); }
  247. timed_mutex(const timed_mutex&) = delete;
  248. timed_mutex& operator=(const timed_mutex&) = delete;
  249. void
  250. lock()
  251. {
  252. unique_lock<mutex> __lk(_M_mut);
  253. _M_cv.wait(__lk, [&]{ return !_M_locked; });
  254. _M_locked = true;
  255. }
  256. bool
  257. try_lock()
  258. {
  259. lock_guard<mutex> __lk(_M_mut);
  260. if (_M_locked)
  261. return false;
  262. _M_locked = true;
  263. return true;
  264. }
  265. template<typename _Rep, typename _Period>
  266. bool
  267. try_lock_for(const chrono::duration<_Rep, _Period>& __rtime)
  268. {
  269. unique_lock<mutex> __lk(_M_mut);
  270. if (!_M_cv.wait_for(__lk, __rtime, [&]{ return !_M_locked; }))
  271. return false;
  272. _M_locked = true;
  273. return true;
  274. }
  275. template<typename _Clock, typename _Duration>
  276. bool
  277. try_lock_until(const chrono::time_point<_Clock, _Duration>& __atime)
  278. {
  279. unique_lock<mutex> __lk(_M_mut);
  280. if (!_M_cv.wait_until(__lk, __atime, [&]{ return !_M_locked; }))
  281. return false;
  282. _M_locked = true;
  283. return true;
  284. }
  285. void
  286. unlock()
  287. {
  288. lock_guard<mutex> __lk(_M_mut);
  289. __glibcxx_assert( _M_locked );
  290. _M_locked = false;
  291. _M_cv.notify_one();
  292. }
  293. };
  294. /// recursive_timed_mutex
  295. class recursive_timed_mutex
  296. {
  297. mutex _M_mut;
  298. condition_variable _M_cv;
  299. thread::id _M_owner;
  300. unsigned _M_count = 0;
  301. // Predicate type that tests whether the current thread can lock a mutex.
  302. struct _Can_lock
  303. {
  304. // Returns true if the mutex is unlocked or is locked by _M_caller.
  305. bool
  306. operator()() const noexcept
  307. { return _M_mx->_M_count == 0 || _M_mx->_M_owner == _M_caller; }
  308. const recursive_timed_mutex* _M_mx;
  309. thread::id _M_caller;
  310. };
  311. public:
  312. recursive_timed_mutex() = default;
  313. ~recursive_timed_mutex() { __glibcxx_assert( _M_count == 0 ); }
  314. recursive_timed_mutex(const recursive_timed_mutex&) = delete;
  315. recursive_timed_mutex& operator=(const recursive_timed_mutex&) = delete;
  316. void
  317. lock()
  318. {
  319. auto __id = this_thread::get_id();
  320. _Can_lock __can_lock{this, __id};
  321. unique_lock<mutex> __lk(_M_mut);
  322. _M_cv.wait(__lk, __can_lock);
  323. if (_M_count == -1u)
  324. __throw_system_error(EAGAIN); // [thread.timedmutex.recursive]/3
  325. _M_owner = __id;
  326. ++_M_count;
  327. }
  328. bool
  329. try_lock()
  330. {
  331. auto __id = this_thread::get_id();
  332. _Can_lock __can_lock{this, __id};
  333. lock_guard<mutex> __lk(_M_mut);
  334. if (!__can_lock())
  335. return false;
  336. if (_M_count == -1u)
  337. return false;
  338. _M_owner = __id;
  339. ++_M_count;
  340. return true;
  341. }
  342. template<typename _Rep, typename _Period>
  343. bool
  344. try_lock_for(const chrono::duration<_Rep, _Period>& __rtime)
  345. {
  346. auto __id = this_thread::get_id();
  347. _Can_lock __can_lock{this, __id};
  348. unique_lock<mutex> __lk(_M_mut);
  349. if (!_M_cv.wait_for(__lk, __rtime, __can_lock))
  350. return false;
  351. if (_M_count == -1u)
  352. return false;
  353. _M_owner = __id;
  354. ++_M_count;
  355. return true;
  356. }
  357. template<typename _Clock, typename _Duration>
  358. bool
  359. try_lock_until(const chrono::time_point<_Clock, _Duration>& __atime)
  360. {
  361. auto __id = this_thread::get_id();
  362. _Can_lock __can_lock{this, __id};
  363. unique_lock<mutex> __lk(_M_mut);
  364. if (!_M_cv.wait_until(__lk, __atime, __can_lock))
  365. return false;
  366. if (_M_count == -1u)
  367. return false;
  368. _M_owner = __id;
  369. ++_M_count;
  370. return true;
  371. }
  372. void
  373. unlock()
  374. {
  375. lock_guard<mutex> __lk(_M_mut);
  376. __glibcxx_assert( _M_owner == this_thread::get_id() );
  377. __glibcxx_assert( _M_count > 0 );
  378. if (--_M_count == 0)
  379. {
  380. _M_owner = {};
  381. _M_cv.notify_one();
  382. }
  383. }
  384. };
  385. #endif
  386. #endif // _GLIBCXX_HAS_GTHREADS
  387. template<typename _Lock>
  388. inline unique_lock<_Lock>
  389. __try_to_lock(_Lock& __l)
  390. { return unique_lock<_Lock>{__l, try_to_lock}; }
  391. template<int _Idx, bool _Continue = true>
  392. struct __try_lock_impl
  393. {
  394. template<typename... _Lock>
  395. static void
  396. __do_try_lock(tuple<_Lock&...>& __locks, int& __idx)
  397. {
  398. __idx = _Idx;
  399. auto __lock = std::__try_to_lock(std::get<_Idx>(__locks));
  400. if (__lock.owns_lock())
  401. {
  402. constexpr bool __cont = _Idx + 2 < sizeof...(_Lock);
  403. using __try_locker = __try_lock_impl<_Idx + 1, __cont>;
  404. __try_locker::__do_try_lock(__locks, __idx);
  405. if (__idx == -1)
  406. __lock.release();
  407. }
  408. }
  409. };
  410. template<int _Idx>
  411. struct __try_lock_impl<_Idx, false>
  412. {
  413. template<typename... _Lock>
  414. static void
  415. __do_try_lock(tuple<_Lock&...>& __locks, int& __idx)
  416. {
  417. __idx = _Idx;
  418. auto __lock = std::__try_to_lock(std::get<_Idx>(__locks));
  419. if (__lock.owns_lock())
  420. {
  421. __idx = -1;
  422. __lock.release();
  423. }
  424. }
  425. };
  426. /** @brief Generic try_lock.
  427. * @param __l1 Meets Lockable requirements (try_lock() may throw).
  428. * @param __l2 Meets Lockable requirements (try_lock() may throw).
  429. * @param __l3 Meets Lockable requirements (try_lock() may throw).
  430. * @return Returns -1 if all try_lock() calls return true. Otherwise returns
  431. * a 0-based index corresponding to the argument that returned false.
  432. * @post Either all arguments are locked, or none will be.
  433. *
  434. * Sequentially calls try_lock() on each argument.
  435. */
  436. template<typename _Lock1, typename _Lock2, typename... _Lock3>
  437. int
  438. try_lock(_Lock1& __l1, _Lock2& __l2, _Lock3&... __l3)
  439. {
  440. int __idx;
  441. auto __locks = std::tie(__l1, __l2, __l3...);
  442. __try_lock_impl<0>::__do_try_lock(__locks, __idx);
  443. return __idx;
  444. }
  445. /** @brief Generic lock.
  446. * @param __l1 Meets Lockable requirements (try_lock() may throw).
  447. * @param __l2 Meets Lockable requirements (try_lock() may throw).
  448. * @param __l3 Meets Lockable requirements (try_lock() may throw).
  449. * @throw An exception thrown by an argument's lock() or try_lock() member.
  450. * @post All arguments are locked.
  451. *
  452. * All arguments are locked via a sequence of calls to lock(), try_lock()
  453. * and unlock(). If the call exits via an exception any locks that were
  454. * obtained will be released.
  455. */
  456. template<typename _L1, typename _L2, typename... _L3>
  457. void
  458. lock(_L1& __l1, _L2& __l2, _L3&... __l3)
  459. {
  460. while (true)
  461. {
  462. using __try_locker = __try_lock_impl<0, sizeof...(_L3) != 0>;
  463. unique_lock<_L1> __first(__l1);
  464. int __idx;
  465. auto __locks = std::tie(__l2, __l3...);
  466. __try_locker::__do_try_lock(__locks, __idx);
  467. if (__idx == -1)
  468. {
  469. __first.release();
  470. return;
  471. }
  472. }
  473. }
  474. #if __cplusplus >= 201703L
  475. #define __cpp_lib_scoped_lock 201703
  476. /** @brief A scoped lock type for multiple lockable objects.
  477. *
  478. * A scoped_lock controls mutex ownership within a scope, releasing
  479. * ownership in the destructor.
  480. */
  481. template<typename... _MutexTypes>
  482. class scoped_lock
  483. {
  484. public:
  485. explicit scoped_lock(_MutexTypes&... __m) : _M_devices(std::tie(__m...))
  486. { std::lock(__m...); }
  487. explicit scoped_lock(adopt_lock_t, _MutexTypes&... __m) noexcept
  488. : _M_devices(std::tie(__m...))
  489. { } // calling thread owns mutex
  490. ~scoped_lock()
  491. {
  492. std::apply([](_MutexTypes&... __m) {
  493. char __i[] __attribute__((__unused__)) = { (__m.unlock(), 0)... };
  494. }, _M_devices);
  495. }
  496. scoped_lock(const scoped_lock&) = delete;
  497. scoped_lock& operator=(const scoped_lock&) = delete;
  498. private:
  499. tuple<_MutexTypes&...> _M_devices;
  500. };
  501. template<>
  502. class scoped_lock<>
  503. {
  504. public:
  505. explicit scoped_lock() = default;
  506. explicit scoped_lock(adopt_lock_t) noexcept { }
  507. ~scoped_lock() = default;
  508. scoped_lock(const scoped_lock&) = delete;
  509. scoped_lock& operator=(const scoped_lock&) = delete;
  510. };
  511. template<typename _Mutex>
  512. class scoped_lock<_Mutex>
  513. {
  514. public:
  515. using mutex_type = _Mutex;
  516. explicit scoped_lock(mutex_type& __m) : _M_device(__m)
  517. { _M_device.lock(); }
  518. explicit scoped_lock(adopt_lock_t, mutex_type& __m) noexcept
  519. : _M_device(__m)
  520. { } // calling thread owns mutex
  521. ~scoped_lock()
  522. { _M_device.unlock(); }
  523. scoped_lock(const scoped_lock&) = delete;
  524. scoped_lock& operator=(const scoped_lock&) = delete;
  525. private:
  526. mutex_type& _M_device;
  527. };
  528. #endif // C++17
  529. #ifdef _GLIBCXX_HAS_GTHREADS
  530. /// once_flag
  531. struct once_flag
  532. {
  533. private:
  534. typedef __gthread_once_t __native_type;
  535. __native_type _M_once = __GTHREAD_ONCE_INIT;
  536. public:
  537. /// Constructor
  538. constexpr once_flag() noexcept = default;
  539. /// Deleted copy constructor
  540. once_flag(const once_flag&) = delete;
  541. /// Deleted assignment operator
  542. once_flag& operator=(const once_flag&) = delete;
  543. template<typename _Callable, typename... _Args>
  544. friend void
  545. call_once(once_flag& __once, _Callable&& __f, _Args&&... __args);
  546. };
  547. #ifdef _GLIBCXX_HAVE_TLS
  548. extern __thread void* __once_callable;
  549. extern __thread void (*__once_call)();
  550. #else
  551. extern function<void()> __once_functor;
  552. extern void
  553. __set_once_functor_lock_ptr(unique_lock<mutex>*);
  554. extern mutex&
  555. __get_once_mutex();
  556. #endif
  557. extern "C" void __once_proxy(void);
  558. /// call_once
  559. template<typename _Callable, typename... _Args>
  560. void
  561. call_once(once_flag& __once, _Callable&& __f, _Args&&... __args)
  562. {
  563. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  564. // 2442. call_once() shouldn't DECAY_COPY()
  565. auto __callable = [&] {
  566. std::__invoke(std::forward<_Callable>(__f),
  567. std::forward<_Args>(__args)...);
  568. };
  569. #ifdef _GLIBCXX_HAVE_TLS
  570. __once_callable = std::__addressof(__callable);
  571. __once_call = []{ (*(decltype(__callable)*)__once_callable)(); };
  572. #else
  573. unique_lock<mutex> __functor_lock(__get_once_mutex());
  574. __once_functor = __callable;
  575. __set_once_functor_lock_ptr(&__functor_lock);
  576. #endif
  577. int __e = __gthread_once(&__once._M_once, &__once_proxy);
  578. #ifndef _GLIBCXX_HAVE_TLS
  579. if (__functor_lock)
  580. __set_once_functor_lock_ptr(0);
  581. #endif
  582. #ifdef __clang_analyzer__
  583. // PR libstdc++/82481
  584. __once_callable = nullptr;
  585. __once_call = nullptr;
  586. #endif
  587. if (__e)
  588. __throw_system_error(__e);
  589. }
  590. #endif // _GLIBCXX_HAS_GTHREADS
  591. // @} group mutexes
  592. _GLIBCXX_END_NAMESPACE_VERSION
  593. } // namespace
  594. #endif // C++11
  595. #endif // _GLIBCXX_MUTEX