diff --git a/libcxx/include/shared_mutex b/libcxx/include/shared_mutex --- a/libcxx/include/shared_mutex +++ b/libcxx/include/shared_mutex @@ -154,8 +154,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD -struct _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_AVAILABILITY_SHARED_MUTEX -_LIBCPP_THREAD_SAFETY_ANNOTATION(capability("shared_mutex")) __shared_mutex_base { +struct _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_AVAILABILITY_SHARED_MUTEX __shared_mutex_base { mutex __mut_; condition_variable __gate1_; condition_variable __gate2_; @@ -171,23 +170,24 @@ __shared_mutex_base& operator=(const __shared_mutex_base&) = delete; // Exclusive ownership - void lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability()); // blocking - bool try_lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(try_acquire_capability(true)); - void unlock() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()); + void lock(); // blocking + bool try_lock(); + void unlock(); // Shared ownership - void lock_shared() _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_shared_capability()); // blocking - bool try_lock_shared() _LIBCPP_THREAD_SAFETY_ANNOTATION(try_acquire_shared_capability(true)); - void unlock_shared() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_shared_capability()); + void lock_shared(); // blocking + bool try_lock_shared(); + void unlock_shared(); // typedef implementation-defined native_handle_type; // See 30.2.3 // native_handle_type native_handle(); // See 30.2.3 }; # 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 +_LIBCPP_THREAD_SAFETY_ANNOTATION(capability("shared_mutex")) shared_mutex { + __shared_mutex_base __base_; + public: _LIBCPP_INLINE_VISIBILITY shared_mutex() : __base_() {} _LIBCPP_INLINE_VISIBILITY ~shared_mutex() = default; @@ -196,24 +196,37 @@ 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(); } + _LIBCPP_INLINE_VISIBILITY void lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability()) { + return __base_.lock(); + } + _LIBCPP_INLINE_VISIBILITY bool try_lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(try_acquire_capability(true)) { + return __base_.try_lock(); + } + _LIBCPP_INLINE_VISIBILITY void unlock() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()) { + 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(); } + _LIBCPP_INLINE_VISIBILITY void lock_shared() _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_shared_capability()) { + return __base_.lock_shared(); + } + _LIBCPP_INLINE_VISIBILITY bool try_lock_shared() + _LIBCPP_THREAD_SAFETY_ANNOTATION(try_acquire_shared_capability(true)) { + return __base_.try_lock_shared(); + } + _LIBCPP_INLINE_VISIBILITY void unlock_shared() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_shared_capability()) { + 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(); } }; #endif - -class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_AVAILABILITY_SHARED_MUTEX shared_timed_mutex -{ +class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_AVAILABILITY_SHARED_MUTEX +_LIBCPP_THREAD_SAFETY_ANNOTATION(capability("shared_mutex")) shared_timed_mutex { __shared_mutex_base __base_; + public: shared_timed_mutex(); _LIBCPP_INLINE_VISIBILITY ~shared_timed_mutex() = default; @@ -222,8 +235,8 @@ shared_timed_mutex& operator=(const shared_timed_mutex&) = delete; // Exclusive ownership - void lock(); - bool try_lock(); + void lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability()); + bool try_lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(try_acquire_capability(true)); template _LIBCPP_INLINE_VISIBILITY bool @@ -235,11 +248,11 @@ _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __abs_time); - void unlock(); + void unlock() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()); // Shared ownership - void lock_shared(); - bool try_lock_shared(); + void lock_shared() _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_shared_capability()); + bool try_lock_shared() _LIBCPP_THREAD_SAFETY_ANNOTATION(try_acquire_shared_capability(true)); template _LIBCPP_INLINE_VISIBILITY bool @@ -251,7 +264,7 @@ _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool try_lock_shared_until(const chrono::time_point<_Clock, _Duration>& __abs_time); - void unlock_shared(); + void unlock_shared() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_shared_capability()); }; template