[libcxx-commits] [libcxx] 2d7eb9c - [libc++][NFC] clang-format <shared_mutex>
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jul 4 08:20:25 PDT 2023
Author: Louis Dionne
Date: 2023-07-04T11:20:21-04:00
New Revision: 2d7eb9c9ea1a146412a83603d5c0c6339a5d8284
URL: https://github.com/llvm/llvm-project/commit/2d7eb9c9ea1a146412a83603d5c0c6339a5d8284
DIFF: https://github.com/llvm/llvm-project/commit/2d7eb9c9ea1a146412a83603d5c0c6339a5d8284.diff
LOG: [libc++][NFC] clang-format <shared_mutex>
I am about to touch several lines in that file for a patch anyway, so
I might as well clang-format it upfront to avoid mixing styles after
my patch.
Added:
Modified:
libcxx/include/shared_mutex
libcxx/src/shared_mutex.cpp
libcxx/utils/data/ignore_format.txt
Removed:
################################################################################
diff --git a/libcxx/include/shared_mutex b/libcxx/include/shared_mutex
index 26415c273007a5..6b6291e5f68600 100644
--- a/libcxx/include/shared_mutex
+++ b/libcxx/include/shared_mutex
@@ -141,16 +141,15 @@ template <class Mutex>
_LIBCPP_PUSH_MACROS
#include <__undef_macros>
-
#if _LIBCPP_STD_VER >= 14
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-# pragma GCC system_header
-#endif
+# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+# endif
-#ifdef _LIBCPP_HAS_NO_THREADS
-# error "<shared_mutex> is not supported since libc++ has been configured without support for threads."
-#endif
+# ifdef _LIBCPP_HAS_NO_THREADS
+# error "<shared_mutex> is not supported since libc++ has been configured without support for threads."
+# endif
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -165,7 +164,7 @@ _LIBCPP_THREAD_SAFETY_ANNOTATION(capability("shared_mutex")) __shared_mutex_base
static const unsigned __n_readers_ = ~__write_entered_;
__shared_mutex_base();
- _LIBCPP_INLINE_VISIBILITY ~__shared_mutex_base() = default;
+ _LIBCPP_HIDE_FROM_ABI ~__shared_mutex_base() = default;
__shared_mutex_base(const __shared_mutex_base&) = delete;
__shared_mutex_base& operator=(const __shared_mutex_base&) = delete;
@@ -185,327 +184,256 @@ _LIBCPP_THREAD_SAFETY_ANNOTATION(capability("shared_mutex")) __shared_mutex_base
};
# if _LIBCPP_STD_VER >= 17
-class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_AVAILABILITY_SHARED_MUTEX shared_mutex
-{
- __shared_mutex_base __base_;
+class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_AVAILABILITY_SHARED_MUTEX shared_mutex {
+ __shared_mutex_base __base_;
+
public:
- _LIBCPP_INLINE_VISIBILITY shared_mutex() : __base_() {}
- _LIBCPP_INLINE_VISIBILITY ~shared_mutex() = default;
+ _LIBCPP_HIDE_FROM_ABI shared_mutex() : __base_() {}
+ _LIBCPP_HIDE_FROM_ABI ~shared_mutex() = default;
- shared_mutex(const shared_mutex&) = delete;
- shared_mutex& operator=(const shared_mutex&) = delete;
+ shared_mutex(const shared_mutex&) = delete;
+ shared_mutex& operator=(const shared_mutex&) = delete;
- // Exclusive ownership
- _LIBCPP_INLINE_VISIBILITY void lock() { return __base_.lock(); }
- _LIBCPP_INLINE_VISIBILITY bool try_lock() { return __base_.try_lock(); }
- _LIBCPP_INLINE_VISIBILITY void unlock() { return __base_.unlock(); }
+ // Exclusive ownership
+ _LIBCPP_HIDE_FROM_ABI void lock() { return __base_.lock(); }
+ _LIBCPP_HIDE_FROM_ABI bool try_lock() { return __base_.try_lock(); }
+ _LIBCPP_HIDE_FROM_ABI void unlock() { return __base_.unlock(); }
- // Shared ownership
- _LIBCPP_INLINE_VISIBILITY void lock_shared() { return __base_.lock_shared(); }
- _LIBCPP_INLINE_VISIBILITY bool try_lock_shared() { return __base_.try_lock_shared(); }
- _LIBCPP_INLINE_VISIBILITY void unlock_shared() { return __base_.unlock_shared(); }
+ // Shared ownership
+ _LIBCPP_HIDE_FROM_ABI void lock_shared() { return __base_.lock_shared(); }
+ _LIBCPP_HIDE_FROM_ABI bool try_lock_shared() { return __base_.try_lock_shared(); }
+ _LIBCPP_HIDE_FROM_ABI void unlock_shared() { return __base_.unlock_shared(); }
-// typedef __shared_mutex_base::native_handle_type native_handle_type;
-// _LIBCPP_INLINE_VISIBILITY native_handle_type native_handle() { return __base::unlock_shared(); }
+ // typedef __shared_mutex_base::native_handle_type native_handle_type;
+ // _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() { return __base::unlock_shared(); }
};
-#endif
+# endif
+class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_AVAILABILITY_SHARED_MUTEX shared_timed_mutex {
+ __shared_mutex_base __base_;
-class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_AVAILABILITY_SHARED_MUTEX shared_timed_mutex
-{
- __shared_mutex_base __base_;
public:
- shared_timed_mutex();
- _LIBCPP_INLINE_VISIBILITY ~shared_timed_mutex() = default;
+ shared_timed_mutex();
+ _LIBCPP_HIDE_FROM_ABI ~shared_timed_mutex() = default;
- shared_timed_mutex(const shared_timed_mutex&) = delete;
- shared_timed_mutex& operator=(const shared_timed_mutex&) = delete;
+ shared_timed_mutex(const shared_timed_mutex&) = delete;
+ shared_timed_mutex& operator=(const shared_timed_mutex&) = delete;
- // Exclusive ownership
- void lock();
- bool try_lock();
- template <class _Rep, class _Period>
- _LIBCPP_INLINE_VISIBILITY
- bool
- try_lock_for(const chrono::duration<_Rep, _Period>& __rel_time)
- {
- return try_lock_until(chrono::steady_clock::now() + __rel_time);
- }
- template <class _Clock, class _Duration>
- _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
- bool
- try_lock_until(const chrono::time_point<_Clock, _Duration>& __abs_time);
- void unlock();
+ // Exclusive ownership
+ void lock();
+ bool try_lock();
+ template <class _Rep, class _Period>
+ _LIBCPP_HIDE_FROM_ABI bool try_lock_for(const chrono::duration<_Rep, _Period>& __rel_time) {
+ return try_lock_until(chrono::steady_clock::now() + __rel_time);
+ }
+ template <class _Clock, class _Duration>
+ _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool
+ try_lock_until(const chrono::time_point<_Clock, _Duration>& __abs_time);
+ void unlock();
- // Shared ownership
- void lock_shared();
- bool try_lock_shared();
- template <class _Rep, class _Period>
- _LIBCPP_INLINE_VISIBILITY
- bool
- try_lock_shared_for(const chrono::duration<_Rep, _Period>& __rel_time)
- {
- return try_lock_shared_until(chrono::steady_clock::now() + __rel_time);
- }
- template <class _Clock, class _Duration>
- _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
- bool
- try_lock_shared_until(const chrono::time_point<_Clock, _Duration>& __abs_time);
- void unlock_shared();
+ // Shared ownership
+ void lock_shared();
+ bool try_lock_shared();
+ template <class _Rep, class _Period>
+ _LIBCPP_HIDE_FROM_ABI bool try_lock_shared_for(const chrono::duration<_Rep, _Period>& __rel_time) {
+ return try_lock_shared_until(chrono::steady_clock::now() + __rel_time);
+ }
+ template <class _Clock, class _Duration>
+ _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool
+ try_lock_shared_until(const chrono::time_point<_Clock, _Duration>& __abs_time);
+ void unlock_shared();
};
template <class _Clock, class _Duration>
-bool
-shared_timed_mutex::try_lock_until(
- const chrono::time_point<_Clock, _Duration>& __abs_time)
-{
- unique_lock<mutex> __lk(__base_.__mut_);
- if (__base_.__state_ & __base_.__write_entered_)
- {
- while (true)
- {
- cv_status __status = __base_.__gate1_.wait_until(__lk, __abs_time);
- if ((__base_.__state_ & __base_.__write_entered_) == 0)
- break;
- if (__status == cv_status::timeout)
- return false;
- }
+bool shared_timed_mutex::try_lock_until(const chrono::time_point<_Clock, _Duration>& __abs_time) {
+ unique_lock<mutex> __lk(__base_.__mut_);
+ if (__base_.__state_ & __base_.__write_entered_) {
+ while (true) {
+ cv_status __status = __base_.__gate1_.wait_until(__lk, __abs_time);
+ if ((__base_.__state_ & __base_.__write_entered_) == 0)
+ break;
+ if (__status == cv_status::timeout)
+ return false;
}
- __base_.__state_ |= __base_.__write_entered_;
- if (__base_.__state_ & __base_.__n_readers_)
- {
- while (true)
- {
- cv_status __status = __base_.__gate2_.wait_until(__lk, __abs_time);
- if ((__base_.__state_ & __base_.__n_readers_) == 0)
- break;
- if (__status == cv_status::timeout)
- {
- __base_.__state_ &= ~__base_.__write_entered_;
- __base_.__gate1_.notify_all();
- return false;
- }
- }
+ }
+ __base_.__state_ |= __base_.__write_entered_;
+ if (__base_.__state_ & __base_.__n_readers_) {
+ while (true) {
+ cv_status __status = __base_.__gate2_.wait_until(__lk, __abs_time);
+ if ((__base_.__state_ & __base_.__n_readers_) == 0)
+ break;
+ if (__status == cv_status::timeout) {
+ __base_.__state_ &= ~__base_.__write_entered_;
+ __base_.__gate1_.notify_all();
+ return false;
+ }
}
- return true;
+ }
+ return true;
}
template <class _Clock, class _Duration>
-bool
-shared_timed_mutex::try_lock_shared_until(
- const chrono::time_point<_Clock, _Duration>& __abs_time)
-{
- unique_lock<mutex> __lk(__base_.__mut_);
- if ((__base_.__state_ & __base_.__write_entered_) || (__base_.__state_ & __base_.__n_readers_) == __base_.__n_readers_)
- {
- while (true)
- {
- cv_status __status = __base_.__gate1_.wait_until(__lk, __abs_time);
- if ((__base_.__state_ & __base_.__write_entered_) == 0 &&
- (__base_.__state_ & __base_.__n_readers_) < __base_.__n_readers_)
- break;
- if (__status == cv_status::timeout)
- return false;
- }
+bool shared_timed_mutex::try_lock_shared_until(const chrono::time_point<_Clock, _Duration>& __abs_time) {
+ unique_lock<mutex> __lk(__base_.__mut_);
+ if ((__base_.__state_ & __base_.__write_entered_) ||
+ (__base_.__state_ & __base_.__n_readers_) == __base_.__n_readers_) {
+ while (true) {
+ cv_status __status = __base_.__gate1_.wait_until(__lk, __abs_time);
+ if ((__base_.__state_ & __base_.__write_entered_) == 0 &&
+ (__base_.__state_ & __base_.__n_readers_) < __base_.__n_readers_)
+ break;
+ if (__status == cv_status::timeout)
+ return false;
}
- unsigned __num_readers = (__base_.__state_ & __base_.__n_readers_) + 1;
- __base_.__state_ &= ~__base_.__n_readers_;
- __base_.__state_ |= __num_readers;
- return true;
+ }
+ unsigned __num_readers = (__base_.__state_ & __base_.__n_readers_) + 1;
+ __base_.__state_ &= ~__base_.__n_readers_;
+ __base_.__state_ |= __num_readers;
+ return true;
}
template <class _Mutex>
-class shared_lock
-{
+class shared_lock {
public:
- typedef _Mutex mutex_type;
+ typedef _Mutex mutex_type;
private:
- mutex_type* __m_;
- bool __owns_;
+ mutex_type* __m_;
+ bool __owns_;
public:
- _LIBCPP_INLINE_VISIBILITY
- shared_lock() _NOEXCEPT
- : __m_(nullptr),
- __owns_(false)
- {}
-
- _LIBCPP_INLINE_VISIBILITY
- explicit shared_lock(mutex_type& __m)
- : __m_(_VSTD::addressof(__m)),
- __owns_(true)
- {__m_->lock_shared();}
-
- _LIBCPP_INLINE_VISIBILITY
- shared_lock(mutex_type& __m, defer_lock_t) _NOEXCEPT
- : __m_(_VSTD::addressof(__m)),
- __owns_(false)
- {}
-
- _LIBCPP_INLINE_VISIBILITY
- shared_lock(mutex_type& __m, try_to_lock_t)
- : __m_(_VSTD::addressof(__m)),
- __owns_(__m.try_lock_shared())
- {}
-
- _LIBCPP_INLINE_VISIBILITY
- shared_lock(mutex_type& __m, adopt_lock_t)
- : __m_(_VSTD::addressof(__m)),
- __owns_(true)
- {}
-
- template <class _Clock, class _Duration>
- _LIBCPP_INLINE_VISIBILITY
- shared_lock(mutex_type& __m,
- const chrono::time_point<_Clock, _Duration>& __abs_time)
- : __m_(_VSTD::addressof(__m)),
- __owns_(__m.try_lock_shared_until(__abs_time))
- {}
-
- template <class _Rep, class _Period>
- _LIBCPP_INLINE_VISIBILITY
- shared_lock(mutex_type& __m,
- const chrono::duration<_Rep, _Period>& __rel_time)
- : __m_(_VSTD::addressof(__m)),
- __owns_(__m.try_lock_shared_for(__rel_time))
- {}
-
- _LIBCPP_INLINE_VISIBILITY
- ~shared_lock()
- {
- if (__owns_)
- __m_->unlock_shared();
- }
+ _LIBCPP_HIDE_FROM_ABI shared_lock() _NOEXCEPT : __m_(nullptr), __owns_(false) {}
- shared_lock(shared_lock const&) = delete;
- shared_lock& operator=(shared_lock const&) = delete;
+ _LIBCPP_HIDE_FROM_ABI explicit shared_lock(mutex_type& __m) : __m_(_VSTD::addressof(__m)), __owns_(true) {
+ __m_->lock_shared();
+ }
- _LIBCPP_INLINE_VISIBILITY
- shared_lock(shared_lock&& __u) _NOEXCEPT
- : __m_(__u.__m_),
- __owns_(__u.__owns_)
- {
- __u.__m_ = nullptr;
- __u.__owns_ = false;
- }
-
- _LIBCPP_INLINE_VISIBILITY
- shared_lock& operator=(shared_lock&& __u) _NOEXCEPT
- {
- if (__owns_)
- __m_->unlock_shared();
- __m_ = nullptr;
- __owns_ = false;
- __m_ = __u.__m_;
- __owns_ = __u.__owns_;
- __u.__m_ = nullptr;
- __u.__owns_ = false;
- return *this;
- }
+ _LIBCPP_HIDE_FROM_ABI shared_lock(mutex_type& __m, defer_lock_t) _NOEXCEPT
+ : __m_(_VSTD::addressof(__m)),
+ __owns_(false) {}
- _LIBCPP_HIDE_FROM_ABI void lock();
- _LIBCPP_HIDE_FROM_ABI bool try_lock();
- template <class Rep, class Period>
- _LIBCPP_HIDE_FROM_ABI bool try_lock_for(const chrono::duration<Rep, Period>& __rel_time);
- template <class Clock, class Duration>
- _LIBCPP_HIDE_FROM_ABI bool try_lock_until(const chrono::time_point<Clock, Duration>& __abs_time);
- _LIBCPP_HIDE_FROM_ABI void unlock();
+ _LIBCPP_HIDE_FROM_ABI shared_lock(mutex_type& __m, try_to_lock_t)
+ : __m_(_VSTD::addressof(__m)), __owns_(__m.try_lock_shared()) {}
- // Setters
- _LIBCPP_INLINE_VISIBILITY
- void swap(shared_lock& __u) _NOEXCEPT
- {
- _VSTD::swap(__m_, __u.__m_);
- _VSTD::swap(__owns_, __u.__owns_);
- }
+ _LIBCPP_HIDE_FROM_ABI shared_lock(mutex_type& __m, adopt_lock_t) : __m_(_VSTD::addressof(__m)), __owns_(true) {}
- _LIBCPP_INLINE_VISIBILITY
- mutex_type* release() _NOEXCEPT
- {
- mutex_type* __m = __m_;
- __m_ = nullptr;
- __owns_ = false;
- return __m;
- }
+ template <class _Clock, class _Duration>
+ _LIBCPP_HIDE_FROM_ABI shared_lock(mutex_type& __m, const chrono::time_point<_Clock, _Duration>& __abs_time)
+ : __m_(_VSTD::addressof(__m)), __owns_(__m.try_lock_shared_until(__abs_time)) {}
- // Getters
- _LIBCPP_INLINE_VISIBILITY
- bool owns_lock() const _NOEXCEPT {return __owns_;}
+ template <class _Rep, class _Period>
+ _LIBCPP_HIDE_FROM_ABI shared_lock(mutex_type& __m, const chrono::duration<_Rep, _Period>& __rel_time)
+ : __m_(_VSTD::addressof(__m)), __owns_(__m.try_lock_shared_for(__rel_time)) {}
- _LIBCPP_INLINE_VISIBILITY
- explicit operator bool () const _NOEXCEPT {return __owns_;}
+ _LIBCPP_HIDE_FROM_ABI ~shared_lock() {
+ if (__owns_)
+ __m_->unlock_shared();
+ }
- _LIBCPP_INLINE_VISIBILITY
- mutex_type* mutex() const _NOEXCEPT {return __m_;}
+ shared_lock(shared_lock const&) = delete;
+ shared_lock& operator=(shared_lock const&) = delete;
+
+ _LIBCPP_HIDE_FROM_ABI shared_lock(shared_lock&& __u) _NOEXCEPT : __m_(__u.__m_), __owns_(__u.__owns_) {
+ __u.__m_ = nullptr;
+ __u.__owns_ = false;
+ }
+
+ _LIBCPP_HIDE_FROM_ABI shared_lock& operator=(shared_lock&& __u) _NOEXCEPT {
+ if (__owns_)
+ __m_->unlock_shared();
+ __m_ = nullptr;
+ __owns_ = false;
+ __m_ = __u.__m_;
+ __owns_ = __u.__owns_;
+ __u.__m_ = nullptr;
+ __u.__owns_ = false;
+ return *this;
+ }
+
+ _LIBCPP_HIDE_FROM_ABI void lock();
+ _LIBCPP_HIDE_FROM_ABI bool try_lock();
+ template <class Rep, class Period>
+ _LIBCPP_HIDE_FROM_ABI bool try_lock_for(const chrono::duration<Rep, Period>& __rel_time);
+ template <class Clock, class Duration>
+ _LIBCPP_HIDE_FROM_ABI bool try_lock_until(const chrono::time_point<Clock, Duration>& __abs_time);
+ _LIBCPP_HIDE_FROM_ABI void unlock();
+
+ // Setters
+ _LIBCPP_HIDE_FROM_ABI void swap(shared_lock& __u) _NOEXCEPT {
+ _VSTD::swap(__m_, __u.__m_);
+ _VSTD::swap(__owns_, __u.__owns_);
+ }
+
+ _LIBCPP_HIDE_FROM_ABI mutex_type* release() _NOEXCEPT {
+ mutex_type* __m = __m_;
+ __m_ = nullptr;
+ __owns_ = false;
+ return __m;
+ }
+
+ // Getters
+ _LIBCPP_HIDE_FROM_ABI bool owns_lock() const _NOEXCEPT { return __owns_; }
+
+ _LIBCPP_HIDE_FROM_ABI explicit operator bool() const _NOEXCEPT { return __owns_; }
+
+ _LIBCPP_HIDE_FROM_ABI mutex_type* mutex() const _NOEXCEPT { return __m_; }
};
_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(shared_lock);
template <class _Mutex>
-void
-shared_lock<_Mutex>::lock()
-{
- if (__m_ == nullptr)
- __throw_system_error(EPERM, "shared_lock::lock: references null mutex");
- if (__owns_)
- __throw_system_error(EDEADLK, "shared_lock::lock: already locked");
- __m_->lock_shared();
- __owns_ = true;
+void shared_lock<_Mutex>::lock() {
+ if (__m_ == nullptr)
+ __throw_system_error(EPERM, "shared_lock::lock: references null mutex");
+ if (__owns_)
+ __throw_system_error(EDEADLK, "shared_lock::lock: already locked");
+ __m_->lock_shared();
+ __owns_ = true;
}
template <class _Mutex>
-bool
-shared_lock<_Mutex>::try_lock()
-{
- if (__m_ == nullptr)
- __throw_system_error(EPERM, "shared_lock::try_lock: references null mutex");
- if (__owns_)
- __throw_system_error(EDEADLK, "shared_lock::try_lock: already locked");
- __owns_ = __m_->try_lock_shared();
- return __owns_;
+bool shared_lock<_Mutex>::try_lock() {
+ if (__m_ == nullptr)
+ __throw_system_error(EPERM, "shared_lock::try_lock: references null mutex");
+ if (__owns_)
+ __throw_system_error(EDEADLK, "shared_lock::try_lock: already locked");
+ __owns_ = __m_->try_lock_shared();
+ return __owns_;
}
template <class _Mutex>
template <class _Rep, class _Period>
-bool
-shared_lock<_Mutex>::try_lock_for(const chrono::duration<_Rep, _Period>& __d)
-{
- if (__m_ == nullptr)
- __throw_system_error(EPERM, "shared_lock::try_lock_for: references null mutex");
- if (__owns_)
- __throw_system_error(EDEADLK, "shared_lock::try_lock_for: already locked");
- __owns_ = __m_->try_lock_shared_for(__d);
- return __owns_;
+bool shared_lock<_Mutex>::try_lock_for(const chrono::duration<_Rep, _Period>& __d) {
+ if (__m_ == nullptr)
+ __throw_system_error(EPERM, "shared_lock::try_lock_for: references null mutex");
+ if (__owns_)
+ __throw_system_error(EDEADLK, "shared_lock::try_lock_for: already locked");
+ __owns_ = __m_->try_lock_shared_for(__d);
+ return __owns_;
}
template <class _Mutex>
template <class _Clock, class _Duration>
-bool
-shared_lock<_Mutex>::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t)
-{
- if (__m_ == nullptr)
- __throw_system_error(EPERM, "shared_lock::try_lock_until: references null mutex");
- if (__owns_)
- __throw_system_error(EDEADLK, "shared_lock::try_lock_until: already locked");
- __owns_ = __m_->try_lock_shared_until(__t);
- return __owns_;
+bool shared_lock<_Mutex>::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t) {
+ if (__m_ == nullptr)
+ __throw_system_error(EPERM, "shared_lock::try_lock_until: references null mutex");
+ if (__owns_)
+ __throw_system_error(EDEADLK, "shared_lock::try_lock_until: already locked");
+ __owns_ = __m_->try_lock_shared_until(__t);
+ return __owns_;
}
template <class _Mutex>
-void
-shared_lock<_Mutex>::unlock()
-{
- if (!__owns_)
- __throw_system_error(EPERM, "shared_lock::unlock: not locked");
- __m_->unlock_shared();
- __owns_ = false;
+void shared_lock<_Mutex>::unlock() {
+ if (!__owns_)
+ __throw_system_error(EPERM, "shared_lock::unlock: not locked");
+ __m_->unlock_shared();
+ __owns_ = false;
}
template <class _Mutex>
-inline _LIBCPP_INLINE_VISIBILITY
-void
-swap(shared_lock<_Mutex>& __x, shared_lock<_Mutex>& __y) _NOEXCEPT
- {__x.swap(__y);}
+inline _LIBCPP_HIDE_FROM_ABI void swap(shared_lock<_Mutex>& __x, shared_lock<_Mutex>& __y) _NOEXCEPT {
+ __x.swap(__y);
+}
_LIBCPP_END_NAMESPACE_STD
diff --git a/libcxx/src/shared_mutex.cpp b/libcxx/src/shared_mutex.cpp
index b1976c11d7ef23..49a51e02712276 100644
--- a/libcxx/src/shared_mutex.cpp
+++ b/libcxx/src/shared_mutex.cpp
@@ -10,107 +10,86 @@
#ifndef _LIBCPP_HAS_NO_THREADS
-#include <mutex>
-#include <shared_mutex>
-#if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
-# pragma comment(lib, "pthread")
-#endif
+# include <mutex>
+# include <shared_mutex>
+# if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
+# pragma comment(lib, "pthread")
+# endif
_LIBCPP_BEGIN_NAMESPACE_STD
// Shared Mutex Base
-__shared_mutex_base::__shared_mutex_base()
- : __state_(0)
-{
-}
+__shared_mutex_base::__shared_mutex_base() : __state_(0) {}
// Exclusive ownership
-void
-__shared_mutex_base::lock()
-{
- unique_lock<mutex> lk(__mut_);
- while (__state_ & __write_entered_)
- __gate1_.wait(lk);
- __state_ |= __write_entered_;
- while (__state_ & __n_readers_)
- __gate2_.wait(lk);
+void __shared_mutex_base::lock() {
+ unique_lock<mutex> lk(__mut_);
+ while (__state_ & __write_entered_)
+ __gate1_.wait(lk);
+ __state_ |= __write_entered_;
+ while (__state_ & __n_readers_)
+ __gate2_.wait(lk);
}
-bool
-__shared_mutex_base::try_lock()
-{
- unique_lock<mutex> lk(__mut_);
- if (__state_ == 0)
- {
- __state_ = __write_entered_;
- return true;
- }
- return false;
+bool __shared_mutex_base::try_lock() {
+ unique_lock<mutex> lk(__mut_);
+ if (__state_ == 0) {
+ __state_ = __write_entered_;
+ return true;
+ }
+ return false;
}
-void
-__shared_mutex_base::unlock()
-{
- lock_guard<mutex> _(__mut_);
- __state_ = 0;
- __gate1_.notify_all();
+void __shared_mutex_base::unlock() {
+ lock_guard<mutex> _(__mut_);
+ __state_ = 0;
+ __gate1_.notify_all();
}
// Shared ownership
-void
-__shared_mutex_base::lock_shared()
-{
- unique_lock<mutex> lk(__mut_);
- while ((__state_ & __write_entered_) || (__state_ & __n_readers_) == __n_readers_)
- __gate1_.wait(lk);
- unsigned num_readers = (__state_ & __n_readers_) + 1;
- __state_ &= ~__n_readers_;
- __state_ |= num_readers;
-}
-
-bool
-__shared_mutex_base::try_lock_shared()
-{
- unique_lock<mutex> lk(__mut_);
- unsigned num_readers = __state_ & __n_readers_;
- if (!(__state_ & __write_entered_) && num_readers != __n_readers_)
- {
- ++num_readers;
- __state_ &= ~__n_readers_;
- __state_ |= num_readers;
- return true;
- }
- return false;
+void __shared_mutex_base::lock_shared() {
+ unique_lock<mutex> lk(__mut_);
+ while ((__state_ & __write_entered_) || (__state_ & __n_readers_) == __n_readers_)
+ __gate1_.wait(lk);
+ unsigned num_readers = (__state_ & __n_readers_) + 1;
+ __state_ &= ~__n_readers_;
+ __state_ |= num_readers;
}
-void
-__shared_mutex_base::unlock_shared()
-{
- lock_guard<mutex> _(__mut_);
- unsigned num_readers = (__state_ & __n_readers_) - 1;
+bool __shared_mutex_base::try_lock_shared() {
+ unique_lock<mutex> lk(__mut_);
+ unsigned num_readers = __state_ & __n_readers_;
+ if (!(__state_ & __write_entered_) && num_readers != __n_readers_) {
+ ++num_readers;
__state_ &= ~__n_readers_;
__state_ |= num_readers;
- if (__state_ & __write_entered_)
- {
- if (num_readers == 0)
- __gate2_.notify_one();
- }
- else
- {
- if (num_readers == __n_readers_ - 1)
- __gate1_.notify_one();
- }
+ return true;
+ }
+ return false;
}
+void __shared_mutex_base::unlock_shared() {
+ lock_guard<mutex> _(__mut_);
+ unsigned num_readers = (__state_ & __n_readers_) - 1;
+ __state_ &= ~__n_readers_;
+ __state_ |= num_readers;
+ if (__state_ & __write_entered_) {
+ if (num_readers == 0)
+ __gate2_.notify_one();
+ } else {
+ if (num_readers == __n_readers_ - 1)
+ __gate1_.notify_one();
+ }
+}
// Shared Timed Mutex
// These routines are here for ABI stability
shared_timed_mutex::shared_timed_mutex() : __base_() {}
-void shared_timed_mutex::lock() { return __base_.lock(); }
+void shared_timed_mutex::lock() { return __base_.lock(); }
bool shared_timed_mutex::try_lock() { return __base_.try_lock(); }
-void shared_timed_mutex::unlock() { return __base_.unlock(); }
+void shared_timed_mutex::unlock() { return __base_.unlock(); }
void shared_timed_mutex::lock_shared() { return __base_.lock_shared(); }
bool shared_timed_mutex::try_lock_shared() { return __base_.try_lock_shared(); }
void shared_timed_mutex::unlock_shared() { return __base_.unlock_shared(); }
diff --git a/libcxx/utils/data/ignore_format.txt b/libcxx/utils/data/ignore_format.txt
index a24da61ecc5d61..00b1f7408d0aad 100644
--- a/libcxx/utils/data/ignore_format.txt
+++ b/libcxx/utils/data/ignore_format.txt
@@ -443,7 +443,6 @@ libcxx/include/scoped_allocator
libcxx/include/semaphore
libcxx/include/set
libcxx/include/setjmp.h
-libcxx/include/shared_mutex
libcxx/include/span
libcxx/include/__split_buffer
libcxx/include/sstream
@@ -555,7 +554,6 @@ libcxx/src/optional.cpp
libcxx/src/random.cpp
libcxx/src/random_shuffle.cpp
libcxx/src/regex.cpp
-libcxx/src/shared_mutex.cpp
libcxx/src/stdexcept.cpp
libcxx/src/std_stream.h
libcxx/src/string.cpp
More information about the libcxx-commits
mailing list