1// <shared_mutex> -*- C++ -*-
3// Copyright (C) 2013-2023 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#include <bits/requires_hosted.h> // concurrency
36#if __cplusplus >= 201402L
38#include <bits/chrono.h>
39#include <bits/error_constants.h>
40#include <bits/functexcept.h>
41#include <bits/move.h> // move, __exchange
42#include <bits/std_mutex.h> // defer_lock_t
44#if ! (_GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK)
45# include <condition_variable>
48namespace std _GLIBCXX_VISIBILITY(default)
50_GLIBCXX_BEGIN_NAMESPACE_VERSION
57#ifdef _GLIBCXX_HAS_GTHREADS
59#if __cplusplus >= 201703L
60#define __cpp_lib_shared_mutex 201505L
64#define __cpp_lib_shared_timed_mutex 201402L
65 class shared_timed_mutex;
67 /// @cond undocumented
69#if _GLIBCXX_USE_PTHREAD_RWLOCK_T
71#define _GLIBCXX_GTHRW(name) \
72 __gthrw(pthread_ ## name); \
74 __glibcxx_ ## name (pthread_rwlock_t *__rwlock) \
76 if (__gthread_active_p ()) \
77 return __gthrw_(pthread_ ## name) (__rwlock); \
81 _GLIBCXX_GTHRW(rwlock_rdlock)
82 _GLIBCXX_GTHRW(rwlock_tryrdlock)
83 _GLIBCXX_GTHRW(rwlock_wrlock)
84 _GLIBCXX_GTHRW(rwlock_trywrlock)
85 _GLIBCXX_GTHRW(rwlock_unlock)
86# ifndef PTHREAD_RWLOCK_INITIALIZER
87 _GLIBCXX_GTHRW(rwlock_destroy)
88 __gthrw(pthread_rwlock_init);
90 __glibcxx_rwlock_init (pthread_rwlock_t *__rwlock)
92 if (__gthread_active_p ())
93 return __gthrw_(pthread_rwlock_init) (__rwlock, NULL);
98# if _GTHREAD_USE_MUTEX_TIMEDLOCK
99 __gthrw(pthread_rwlock_timedrdlock);
101 __glibcxx_rwlock_timedrdlock (pthread_rwlock_t *__rwlock,
102 const timespec *__ts)
104 if (__gthread_active_p ())
105 return __gthrw_(pthread_rwlock_timedrdlock) (__rwlock, __ts);
109 __gthrw(pthread_rwlock_timedwrlock);
111 __glibcxx_rwlock_timedwrlock (pthread_rwlock_t *__rwlock,
112 const timespec *__ts)
114 if (__gthread_active_p ())
115 return __gthrw_(pthread_rwlock_timedwrlock) (__rwlock, __ts);
122 __glibcxx_rwlock_rdlock (pthread_rwlock_t *__rwlock)
123 { return pthread_rwlock_rdlock (__rwlock); }
125 __glibcxx_rwlock_tryrdlock (pthread_rwlock_t *__rwlock)
126 { return pthread_rwlock_tryrdlock (__rwlock); }
128 __glibcxx_rwlock_wrlock (pthread_rwlock_t *__rwlock)
129 { return pthread_rwlock_wrlock (__rwlock); }
131 __glibcxx_rwlock_trywrlock (pthread_rwlock_t *__rwlock)
132 { return pthread_rwlock_trywrlock (__rwlock); }
134 __glibcxx_rwlock_unlock (pthread_rwlock_t *__rwlock)
135 { return pthread_rwlock_unlock (__rwlock); }
137 __glibcxx_rwlock_destroy(pthread_rwlock_t *__rwlock)
138 { return pthread_rwlock_destroy (__rwlock); }
140 __glibcxx_rwlock_init(pthread_rwlock_t *__rwlock)
141 { return pthread_rwlock_init (__rwlock, NULL); }
142# if _GTHREAD_USE_MUTEX_TIMEDLOCK
144 __glibcxx_rwlock_timedrdlock (pthread_rwlock_t *__rwlock,
145 const timespec *__ts)
146 { return pthread_rwlock_timedrdlock (__rwlock, __ts); }
148 __glibcxx_rwlock_timedwrlock (pthread_rwlock_t *__rwlock,
149 const timespec *__ts)
150 { return pthread_rwlock_timedwrlock (__rwlock, __ts); }
154 /// A shared mutex type implemented using pthread_rwlock_t.
155 class __shared_mutex_pthread
157 friend class shared_timed_mutex;
159#ifdef PTHREAD_RWLOCK_INITIALIZER
160 pthread_rwlock_t _M_rwlock = PTHREAD_RWLOCK_INITIALIZER;
163 __shared_mutex_pthread() = default;
164 ~__shared_mutex_pthread() = default;
166 pthread_rwlock_t _M_rwlock;
169 __shared_mutex_pthread()
171 int __ret = __glibcxx_rwlock_init(&_M_rwlock);
174 else if (__ret == EAGAIN)
175 __throw_system_error(int(errc::resource_unavailable_try_again));
176 else if (__ret == EPERM)
177 __throw_system_error(int(errc::operation_not_permitted));
178 // Errors not handled: EBUSY, EINVAL
179 __glibcxx_assert(__ret == 0);
182 ~__shared_mutex_pthread()
184 int __ret __attribute((__unused__)) = __glibcxx_rwlock_destroy(&_M_rwlock);
185 // Errors not handled: EBUSY, EINVAL
186 __glibcxx_assert(__ret == 0);
190 __shared_mutex_pthread(const __shared_mutex_pthread&) = delete;
191 __shared_mutex_pthread& operator=(const __shared_mutex_pthread&) = delete;
196 int __ret = __glibcxx_rwlock_wrlock(&_M_rwlock);
197 if (__ret == EDEADLK)
198 __throw_system_error(int(errc::resource_deadlock_would_occur));
199 // Errors not handled: EINVAL
200 __glibcxx_assert(__ret == 0);
206 int __ret = __glibcxx_rwlock_trywrlock(&_M_rwlock);
207 if (__ret == EBUSY) return false;
208 // Errors not handled: EINVAL
209 __glibcxx_assert(__ret == 0);
216 int __ret __attribute((__unused__)) = __glibcxx_rwlock_unlock(&_M_rwlock);
217 // Errors not handled: EPERM, EBUSY, EINVAL
218 __glibcxx_assert(__ret == 0);
227 // We retry if we exceeded the maximum number of read locks supported by
228 // the POSIX implementation; this can result in busy-waiting, but this
229 // is okay based on the current specification of forward progress
230 // guarantees by the standard.
232 __ret = __glibcxx_rwlock_rdlock(&_M_rwlock);
233 while (__ret == EAGAIN);
234 if (__ret == EDEADLK)
235 __throw_system_error(int(errc::resource_deadlock_would_occur));
236 // Errors not handled: EINVAL
237 __glibcxx_assert(__ret == 0);
243 int __ret = __glibcxx_rwlock_tryrdlock(&_M_rwlock);
244 // If the maximum number of read locks has been exceeded, we just fail
245 // to acquire the lock. Unlike for lock(), we are not allowed to throw
247 if (__ret == EBUSY || __ret == EAGAIN) return false;
248 // Errors not handled: EINVAL
249 __glibcxx_assert(__ret == 0);
259 void* native_handle() { return &_M_rwlock; }
263#if ! (_GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK)
264 /// A shared mutex type implemented using std::condition_variable.
265 class __shared_mutex_cv
267 friend class shared_timed_mutex;
269 // Based on Howard Hinnant's reference implementation from N2406.
271 // The high bit of _M_state is the write-entered flag which is set to
272 // indicate a writer has taken the lock or is queuing to take the lock.
273 // The remaining bits are the count of reader locks.
275 // To take a reader lock, block on gate1 while the write-entered flag is
276 // set or the maximum number of reader locks is held, then increment the
277 // reader lock count.
278 // To release, decrement the count, then if the write-entered flag is set
279 // and the count is zero then signal gate2 to wake a queued writer,
280 // otherwise if the maximum number of reader locks was held signal gate1
283 // To take a writer lock, block on gate1 while the write-entered flag is
284 // set, then set the write-entered flag to start queueing, then block on
285 // gate2 while the number of reader locks is non-zero.
286 // To release, unset the write-entered flag and signal gate1 to wake all
287 // blocked readers and writers.
289 // This means that when no reader locks are held readers and writers get
290 // equal priority. When one or more reader locks is held a writer gets
291 // priority and no more reader locks can be taken while the writer is
294 // Only locked when accessing _M_state or waiting on condition variables.
296 // Used to block while write-entered is set or reader count at maximum.
297 condition_variable _M_gate1;
298 // Used to block queued writers while reader count is non-zero.
299 condition_variable _M_gate2;
300 // The write-entered flag and reader count.
303 static constexpr unsigned _S_write_entered
304 = 1U << (sizeof(unsigned)*__CHAR_BIT__ - 1);
305 static constexpr unsigned _S_max_readers = ~_S_write_entered;
307 // Test whether the write-entered flag is set. _M_mut must be locked.
308 bool _M_write_entered() const { return _M_state & _S_write_entered; }
310 // The number of reader locks currently held. _M_mut must be locked.
311 unsigned _M_readers() const { return _M_state & _S_max_readers; }
314 __shared_mutex_cv() : _M_state(0) {}
318 __glibcxx_assert( _M_state == 0 );
321 __shared_mutex_cv(const __shared_mutex_cv&) = delete;
322 __shared_mutex_cv& operator=(const __shared_mutex_cv&) = delete;
324 // Exclusive ownership
329 unique_lock<mutex> __lk(_M_mut);
330 // Wait until we can set the write-entered flag.
331 _M_gate1.wait(__lk, [=]{ return !_M_write_entered(); });
332 _M_state |= _S_write_entered;
333 // Then wait until there are no more readers.
334 _M_gate2.wait(__lk, [=]{ return _M_readers() == 0; });
340 unique_lock<mutex> __lk(_M_mut, try_to_lock);
341 if (__lk.owns_lock() && _M_state == 0)
343 _M_state = _S_write_entered;
352 lock_guard<mutex> __lk(_M_mut);
353 __glibcxx_assert( _M_write_entered() );
355 // call notify_all() while mutex is held so that another thread can't
356 // lock and unlock the mutex then destroy *this before we make the call.
357 _M_gate1.notify_all();
365 unique_lock<mutex> __lk(_M_mut);
366 _M_gate1.wait(__lk, [=]{ return _M_state < _S_max_readers; });
373 unique_lock<mutex> __lk(_M_mut, try_to_lock);
374 if (!__lk.owns_lock())
376 if (_M_state < _S_max_readers)
387 lock_guard<mutex> __lk(_M_mut);
388 __glibcxx_assert( _M_readers() > 0 );
389 auto __prev = _M_state--;
390 if (_M_write_entered())
392 // Wake the queued writer if there are no more readers.
393 if (_M_readers() == 0)
394 _M_gate2.notify_one();
395 // No need to notify gate1 because we give priority to the queued
396 // writer, and that writer will eventually notify gate1 after it
397 // clears the write-entered flag.
401 // Wake any thread that was blocked on reader overflow.
402 if (__prev == _S_max_readers)
403 _M_gate1.notify_one();
410#if __cplusplus >= 201703L
411 /// The standard shared mutex type.
415 shared_mutex() = default;
416 ~shared_mutex() = default;
418 shared_mutex(const shared_mutex&) = delete;
419 shared_mutex& operator=(const shared_mutex&) = delete;
421 // Exclusive ownership
423 void lock() { _M_impl.lock(); }
424 [[nodiscard]] bool try_lock() { return _M_impl.try_lock(); }
425 void unlock() { _M_impl.unlock(); }
429 void lock_shared() { _M_impl.lock_shared(); }
430 [[nodiscard]] bool try_lock_shared() { return _M_impl.try_lock_shared(); }
431 void unlock_shared() { _M_impl.unlock_shared(); }
433#if _GLIBCXX_USE_PTHREAD_RWLOCK_T
434 typedef void* native_handle_type;
435 native_handle_type native_handle() { return _M_impl.native_handle(); }
438 __shared_mutex_pthread _M_impl;
441 __shared_mutex_cv _M_impl;
446 /// @cond undocumented
447#if _GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK
448 using __shared_timed_mutex_base = __shared_mutex_pthread;
450 using __shared_timed_mutex_base = __shared_mutex_cv;
454 /// The standard shared timed mutex type.
455 class shared_timed_mutex
456 : private __shared_timed_mutex_base
458 using _Base = __shared_timed_mutex_base;
460 // Must use the same clock as condition_variable for __shared_mutex_cv.
461#ifdef _GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK
462 using __clock_t = chrono::steady_clock;
464 using __clock_t = chrono::system_clock;
468 shared_timed_mutex() = default;
469 ~shared_timed_mutex() = default;
471 shared_timed_mutex(const shared_timed_mutex&) = delete;
472 shared_timed_mutex& operator=(const shared_timed_mutex&) = delete;
474 // Exclusive ownership
476 void lock() { _Base::lock(); }
477 _GLIBCXX_NODISCARD bool try_lock() { return _Base::try_lock(); }
478 void unlock() { _Base::unlock(); }
480 template<typename _Rep, typename _Period>
483 try_lock_for(const chrono::duration<_Rep, _Period>& __rtime)
485 auto __rt = chrono::duration_cast<__clock_t::duration>(__rtime);
486 if (ratio_greater<__clock_t::period, _Period>())
488 return try_lock_until(__clock_t::now() + __rt);
493 void lock_shared() { _Base::lock_shared(); }
495 bool try_lock_shared() { return _Base::try_lock_shared(); }
496 void unlock_shared() { _Base::unlock_shared(); }
498 template<typename _Rep, typename _Period>
501 try_lock_shared_for(const chrono::duration<_Rep, _Period>& __rtime)
503 auto __rt = chrono::duration_cast<__clock_t::duration>(__rtime);
504 if (ratio_greater<__clock_t::period, _Period>())
506 return try_lock_shared_until(__clock_t::now() + __rt);
509#if _GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK
511 // Exclusive ownership
513 template<typename _Duration>
516 try_lock_until(const chrono::time_point<chrono::system_clock,
519 auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
520 auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
522 __gthread_time_t __ts =
524 static_cast<std::time_t>(__s.time_since_epoch().count()),
525 static_cast<long>(__ns.count())
528 int __ret = __glibcxx_rwlock_timedwrlock(&_M_rwlock, &__ts);
529 // On self-deadlock, we just fail to acquire the lock. Technically,
530 // the program violated the precondition.
531 if (__ret == ETIMEDOUT || __ret == EDEADLK)
533 // Errors not handled: EINVAL
534 __glibcxx_assert(__ret == 0);
538#ifdef _GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK
539 template<typename _Duration>
542 try_lock_until(const chrono::time_point<chrono::steady_clock,
545 auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
546 auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
548 __gthread_time_t __ts =
550 static_cast<std::time_t>(__s.time_since_epoch().count()),
551 static_cast<long>(__ns.count())
554 int __ret = pthread_rwlock_clockwrlock(&_M_rwlock, CLOCK_MONOTONIC,
556 // On self-deadlock, we just fail to acquire the lock. Technically,
557 // the program violated the precondition.
558 if (__ret == ETIMEDOUT || __ret == EDEADLK)
560 // Errors not handled: EINVAL
561 __glibcxx_assert(__ret == 0);
566 template<typename _Clock, typename _Duration>
569 try_lock_until(const chrono::time_point<_Clock, _Duration>& __atime)
571#if __cplusplus > 201703L
572 static_assert(chrono::is_clock_v<_Clock>);
574 // The user-supplied clock may not tick at the same rate as
575 // steady_clock, so we must loop in order to guarantee that
576 // the timeout has expired before returning false.
577 typename _Clock::time_point __now = _Clock::now();
579 auto __rtime = __atime - __now;
580 if (try_lock_for(__rtime))
582 __now = _Clock::now();
583 } while (__atime > __now);
589 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>
632 try_lock_shared_until(const chrono::time_point<chrono::steady_clock,
635 auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
636 auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
638 __gthread_time_t __ts =
640 static_cast<std::time_t>(__s.time_since_epoch().count()),
641 static_cast<long>(__ns.count())
644 int __ret = pthread_rwlock_clockrdlock(&_M_rwlock, CLOCK_MONOTONIC,
646 // On self-deadlock, we just fail to acquire the lock. Technically,
647 // the program violated the precondition.
648 if (__ret == ETIMEDOUT || __ret == EDEADLK)
650 // Errors not handled: EINVAL
651 __glibcxx_assert(__ret == 0);
656 template<typename _Clock, typename _Duration>
659 try_lock_shared_until(const chrono::time_point<_Clock,
662#if __cplusplus > 201703L
663 static_assert(chrono::is_clock_v<_Clock>);
665 // The user-supplied clock may not tick at the same rate as
666 // steady_clock, so we must loop in order to guarantee that
667 // the timeout has expired before returning false.
668 typename _Clock::time_point __now = _Clock::now();
670 auto __rtime = __atime - __now;
671 if (try_lock_shared_for(__rtime))
673 __now = _Clock::now();
674 } while (__atime > __now);
678#else // ! (_GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK)
680 // Exclusive ownership
682 template<typename _Clock, typename _Duration>
685 try_lock_until(const chrono::time_point<_Clock, _Duration>& __abs_time)
687 unique_lock<mutex> __lk(_M_mut);
688 if (!_M_gate1.wait_until(__lk, __abs_time,
689 [=]{ return !_M_write_entered(); }))
693 _M_state |= _S_write_entered;
694 if (!_M_gate2.wait_until(__lk, __abs_time,
695 [=]{ return _M_readers() == 0; }))
697 _M_state ^= _S_write_entered;
698 // Wake all threads blocked while the write-entered flag was set.
699 _M_gate1.notify_all();
707 template <typename _Clock, typename _Duration>
710 try_lock_shared_until(const chrono::time_point<_Clock,
711 _Duration>& __abs_time)
713 unique_lock<mutex> __lk(_M_mut);
714 if (!_M_gate1.wait_until(__lk, __abs_time,
715 [=]{ return _M_state < _S_max_readers; }))
723#endif // _GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK
725#endif // _GLIBCXX_HAS_GTHREADS
728 template<typename _Mutex>
732 typedef _Mutex mutex_type;
736 shared_lock() noexcept : _M_pm(nullptr), _M_owns(false) { }
739 shared_lock(mutex_type& __m)
740 : _M_pm(std::__addressof(__m)), _M_owns(true)
741 { __m.lock_shared(); }
743 shared_lock(mutex_type& __m, defer_lock_t) noexcept
744 : _M_pm(std::__addressof(__m)), _M_owns(false) { }
746 shared_lock(mutex_type& __m, try_to_lock_t)
747 : _M_pm(std::__addressof(__m)), _M_owns(__m.try_lock_shared()) { }
749 shared_lock(mutex_type& __m, adopt_lock_t)
750 : _M_pm(std::__addressof(__m)), _M_owns(true) { }
752 template<typename _Clock, typename _Duration>
753 shared_lock(mutex_type& __m,
754 const chrono::time_point<_Clock, _Duration>& __abs_time)
755 : _M_pm(std::__addressof(__m)),
756 _M_owns(__m.try_lock_shared_until(__abs_time)) { }
758 template<typename _Rep, typename _Period>
759 shared_lock(mutex_type& __m,
760 const chrono::duration<_Rep, _Period>& __rel_time)
761 : _M_pm(std::__addressof(__m)),
762 _M_owns(__m.try_lock_shared_for(__rel_time)) { }
767 _M_pm->unlock_shared();
770 shared_lock(shared_lock const&) = delete;
771 shared_lock& operator=(shared_lock const&) = delete;
773 shared_lock(shared_lock&& __sl) noexcept : shared_lock()
777 operator=(shared_lock&& __sl) noexcept
779 shared_lock(std::move(__sl)).swap(*this);
787 _M_pm->lock_shared();
796 return _M_owns = _M_pm->try_lock_shared();
799 template<typename _Rep, typename _Period>
802 try_lock_for(const chrono::duration<_Rep, _Period>& __rel_time)
805 return _M_owns = _M_pm->try_lock_shared_for(__rel_time);
808 template<typename _Clock, typename _Duration>
811 try_lock_until(const chrono::time_point<_Clock, _Duration>& __abs_time)
814 return _M_owns = _M_pm->try_lock_shared_until(__abs_time);
821 __throw_system_error(int(errc::resource_deadlock_would_occur));
822 _M_pm->unlock_shared();
829 swap(shared_lock& __u) noexcept
831 std::swap(_M_pm, __u._M_pm);
832 std::swap(_M_owns, __u._M_owns);
839 return std::__exchange(_M_pm, nullptr);
845 bool owns_lock() const noexcept { return _M_owns; }
847 explicit operator bool() const noexcept { return _M_owns; }
850 mutex_type* mutex() const noexcept { return _M_pm; }
856 if (_M_pm == nullptr)
857 __throw_system_error(int(errc::operation_not_permitted));
859 __throw_system_error(int(errc::resource_deadlock_would_occur));
866 /// Swap specialization for shared_lock
867 /// @relates shared_mutex
868 template<typename _Mutex>
870 swap(shared_lock<_Mutex>& __x, shared_lock<_Mutex>& __y) noexcept
874_GLIBCXX_END_NAMESPACE_VERSION
879#endif // _GLIBCXX_SHARED_MUTEX