1// <shared_mutex> -*- C++ -*-
3// Copyright (C) 2013-2025 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
33#pragma GCC system_header
36#include <bits/requires_hosted.h> // concurrency
38#if __cplusplus >= 201402L
40#include <bits/chrono.h>
41#include <bits/error_constants.h>
42#include <bits/functexcept.h>
43#include <bits/move.h> // move, __exchange
44#include <bits/std_mutex.h> // defer_lock_t
46#define __glibcxx_want_shared_mutex
47#define __glibcxx_want_shared_timed_mutex
48#include <bits/version.h>
50#if ! (_GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK)
51# include <condition_variable>
54namespace std _GLIBCXX_VISIBILITY(default)
56_GLIBCXX_BEGIN_NAMESPACE_VERSION
63#ifdef _GLIBCXX_HAS_GTHREADS
65#ifdef __cpp_lib_shared_mutex // C++ >= 17 && hosted && gthread
69 class shared_timed_mutex;
71 /// @cond undocumented
73#if _GLIBCXX_USE_PTHREAD_RWLOCK_T
75#define _GLIBCXX_GTHRW(name) \
76 __gthrw(pthread_ ## name); \
78 __glibcxx_ ## name (pthread_rwlock_t *__rwlock) \
80 if (__gthread_active_p ()) \
81 return __gthrw_(pthread_ ## name) (__rwlock); \
85 _GLIBCXX_GTHRW(rwlock_rdlock)
86 _GLIBCXX_GTHRW(rwlock_tryrdlock)
87 _GLIBCXX_GTHRW(rwlock_wrlock)
88 _GLIBCXX_GTHRW(rwlock_trywrlock)
89 _GLIBCXX_GTHRW(rwlock_unlock)
90# ifndef PTHREAD_RWLOCK_INITIALIZER
91 _GLIBCXX_GTHRW(rwlock_destroy)
92 __gthrw(pthread_rwlock_init);
94 __glibcxx_rwlock_init (pthread_rwlock_t *__rwlock)
96 if (__gthread_active_p ())
97 return __gthrw_(pthread_rwlock_init) (__rwlock, NULL);
102# if _GTHREAD_USE_MUTEX_TIMEDLOCK
103 __gthrw(pthread_rwlock_timedrdlock);
105 __glibcxx_rwlock_timedrdlock (pthread_rwlock_t *__rwlock,
106 const timespec *__ts)
108 if (__gthread_active_p ())
109 return __gthrw_(pthread_rwlock_timedrdlock) (__rwlock, __ts);
113 __gthrw(pthread_rwlock_timedwrlock);
115 __glibcxx_rwlock_timedwrlock (pthread_rwlock_t *__rwlock,
116 const timespec *__ts)
118 if (__gthread_active_p ())
119 return __gthrw_(pthread_rwlock_timedwrlock) (__rwlock, __ts);
126 __glibcxx_rwlock_rdlock (pthread_rwlock_t *__rwlock)
127 { return pthread_rwlock_rdlock (__rwlock); }
129 __glibcxx_rwlock_tryrdlock (pthread_rwlock_t *__rwlock)
130 { return pthread_rwlock_tryrdlock (__rwlock); }
132 __glibcxx_rwlock_wrlock (pthread_rwlock_t *__rwlock)
133 { return pthread_rwlock_wrlock (__rwlock); }
135 __glibcxx_rwlock_trywrlock (pthread_rwlock_t *__rwlock)
136 { return pthread_rwlock_trywrlock (__rwlock); }
138 __glibcxx_rwlock_unlock (pthread_rwlock_t *__rwlock)
139 { return pthread_rwlock_unlock (__rwlock); }
141 __glibcxx_rwlock_destroy(pthread_rwlock_t *__rwlock)
142 { return pthread_rwlock_destroy (__rwlock); }
144 __glibcxx_rwlock_init(pthread_rwlock_t *__rwlock)
145 { return pthread_rwlock_init (__rwlock, NULL); }
146# if _GTHREAD_USE_MUTEX_TIMEDLOCK
148 __glibcxx_rwlock_timedrdlock (pthread_rwlock_t *__rwlock,
149 const timespec *__ts)
150 { return pthread_rwlock_timedrdlock (__rwlock, __ts); }
152 __glibcxx_rwlock_timedwrlock (pthread_rwlock_t *__rwlock,
153 const timespec *__ts)
154 { return pthread_rwlock_timedwrlock (__rwlock, __ts); }
158 /// A shared mutex type implemented using pthread_rwlock_t.
159 class __shared_mutex_pthread
161 friend class shared_timed_mutex;
163#ifdef PTHREAD_RWLOCK_INITIALIZER
164 pthread_rwlock_t _M_rwlock = PTHREAD_RWLOCK_INITIALIZER;
167 __shared_mutex_pthread() = default;
168 ~__shared_mutex_pthread() = default;
170 pthread_rwlock_t _M_rwlock;
173 __shared_mutex_pthread()
175 int __ret = __glibcxx_rwlock_init(&_M_rwlock);
178 else if (__ret == EAGAIN)
179 __throw_system_error(int(errc::resource_unavailable_try_again));
180 else if (__ret == EPERM)
181 __throw_system_error(int(errc::operation_not_permitted));
182 // Errors not handled: EBUSY, EINVAL
183 __glibcxx_assert(__ret == 0);
186 ~__shared_mutex_pthread()
188 int __ret __attribute((__unused__)) = __glibcxx_rwlock_destroy(&_M_rwlock);
189 // Errors not handled: EBUSY, EINVAL
190 __glibcxx_assert(__ret == 0);
194 __shared_mutex_pthread(const __shared_mutex_pthread&) = delete;
195 __shared_mutex_pthread& operator=(const __shared_mutex_pthread&) = delete;
200 int __ret = __glibcxx_rwlock_wrlock(&_M_rwlock);
201 if (__ret == EDEADLK)
202 __throw_system_error(int(errc::resource_deadlock_would_occur));
203 // Errors not handled: EINVAL
204 __glibcxx_assert(__ret == 0);
210 int __ret = __glibcxx_rwlock_trywrlock(&_M_rwlock);
211 if (__ret == EBUSY) return false;
212 // Errors not handled: EINVAL
213 __glibcxx_assert(__ret == 0);
220 int __ret __attribute((__unused__)) = __glibcxx_rwlock_unlock(&_M_rwlock);
221 // Errors not handled: EPERM, EBUSY, EINVAL
222 __glibcxx_assert(__ret == 0);
231 // We retry if we exceeded the maximum number of read locks supported by
232 // the POSIX implementation; this can result in busy-waiting, but this
233 // is okay based on the current specification of forward progress
234 // guarantees by the standard.
236 __ret = __glibcxx_rwlock_rdlock(&_M_rwlock);
237 while (__ret == EAGAIN);
238 if (__ret == EDEADLK)
239 __throw_system_error(int(errc::resource_deadlock_would_occur));
240 // Errors not handled: EINVAL
241 __glibcxx_assert(__ret == 0);
247 int __ret = __glibcxx_rwlock_tryrdlock(&_M_rwlock);
248 // If the maximum number of read locks has been exceeded, we just fail
249 // to acquire the lock. Unlike for lock(), we are not allowed to throw
251 if (__ret == EBUSY || __ret == EAGAIN) return false;
252 // Errors not handled: EINVAL
253 __glibcxx_assert(__ret == 0);
263 void* native_handle() { return &_M_rwlock; }
267#if ! (_GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK)
268 /// A shared mutex type implemented using std::condition_variable.
269 class __shared_mutex_cv
271 friend class shared_timed_mutex;
273 // Based on Howard Hinnant's reference implementation from N2406.
275 // The high bit of _M_state is the write-entered flag which is set to
276 // indicate a writer has taken the lock or is queuing to take the lock.
277 // The remaining bits are the count of reader locks.
279 // To take a reader lock, block on gate1 while the write-entered flag is
280 // set or the maximum number of reader locks is held, then increment the
281 // reader lock count.
282 // To release, decrement the count, then if the write-entered flag is set
283 // and the count is zero then signal gate2 to wake a queued writer,
284 // otherwise if the maximum number of reader locks was held signal gate1
287 // To take a writer lock, block on gate1 while the write-entered flag is
288 // set, then set the write-entered flag to start queueing, then block on
289 // gate2 while the number of reader locks is non-zero.
290 // To release, unset the write-entered flag and signal gate1 to wake all
291 // blocked readers and writers.
293 // This means that when no reader locks are held readers and writers get
294 // equal priority. When one or more reader locks is held a writer gets
295 // priority and no more reader locks can be taken while the writer is
298 // Only locked when accessing _M_state or waiting on condition variables.
300 // Used to block while write-entered is set or reader count at maximum.
301 condition_variable _M_gate1;
302 // Used to block queued writers while reader count is non-zero.
303 condition_variable _M_gate2;
304 // The write-entered flag and reader count.
307 static constexpr unsigned _S_write_entered
308 = 1U << (sizeof(unsigned)*__CHAR_BIT__ - 1);
309 static constexpr unsigned _S_max_readers = ~_S_write_entered;
311 // Test whether the write-entered flag is set. _M_mut must be locked.
312 bool _M_write_entered() const { return _M_state & _S_write_entered; }
314 // The number of reader locks currently held. _M_mut must be locked.
315 unsigned _M_readers() const { return _M_state & _S_max_readers; }
318 __shared_mutex_cv() : _M_state(0) {}
322 __glibcxx_assert( _M_state == 0 );
325 __shared_mutex_cv(const __shared_mutex_cv&) = delete;
326 __shared_mutex_cv& operator=(const __shared_mutex_cv&) = delete;
328 // Exclusive ownership
333 unique_lock<mutex> __lk(_M_mut);
334 // Wait until we can set the write-entered flag.
335 _M_gate1.wait(__lk, [this]{ return !_M_write_entered(); });
336 _M_state |= _S_write_entered;
337 // Then wait until there are no more readers.
338 _M_gate2.wait(__lk, [this]{ return _M_readers() == 0; });
344 unique_lock<mutex> __lk(_M_mut, try_to_lock);
345 if (__lk.owns_lock() && _M_state == 0)
347 _M_state = _S_write_entered;
356 lock_guard<mutex> __lk(_M_mut);
357 __glibcxx_assert( _M_write_entered() );
359 // call notify_all() while mutex is held so that another thread can't
360 // lock and unlock the mutex then destroy *this before we make the call.
361 _M_gate1.notify_all();
369 unique_lock<mutex> __lk(_M_mut);
370 _M_gate1.wait(__lk, [this]{ return _M_state < _S_max_readers; });
377 unique_lock<mutex> __lk(_M_mut, try_to_lock);
378 if (!__lk.owns_lock())
380 if (_M_state < _S_max_readers)
391 lock_guard<mutex> __lk(_M_mut);
392 __glibcxx_assert( _M_readers() > 0 );
393 auto __prev = _M_state--;
394 if (_M_write_entered())
396 // Wake the queued writer if there are no more readers.
397 if (_M_readers() == 0)
398 _M_gate2.notify_one();
399 // No need to notify gate1 because we give priority to the queued
400 // writer, and that writer will eventually notify gate1 after it
401 // clears the write-entered flag.
405 // Wake any thread that was blocked on reader overflow.
406 if (__prev == _S_max_readers)
407 _M_gate1.notify_one();
414#ifdef __cpp_lib_shared_mutex
415 /// The standard shared mutex type.
419 shared_mutex() = default;
420 ~shared_mutex() = default;
422 shared_mutex(const shared_mutex&) = delete;
423 shared_mutex& operator=(const shared_mutex&) = delete;
425 // Exclusive ownership
427 void lock() { _M_impl.lock(); }
428 [[nodiscard]] bool try_lock() { return _M_impl.try_lock(); }
429 void unlock() { _M_impl.unlock(); }
433 void lock_shared() { _M_impl.lock_shared(); }
434 [[nodiscard]] bool try_lock_shared() { return _M_impl.try_lock_shared(); }
435 void unlock_shared() { _M_impl.unlock_shared(); }
437#if _GLIBCXX_USE_PTHREAD_RWLOCK_T
438 typedef void* native_handle_type;
439 native_handle_type native_handle() { return _M_impl.native_handle(); }
442 __shared_mutex_pthread _M_impl;
445 __shared_mutex_cv _M_impl;
448#endif // __cpp_lib_shared_mutex
450 /// @cond undocumented
451#if _GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK
452 using __shared_timed_mutex_base = __shared_mutex_pthread;
454 using __shared_timed_mutex_base = __shared_mutex_cv;
458 /// The standard shared timed mutex type.
459 class shared_timed_mutex
460 : private __shared_timed_mutex_base
462 using _Base = __shared_timed_mutex_base;
464 // Must use the same clock as condition_variable for __shared_mutex_cv.
465#ifdef _GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK
466 using __clock_t = chrono::steady_clock;
468 using __clock_t = chrono::system_clock;
472 shared_timed_mutex() = default;
473 ~shared_timed_mutex() = default;
475 shared_timed_mutex(const shared_timed_mutex&) = delete;
476 shared_timed_mutex& operator=(const shared_timed_mutex&) = delete;
478 // Exclusive ownership
480 void lock() { _Base::lock(); }
481 _GLIBCXX_NODISCARD bool try_lock() { return _Base::try_lock(); }
482 void unlock() { _Base::unlock(); }
484 template<typename _Rep, typename _Period>
487 try_lock_for(const chrono::duration<_Rep, _Period>& __rtime)
489 auto __rt = chrono::duration_cast<__clock_t::duration>(__rtime);
490 if (ratio_greater<__clock_t::period, _Period>())
492 return try_lock_until(__clock_t::now() + __rt);
497 void lock_shared() { _Base::lock_shared(); }
499 bool try_lock_shared() { return _Base::try_lock_shared(); }
500 void unlock_shared() { _Base::unlock_shared(); }
502 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>
520 try_lock_until(const chrono::time_point<chrono::system_clock,
523 auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
524 auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
526 __gthread_time_t __ts =
528 static_cast<std::time_t>(__s.time_since_epoch().count()),
529 static_cast<long>(__ns.count())
532 int __ret = __glibcxx_rwlock_timedwrlock(&_M_rwlock, &__ts);
533 // On self-deadlock, we just fail to acquire the lock. Technically,
534 // the program violated the precondition.
535 if (__ret == ETIMEDOUT || __ret == EDEADLK)
537 // Errors not handled: EINVAL
538 __glibcxx_assert(__ret == 0);
542#ifdef _GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK
543 template<typename _Duration>
546 try_lock_until(const chrono::time_point<chrono::steady_clock,
549 auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
550 auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
552 __gthread_time_t __ts =
554 static_cast<std::time_t>(__s.time_since_epoch().count()),
555 static_cast<long>(__ns.count())
558 int __ret = pthread_rwlock_clockwrlock(&_M_rwlock, CLOCK_MONOTONIC,
560 // On self-deadlock, we just fail to acquire the lock. Technically,
561 // the program violated the precondition.
562 if (__ret == ETIMEDOUT || __ret == EDEADLK)
564 // Errors not handled: EINVAL
565 __glibcxx_assert(__ret == 0);
570 template<typename _Clock, typename _Duration>
573 try_lock_until(const chrono::time_point<_Clock, _Duration>& __atime)
575#if __cplusplus > 201703L
576 static_assert(chrono::is_clock_v<_Clock>);
578 // The user-supplied clock may not tick at the same rate as
579 // steady_clock, so we must loop in order to guarantee that
580 // the timeout has expired before returning false.
581 typename _Clock::time_point __now = _Clock::now();
583 auto __rtime = __atime - __now;
584 if (try_lock_for(__rtime))
586 __now = _Clock::now();
587 } while (__atime > __now);
593 template<typename _Duration>
596 try_lock_shared_until(const chrono::time_point<chrono::system_clock,
599 auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
600 auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
602 __gthread_time_t __ts =
604 static_cast<std::time_t>(__s.time_since_epoch().count()),
605 static_cast<long>(__ns.count())
609 // Unlike for lock(), we are not allowed to throw an exception so if
610 // the maximum number of read locks has been exceeded, or we would
611 // deadlock, we just try to acquire the lock again (and will time out
613 // In cases where we would exceed the maximum number of read locks
614 // throughout the whole time until the timeout, we will fail to
615 // acquire the lock even if it would be logically free; however, this
616 // is allowed by the standard, and we made a "strong effort"
617 // (see C++14 30.4.1.4p26).
618 // For cases where the implementation detects a deadlock we
619 // intentionally block and timeout so that an early return isn't
620 // mistaken for a spurious failure, which might help users realise
621 // there is a deadlock.
623 __ret = __glibcxx_rwlock_timedrdlock(&_M_rwlock, &__ts);
624 while (__ret == EAGAIN || __ret == EDEADLK);
625 if (__ret == ETIMEDOUT)
627 // Errors not handled: EINVAL
628 __glibcxx_assert(__ret == 0);
632#ifdef _GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK
633 template<typename _Duration>
636 try_lock_shared_until(const chrono::time_point<chrono::steady_clock,
639 auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
640 auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
642 __gthread_time_t __ts =
644 static_cast<std::time_t>(__s.time_since_epoch().count()),
645 static_cast<long>(__ns.count())
648 int __ret = pthread_rwlock_clockrdlock(&_M_rwlock, CLOCK_MONOTONIC,
650 // On self-deadlock, we just fail to acquire the lock. Technically,
651 // the program violated the precondition.
652 if (__ret == ETIMEDOUT || __ret == EDEADLK)
654 // Errors not handled: EINVAL
655 __glibcxx_assert(__ret == 0);
660 template<typename _Clock, typename _Duration>
663 try_lock_shared_until(const chrono::time_point<_Clock,
666#if __cplusplus > 201703L
667 static_assert(chrono::is_clock_v<_Clock>);
669 // The user-supplied clock may not tick at the same rate as
670 // steady_clock, so we must loop in order to guarantee that
671 // the timeout has expired before returning false.
672 typename _Clock::time_point __now = _Clock::now();
674 auto __rtime = __atime - __now;
675 if (try_lock_shared_for(__rtime))
677 __now = _Clock::now();
678 } while (__atime > __now);
682#else // ! (_GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK)
684 // Exclusive ownership
686 template<typename _Clock, typename _Duration>
689 try_lock_until(const chrono::time_point<_Clock, _Duration>& __abs_time)
691 unique_lock<mutex> __lk(_M_mut);
692 if (!_M_gate1.wait_until(__lk, __abs_time,
693 [this]{ return !_M_write_entered(); }))
697 _M_state |= _S_write_entered;
698 if (!_M_gate2.wait_until(__lk, __abs_time,
699 [this]{ return _M_readers() == 0; }))
701 _M_state ^= _S_write_entered;
702 // Wake all threads blocked while the write-entered flag was set.
703 _M_gate1.notify_all();
711 template <typename _Clock, typename _Duration>
714 try_lock_shared_until(const chrono::time_point<_Clock,
715 _Duration>& __abs_time)
717 unique_lock<mutex> __lk(_M_mut);
718 if (!_M_gate1.wait_until(__lk, __abs_time,
719 [this]{ return _M_state < _S_max_readers; }))
727#endif // _GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK
729#endif // _GLIBCXX_HAS_GTHREADS
732 template<typename _Mutex>
736 typedef _Mutex mutex_type;
740 shared_lock() noexcept : _M_pm(nullptr), _M_owns(false) { }
743 shared_lock(mutex_type& __m)
744 : _M_pm(std::__addressof(__m)), _M_owns(true)
745 { __m.lock_shared(); }
747 shared_lock(mutex_type& __m, defer_lock_t) noexcept
748 : _M_pm(std::__addressof(__m)), _M_owns(false) { }
750 shared_lock(mutex_type& __m, try_to_lock_t)
751 : _M_pm(std::__addressof(__m)), _M_owns(__m.try_lock_shared()) { }
753 shared_lock(mutex_type& __m, adopt_lock_t)
754 : _M_pm(std::__addressof(__m)), _M_owns(true) { }
756 template<typename _Clock, typename _Duration>
757 shared_lock(mutex_type& __m,
758 const chrono::time_point<_Clock, _Duration>& __abs_time)
759 : _M_pm(std::__addressof(__m)),
760 _M_owns(__m.try_lock_shared_until(__abs_time)) { }
762 template<typename _Rep, typename _Period>
763 shared_lock(mutex_type& __m,
764 const chrono::duration<_Rep, _Period>& __rel_time)
765 : _M_pm(std::__addressof(__m)),
766 _M_owns(__m.try_lock_shared_for(__rel_time)) { }
771 _M_pm->unlock_shared();
774 shared_lock(shared_lock const&) = delete;
775 shared_lock& operator=(shared_lock const&) = delete;
777 shared_lock(shared_lock&& __sl) noexcept : shared_lock()
781 operator=(shared_lock&& __sl) noexcept
783 // _GLIBCXX_RESOLVE_LIB_DEFECTS
784 // 4172. unique_lock self-move-assignment is broken
785 shared_lock(std::move(__sl)).swap(*this);
793 _M_pm->lock_shared();
802 return _M_owns = _M_pm->try_lock_shared();
805 template<typename _Rep, typename _Period>
808 try_lock_for(const chrono::duration<_Rep, _Period>& __rel_time)
811 return _M_owns = _M_pm->try_lock_shared_for(__rel_time);
814 template<typename _Clock, typename _Duration>
817 try_lock_until(const chrono::time_point<_Clock, _Duration>& __abs_time)
820 return _M_owns = _M_pm->try_lock_shared_until(__abs_time);
827 __throw_system_error(int(errc::operation_not_permitted));
828 _M_pm->unlock_shared();
835 swap(shared_lock& __u) noexcept
837 std::swap(_M_pm, __u._M_pm);
838 std::swap(_M_owns, __u._M_owns);
845 return std::__exchange(_M_pm, nullptr);
851 bool owns_lock() const noexcept { return _M_owns; }
853 explicit operator bool() const noexcept { return _M_owns; }
856 mutex_type* mutex() const noexcept { return _M_pm; }
862 if (_M_pm == nullptr)
863 __throw_system_error(int(errc::operation_not_permitted));
865 __throw_system_error(int(errc::resource_deadlock_would_occur));
872 /// Swap specialization for shared_lock
873 /// @relates shared_mutex
874 template<typename _Mutex>
876 swap(shared_lock<_Mutex>& __x, shared_lock<_Mutex>& __y) noexcept
880_GLIBCXX_END_NAMESPACE_VERSION
885#endif // _GLIBCXX_SHARED_MUTEX