1 // <shared_mutex> -*- C++ -*-
3 // Copyright (C) 2013-2020 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file include/shared_mutex
26 * This is a Standard C++ Library header.
29 #ifndef _GLIBCXX_SHARED_MUTEX
30 #define _GLIBCXX_SHARED_MUTEX 1
32 #pragma GCC system_header
34 #if __cplusplus >= 201402L
36 #include <bits/c++config.h>
37 #include <condition_variable>
38 #include <bits/functexcept.h>
40 namespace std _GLIBCXX_VISIBILITY(default)
42 _GLIBCXX_BEGIN_NAMESPACE_VERSION
49 #ifdef _GLIBCXX_HAS_GTHREADS
51 #if __cplusplus >= 201703L
52 #define __cpp_lib_shared_mutex 201505
56 #define __cpp_lib_shared_timed_mutex 201402
57 class shared_timed_mutex;
59 /// @cond undocumented
61 #if _GLIBCXX_USE_PTHREAD_RWLOCK_T
63 #define _GLIBCXX_GTHRW(name) \
64 __gthrw(pthread_ ## name); \
66 __glibcxx_ ## name (pthread_rwlock_t *__rwlock) \
68 if (__gthread_active_p ()) \
69 return __gthrw_(pthread_ ## name) (__rwlock); \
73 _GLIBCXX_GTHRW(rwlock_rdlock)
74 _GLIBCXX_GTHRW(rwlock_tryrdlock)
75 _GLIBCXX_GTHRW(rwlock_wrlock)
76 _GLIBCXX_GTHRW(rwlock_trywrlock)
77 _GLIBCXX_GTHRW(rwlock_unlock)
78 # ifndef PTHREAD_RWLOCK_INITIALIZER
79 _GLIBCXX_GTHRW(rwlock_destroy)
80 __gthrw(pthread_rwlock_init);
82 __glibcxx_rwlock_init (pthread_rwlock_t *__rwlock)
84 if (__gthread_active_p ())
85 return __gthrw_(pthread_rwlock_init) (__rwlock, NULL);
90 # if _GTHREAD_USE_MUTEX_TIMEDLOCK
91 __gthrw(pthread_rwlock_timedrdlock);
93 __glibcxx_rwlock_timedrdlock (pthread_rwlock_t *__rwlock,
96 if (__gthread_active_p ())
97 return __gthrw_(pthread_rwlock_timedrdlock) (__rwlock, __ts);
101 __gthrw(pthread_rwlock_timedwrlock);
103 __glibcxx_rwlock_timedwrlock (pthread_rwlock_t *__rwlock,
104 const timespec *__ts)
106 if (__gthread_active_p ())
107 return __gthrw_(pthread_rwlock_timedwrlock) (__rwlock, __ts);
114 __glibcxx_rwlock_rdlock (pthread_rwlock_t *__rwlock)
115 { return pthread_rwlock_rdlock (__rwlock); }
117 __glibcxx_rwlock_tryrdlock (pthread_rwlock_t *__rwlock)
118 { return pthread_rwlock_tryrdlock (__rwlock); }
120 __glibcxx_rwlock_wrlock (pthread_rwlock_t *__rwlock)
121 { return pthread_rwlock_wrlock (__rwlock); }
123 __glibcxx_rwlock_trywrlock (pthread_rwlock_t *__rwlock)
124 { return pthread_rwlock_trywrlock (__rwlock); }
126 __glibcxx_rwlock_unlock (pthread_rwlock_t *__rwlock)
127 { return pthread_rwlock_unlock (__rwlock); }
129 __glibcxx_rwlock_destroy(pthread_rwlock_t *__rwlock)
130 { return pthread_rwlock_destroy (__rwlock); }
132 __glibcxx_rwlock_init(pthread_rwlock_t *__rwlock)
133 { return pthread_rwlock_init (__rwlock, NULL); }
134 # if _GTHREAD_USE_MUTEX_TIMEDLOCK
136 __glibcxx_rwlock_timedrdlock (pthread_rwlock_t *__rwlock,
137 const timespec *__ts)
138 { return pthread_rwlock_timedrdlock (__rwlock, __ts); }
140 __glibcxx_rwlock_timedwrlock (pthread_rwlock_t *__rwlock,
141 const timespec *__ts)
142 { return pthread_rwlock_timedwrlock (__rwlock, __ts); }
146 /// A shared mutex type implemented using pthread_rwlock_t.
147 class __shared_mutex_pthread
149 friend class shared_timed_mutex;
151 #ifdef PTHREAD_RWLOCK_INITIALIZER
152 pthread_rwlock_t _M_rwlock = PTHREAD_RWLOCK_INITIALIZER;
155 __shared_mutex_pthread() = default;
156 ~__shared_mutex_pthread() = default;
158 pthread_rwlock_t _M_rwlock;
161 __shared_mutex_pthread()
163 int __ret = __glibcxx_rwlock_init(&_M_rwlock);
166 else if (__ret == EAGAIN)
167 __throw_system_error(int(errc::resource_unavailable_try_again));
168 else if (__ret == EPERM)
169 __throw_system_error(int(errc::operation_not_permitted));
170 // Errors not handled: EBUSY, EINVAL
171 __glibcxx_assert(__ret == 0);
174 ~__shared_mutex_pthread()
176 int __ret __attribute((__unused__)) = __glibcxx_rwlock_destroy(&_M_rwlock);
177 // Errors not handled: EBUSY, EINVAL
178 __glibcxx_assert(__ret == 0);
182 __shared_mutex_pthread(const __shared_mutex_pthread&) = delete;
183 __shared_mutex_pthread& operator=(const __shared_mutex_pthread&) = delete;
188 int __ret = __glibcxx_rwlock_wrlock(&_M_rwlock);
189 if (__ret == EDEADLK)
190 __throw_system_error(int(errc::resource_deadlock_would_occur));
191 // Errors not handled: EINVAL
192 __glibcxx_assert(__ret == 0);
198 int __ret = __glibcxx_rwlock_trywrlock(&_M_rwlock);
199 if (__ret == EBUSY) return false;
200 // Errors not handled: EINVAL
201 __glibcxx_assert(__ret == 0);
208 int __ret __attribute((__unused__)) = __glibcxx_rwlock_unlock(&_M_rwlock);
209 // Errors not handled: EPERM, EBUSY, EINVAL
210 __glibcxx_assert(__ret == 0);
219 // We retry if we exceeded the maximum number of read locks supported by
220 // the POSIX implementation; this can result in busy-waiting, but this
221 // is okay based on the current specification of forward progress
222 // guarantees by the standard.
224 __ret = __glibcxx_rwlock_rdlock(&_M_rwlock);
225 while (__ret == EAGAIN);
226 if (__ret == EDEADLK)
227 __throw_system_error(int(errc::resource_deadlock_would_occur));
228 // Errors not handled: EINVAL
229 __glibcxx_assert(__ret == 0);
235 int __ret = __glibcxx_rwlock_tryrdlock(&_M_rwlock);
236 // If the maximum number of read locks has been exceeded, we just fail
237 // to acquire the lock. Unlike for lock(), we are not allowed to throw
239 if (__ret == EBUSY || __ret == EAGAIN) return false;
240 // Errors not handled: EINVAL
241 __glibcxx_assert(__ret == 0);
251 void* native_handle() { return &_M_rwlock; }
255 #if ! (_GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK)
256 /// A shared mutex type implemented using std::condition_variable.
257 class __shared_mutex_cv
259 friend class shared_timed_mutex;
261 // Based on Howard Hinnant's reference implementation from N2406.
263 // The high bit of _M_state is the write-entered flag which is set to
264 // indicate a writer has taken the lock or is queuing to take the lock.
265 // The remaining bits are the count of reader locks.
267 // To take a reader lock, block on gate1 while the write-entered flag is
268 // set or the maximum number of reader locks is held, then increment the
269 // reader lock count.
270 // To release, decrement the count, then if the write-entered flag is set
271 // and the count is zero then signal gate2 to wake a queued writer,
272 // otherwise if the maximum number of reader locks was held signal gate1
275 // To take a writer lock, block on gate1 while the write-entered flag is
276 // set, then set the write-entered flag to start queueing, then block on
277 // gate2 while the number of reader locks is non-zero.
278 // To release, unset the write-entered flag and signal gate1 to wake all
279 // blocked readers and writers.
281 // This means that when no reader locks are held readers and writers get
282 // equal priority. When one or more reader locks is held a writer gets
283 // priority and no more reader locks can be taken while the writer is
286 // Only locked when accessing _M_state or waiting on condition variables.
288 // Used to block while write-entered is set or reader count at maximum.
289 condition_variable _M_gate1;
290 // Used to block queued writers while reader count is non-zero.
291 condition_variable _M_gate2;
292 // The write-entered flag and reader count.
295 static constexpr unsigned _S_write_entered
296 = 1U << (sizeof(unsigned)*__CHAR_BIT__ - 1);
297 static constexpr unsigned _S_max_readers = ~_S_write_entered;
299 // Test whether the write-entered flag is set. _M_mut must be locked.
300 bool _M_write_entered() const { return _M_state & _S_write_entered; }
302 // The number of reader locks currently held. _M_mut must be locked.
303 unsigned _M_readers() const { return _M_state & _S_max_readers; }
306 __shared_mutex_cv() : _M_state(0) {}
310 __glibcxx_assert( _M_state == 0 );
313 __shared_mutex_cv(const __shared_mutex_cv&) = delete;
314 __shared_mutex_cv& operator=(const __shared_mutex_cv&) = delete;
316 // Exclusive ownership
321 unique_lock<mutex> __lk(_M_mut);
322 // Wait until we can set the write-entered flag.
323 _M_gate1.wait(__lk, [=]{ return !_M_write_entered(); });
324 _M_state |= _S_write_entered;
325 // Then wait until there are no more readers.
326 _M_gate2.wait(__lk, [=]{ return _M_readers() == 0; });
332 unique_lock<mutex> __lk(_M_mut, try_to_lock);
333 if (__lk.owns_lock() && _M_state == 0)
335 _M_state = _S_write_entered;
344 lock_guard<mutex> __lk(_M_mut);
345 __glibcxx_assert( _M_write_entered() );
347 // call notify_all() while mutex is held so that another thread can't
348 // lock and unlock the mutex then destroy *this before we make the call.
349 _M_gate1.notify_all();
357 unique_lock<mutex> __lk(_M_mut);
358 _M_gate1.wait(__lk, [=]{ return _M_state < _S_max_readers; });
365 unique_lock<mutex> __lk(_M_mut, try_to_lock);
366 if (!__lk.owns_lock())
368 if (_M_state < _S_max_readers)
379 lock_guard<mutex> __lk(_M_mut);
380 __glibcxx_assert( _M_readers() > 0 );
381 auto __prev = _M_state--;
382 if (_M_write_entered())
384 // Wake the queued writer if there are no more readers.
385 if (_M_readers() == 0)
386 _M_gate2.notify_one();
387 // No need to notify gate1 because we give priority to the queued
388 // writer, and that writer will eventually notify gate1 after it
389 // clears the write-entered flag.
393 // Wake any thread that was blocked on reader overflow.
394 if (__prev == _S_max_readers)
395 _M_gate1.notify_one();
402 #if __cplusplus > 201402L
403 /// The standard shared mutex type.
405 _GLIBCXX_THREAD_SAFETY_ANNOTATION(capability("shared_mutex")) shared_mutex
408 shared_mutex() = default;
409 ~shared_mutex() = default;
411 shared_mutex(const shared_mutex&) = delete;
412 shared_mutex& operator=(const shared_mutex&) = delete;
414 // Exclusive ownership
416 void lock() _GLIBCXX_THREAD_SAFETY_ANNOTATION(acquire_capability())
420 _GLIBCXX_THREAD_SAFETY_ANNOTATION(try_acquire_capability(true))
421 { return _M_impl.try_lock(); }
423 void unlock() _GLIBCXX_THREAD_SAFETY_ANNOTATION(release_capability())
424 { _M_impl.unlock(); }
429 _GLIBCXX_THREAD_SAFETY_ANNOTATION(acquire_shared_capability())
430 { _M_impl.lock_shared(); }
432 bool try_lock_shared()
433 _GLIBCXX_THREAD_SAFETY_ANNOTATION(try_acquire_shared_capability(true))
434 { return _M_impl.try_lock_shared(); }
437 _GLIBCXX_THREAD_SAFETY_ANNOTATION(release_shared_capability())
438 { _M_impl.unlock_shared(); }
440 #if _GLIBCXX_USE_PTHREAD_RWLOCK_T
441 typedef void* native_handle_type;
442 native_handle_type native_handle() { return _M_impl.native_handle(); }
445 __shared_mutex_pthread _M_impl;
448 __shared_mutex_cv _M_impl;
453 /// @cond undocumented
454 #if _GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK
455 using __shared_timed_mutex_base = __shared_mutex_pthread;
457 using __shared_timed_mutex_base = __shared_mutex_cv;
461 /// The standard shared timed mutex type.
462 class shared_timed_mutex
463 : private __shared_timed_mutex_base
465 using _Base = __shared_timed_mutex_base;
467 // Must use the same clock as condition_variable for __shared_mutex_cv.
468 #ifdef _GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK
469 using __clock_t = chrono::steady_clock;
471 using __clock_t = chrono::system_clock;
475 shared_timed_mutex() = default;
476 ~shared_timed_mutex() = default;
478 shared_timed_mutex(const shared_timed_mutex&) = delete;
479 shared_timed_mutex& operator=(const shared_timed_mutex&) = delete;
481 // Exclusive ownership
483 void lock() { _Base::lock(); }
484 bool try_lock() { return _Base::try_lock(); }
485 void unlock() { _Base::unlock(); }
487 template<typename _Rep, typename _Period>
489 try_lock_for(const chrono::duration<_Rep, _Period>& __rtime)
491 auto __rt = chrono::duration_cast<__clock_t::duration>(__rtime);
492 if (ratio_greater<__clock_t::period, _Period>())
494 return try_lock_until(__clock_t::now() + __rt);
499 void lock_shared() { _Base::lock_shared(); }
500 bool try_lock_shared() { return _Base::try_lock_shared(); }
501 void unlock_shared() { _Base::unlock_shared(); }
503 template<typename _Rep, typename _Period>
505 try_lock_shared_for(const chrono::duration<_Rep, _Period>& __rtime)
507 auto __rt = chrono::duration_cast<__clock_t::duration>(__rtime);
508 if (ratio_greater<__clock_t::period, _Period>())
510 return try_lock_shared_until(__clock_t::now() + __rt);
513 #if _GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK
515 // Exclusive ownership
517 template<typename _Duration>
519 try_lock_until(const chrono::time_point<chrono::system_clock,
522 auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
523 auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
525 __gthread_time_t __ts =
527 static_cast<std::time_t>(__s.time_since_epoch().count()),
528 static_cast<long>(__ns.count())
531 int __ret = __glibcxx_rwlock_timedwrlock(&_M_rwlock, &__ts);
532 // On self-deadlock, we just fail to acquire the lock. Technically,
533 // the program violated the precondition.
534 if (__ret == ETIMEDOUT || __ret == EDEADLK)
536 // Errors not handled: EINVAL
537 __glibcxx_assert(__ret == 0);
541 #ifdef _GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK
542 template<typename _Duration>
544 try_lock_until(const chrono::time_point<chrono::steady_clock,
547 auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
548 auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
550 __gthread_time_t __ts =
552 static_cast<std::time_t>(__s.time_since_epoch().count()),
553 static_cast<long>(__ns.count())
556 int __ret = pthread_rwlock_clockwrlock(&_M_rwlock, CLOCK_MONOTONIC,
558 // On self-deadlock, we just fail to acquire the lock. Technically,
559 // the program violated the precondition.
560 if (__ret == ETIMEDOUT || __ret == EDEADLK)
562 // Errors not handled: EINVAL
563 __glibcxx_assert(__ret == 0);
568 template<typename _Clock, typename _Duration>
570 try_lock_until(const chrono::time_point<_Clock, _Duration>& __atime)
572 #if __cplusplus > 201703L
573 static_assert(chrono::is_clock_v<_Clock>);
575 // The user-supplied clock may not tick at the same rate as
576 // steady_clock, so we must loop in order to guarantee that
577 // the timeout has expired before returning false.
578 typename _Clock::time_point __now = _Clock::now();
580 auto __rtime = __atime - __now;
581 if (try_lock_for(__rtime))
583 __now = _Clock::now();
584 } while (__atime > __now);
590 template<typename _Duration>
592 try_lock_shared_until(const chrono::time_point<chrono::system_clock,
595 auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
596 auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
598 __gthread_time_t __ts =
600 static_cast<std::time_t>(__s.time_since_epoch().count()),
601 static_cast<long>(__ns.count())
605 // Unlike for lock(), we are not allowed to throw an exception so if
606 // the maximum number of read locks has been exceeded, or we would
607 // deadlock, we just try to acquire the lock again (and will time out
609 // In cases where we would exceed the maximum number of read locks
610 // throughout the whole time until the timeout, we will fail to
611 // acquire the lock even if it would be logically free; however, this
612 // is allowed by the standard, and we made a "strong effort"
613 // (see C++14 30.4.1.4p26).
614 // For cases where the implementation detects a deadlock we
615 // intentionally block and timeout so that an early return isn't
616 // mistaken for a spurious failure, which might help users realise
617 // there is a deadlock.
619 __ret = __glibcxx_rwlock_timedrdlock(&_M_rwlock, &__ts);
620 while (__ret == EAGAIN || __ret == EDEADLK);
621 if (__ret == ETIMEDOUT)
623 // Errors not handled: EINVAL
624 __glibcxx_assert(__ret == 0);
628 #ifdef _GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK
629 template<typename _Duration>
631 try_lock_shared_until(const chrono::time_point<chrono::steady_clock,
634 auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
635 auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
637 __gthread_time_t __ts =
639 static_cast<std::time_t>(__s.time_since_epoch().count()),
640 static_cast<long>(__ns.count())
643 int __ret = pthread_rwlock_clockrdlock(&_M_rwlock, CLOCK_MONOTONIC,
645 // On self-deadlock, we just fail to acquire the lock. Technically,
646 // the program violated the precondition.
647 if (__ret == ETIMEDOUT || __ret == EDEADLK)
649 // Errors not handled: EINVAL
650 __glibcxx_assert(__ret == 0);
655 template<typename _Clock, typename _Duration>
657 try_lock_shared_until(const chrono::time_point<_Clock,
660 #if __cplusplus > 201703L
661 static_assert(chrono::is_clock_v<_Clock>);
663 // The user-supplied clock may not tick at the same rate as
664 // steady_clock, so we must loop in order to guarantee that
665 // the timeout has expired before returning false.
666 typename _Clock::time_point __now = _Clock::now();
668 auto __rtime = __atime - __now;
669 if (try_lock_shared_for(__rtime))
671 __now = _Clock::now();
672 } while (__atime > __now);
676 #else // ! (_GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK)
678 // Exclusive ownership
680 template<typename _Clock, typename _Duration>
682 try_lock_until(const chrono::time_point<_Clock, _Duration>& __abs_time)
684 unique_lock<mutex> __lk(_M_mut);
685 if (!_M_gate1.wait_until(__lk, __abs_time,
686 [=]{ return !_M_write_entered(); }))
690 _M_state |= _S_write_entered;
691 if (!_M_gate2.wait_until(__lk, __abs_time,
692 [=]{ return _M_readers() == 0; }))
694 _M_state ^= _S_write_entered;
695 // Wake all threads blocked while the write-entered flag was set.
696 _M_gate1.notify_all();
704 template <typename _Clock, typename _Duration>
706 try_lock_shared_until(const chrono::time_point<_Clock,
707 _Duration>& __abs_time)
709 unique_lock<mutex> __lk(_M_mut);
710 if (!_M_gate1.wait_until(__lk, __abs_time,
711 [=]{ return _M_state < _S_max_readers; }))
719 #endif // _GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK
721 #endif // _GLIBCXX_HAS_GTHREADS
724 template<typename _Mutex>
728 typedef _Mutex mutex_type;
732 shared_lock() noexcept : _M_pm(nullptr), _M_owns(false) { }
735 shared_lock(mutex_type& __m)
736 : _M_pm(std::__addressof(__m)), _M_owns(true)
737 { __m.lock_shared(); }
739 shared_lock(mutex_type& __m, defer_lock_t) noexcept
740 : _M_pm(std::__addressof(__m)), _M_owns(false) { }
742 shared_lock(mutex_type& __m, try_to_lock_t)
743 : _M_pm(std::__addressof(__m)), _M_owns(__m.try_lock_shared()) { }
745 shared_lock(mutex_type& __m, adopt_lock_t)
746 : _M_pm(std::__addressof(__m)), _M_owns(true) { }
748 template<typename _Clock, typename _Duration>
749 shared_lock(mutex_type& __m,
750 const chrono::time_point<_Clock, _Duration>& __abs_time)
751 : _M_pm(std::__addressof(__m)),
752 _M_owns(__m.try_lock_shared_until(__abs_time)) { }
754 template<typename _Rep, typename _Period>
755 shared_lock(mutex_type& __m,
756 const chrono::duration<_Rep, _Period>& __rel_time)
757 : _M_pm(std::__addressof(__m)),
758 _M_owns(__m.try_lock_shared_for(__rel_time)) { }
763 _M_pm->unlock_shared();
766 shared_lock(shared_lock const&) = delete;
767 shared_lock& operator=(shared_lock const&) = delete;
769 shared_lock(shared_lock&& __sl) noexcept : shared_lock()
773 operator=(shared_lock&& __sl) noexcept
775 shared_lock(std::move(__sl)).swap(*this);
783 _M_pm->lock_shared();
791 return _M_owns = _M_pm->try_lock_shared();
794 template<typename _Rep, typename _Period>
796 try_lock_for(const chrono::duration<_Rep, _Period>& __rel_time)
799 return _M_owns = _M_pm->try_lock_shared_for(__rel_time);
802 template<typename _Clock, typename _Duration>
804 try_lock_until(const chrono::time_point<_Clock, _Duration>& __abs_time)
807 return _M_owns = _M_pm->try_lock_shared_until(__abs_time);
814 __throw_system_error(int(errc::resource_deadlock_would_occur));
815 _M_pm->unlock_shared();
822 swap(shared_lock& __u) noexcept
824 std::swap(_M_pm, __u._M_pm);
825 std::swap(_M_owns, __u._M_owns);
832 return std::exchange(_M_pm, nullptr);
837 bool owns_lock() const noexcept { return _M_owns; }
839 explicit operator bool() const noexcept { return _M_owns; }
841 mutex_type* mutex() const noexcept { return _M_pm; }
847 if (_M_pm == nullptr)
848 __throw_system_error(int(errc::operation_not_permitted));
850 __throw_system_error(int(errc::resource_deadlock_would_occur));
857 /// Swap specialization for shared_lock
858 /// @relates shared_mutex
859 template<typename _Mutex>
861 swap(shared_lock<_Mutex>& __x, shared_lock<_Mutex>& __y) noexcept
865 _GLIBCXX_END_NAMESPACE_VERSION
870 #endif // _GLIBCXX_SHARED_MUTEX