Index: libcxx/include/__mutex_base =================================================================== --- libcxx/include/__mutex_base +++ libcxx/include/__mutex_base @@ -110,7 +110,7 @@ }; template -class _LIBCPP_TEMPLATE_VIS unique_lock +class _LIBCPP_TEMPLATE_VIS _LIBCPP_THREAD_SAFETY_ANNOTATION(scoped_lockable) unique_lock { public: typedef _Mutex mutex_type; @@ -123,7 +123,7 @@ _LIBCPP_INLINE_VISIBILITY unique_lock() _NOEXCEPT : __m_(nullptr), __owns_(false) {} _LIBCPP_INLINE_VISIBILITY - explicit unique_lock(mutex_type& __m) + explicit unique_lock(mutex_type& __m) _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability(__m)) : __m_(_VSTD::addressof(__m)), __owns_(true) {__m_->lock();} _LIBCPP_INLINE_VISIBILITY unique_lock(mutex_type& __m, defer_lock_t) _NOEXCEPT @@ -132,7 +132,7 @@ unique_lock(mutex_type& __m, try_to_lock_t) : __m_(_VSTD::addressof(__m)), __owns_(__m.try_lock()) {} _LIBCPP_INLINE_VISIBILITY - unique_lock(mutex_type& __m, adopt_lock_t) + unique_lock(mutex_type& __m, adopt_lock_t) _LIBCPP_THREAD_SAFETY_ANNOTATION(requires_capability(__m)) : __m_(_VSTD::addressof(__m)), __owns_(true) {} template _LIBCPP_INLINE_VISIBILITY @@ -143,7 +143,7 @@ unique_lock(mutex_type& __m, const chrono::duration<_Rep, _Period>& __d) : __m_(_VSTD::addressof(__m)), __owns_(__m.try_lock_for(__d)) {} _LIBCPP_INLINE_VISIBILITY - ~unique_lock() + ~unique_lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()) { if (__owns_) __m_->unlock(); @@ -173,15 +173,17 @@ #endif // _LIBCPP_CXX03_LANG - 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 - bool try_lock_for(const chrono::duration<_Rep, _Period>& __d); + bool try_lock_for(const chrono::duration<_Rep, _Period>& __d) + _LIBCPP_THREAD_SAFETY_ANNOTATION(try_acquire_capability(true)); template - bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t); + bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t) + _LIBCPP_THREAD_SAFETY_ANNOTATION(try_acquire_capability(true)); - void unlock(); + void unlock() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()); _LIBCPP_INLINE_VISIBILITY void swap(unique_lock& __u) _NOEXCEPT @@ -203,7 +205,7 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_EXPLICIT operator bool () const _NOEXCEPT {return __owns_;} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_THREAD_SAFETY_ANNOTATION(return_capability(__m_)) mutex_type* mutex() const _NOEXCEPT {return __m_;} }; Index: libcxx/include/shared_mutex =================================================================== --- libcxx/include/shared_mutex +++ libcxx/include/shared_mutex @@ -176,7 +176,7 @@ #if _LIBCPP_STD_VER > 14 -class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_SHARED_MUTEX shared_mutex +class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_SHARED_MUTEX _LIBCPP_THREAD_SAFETY_ANNOTATION(capability("shared_mutex")) shared_mutex { __shared_mutex_base __base; public: @@ -187,14 +187,20 @@ 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(); } @@ -306,7 +312,7 @@ } template -class shared_lock +class _LIBCPP_THREAD_SAFETY_ANNOTATION(scoped_lockable) shared_lock { public: typedef _Mutex mutex_type; @@ -323,7 +329,7 @@ {} _LIBCPP_INLINE_VISIBILITY - explicit shared_lock(mutex_type& __m) + explicit shared_lock(mutex_type& __m) _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_shared_capability(__m)) : __m_(_VSTD::addressof(__m)), __owns_(true) {__m_->lock_shared();} @@ -341,7 +347,7 @@ {} _LIBCPP_INLINE_VISIBILITY - shared_lock(mutex_type& __m, adopt_lock_t) + shared_lock(mutex_type& __m, adopt_lock_t) _LIBCPP_THREAD_SAFETY_ANNOTATION(requires_shared_capability(__m)) : __m_(_VSTD::addressof(__m)), __owns_(true) {} @@ -363,7 +369,7 @@ {} _LIBCPP_INLINE_VISIBILITY - ~shared_lock() + ~shared_lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability(__m)) { if (__owns_) __m_->unlock_shared(); @@ -395,13 +401,15 @@ return *this; } - void lock(); - bool try_lock(); + void lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_shared_capability()); + bool try_lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(try_acquire_shared_capability(true)); template - bool try_lock_for(const chrono::duration& rel_time); + bool try_lock_for(const chrono::duration& rel_time) + _LIBCPP_THREAD_SAFETY_ANNOTATION(try_acquire_capability(true)); template - bool try_lock_until(const chrono::time_point& abs_time); - void unlock(); + bool try_lock_until(const chrono::time_point& abs_time) + _LIBCPP_THREAD_SAFETY_ANNOTATION(try_acquire_capability(true)); + void unlock() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_shared_capability()); // Setters _LIBCPP_INLINE_VISIBILITY @@ -427,7 +435,7 @@ _LIBCPP_INLINE_VISIBILITY explicit operator bool () const _NOEXCEPT {return __owns_;} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_THREAD_SAFETY_ANNOTATION(return_capability(__m_)) mutex_type* mutex() const _NOEXCEPT {return __m_;} };