Index: include/__threading_support =================================================================== --- include/__threading_support +++ include/__threading_support @@ -40,14 +40,30 @@ #define _LIBCPP_THREAD_ABI_VISIBILITY inline _LIBCPP_INLINE_VISIBILITY #endif +#if defined(__FreeBSD__) && !defined(_LIBCPP_DISABLE_THREAD_SAFETY_ATTRIBUTE) && \ + !defined(_LIBCPP_ENABLE_THREAD_SAFETY_ATTRIBUTE) +# define _LIBCPP_ENABLE_THREAD_SAFETY_ATTRIBUTE +#endif + +#ifndef _LIBCPP_THREAD_SAFETY_ATTRIBUTE +# if defined(__clang__) && __has_attribute(acquire_capability) && \ + defined(_LIBCPP_ENABLE_THREAD_SAFETY_ATTRIBUTE) +# define _LIBCPP_THREAD_SAFETY_ATTRIBUTE(x) __attribute__((x)) +# else +# define _LIBCPP_THREAD_SAFETY_ATTRIBUTE(x) +# endif +#endif + _LIBCPP_BEGIN_NAMESPACE_STD #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) // Mutex -typedef pthread_mutex_t __libcpp_mutex_t; +typedef pthread_mutex_t __libcpp_mutex_t +_LIBCPP_THREAD_SAFETY_ATTRIBUTE(capability("mutex")); #define _LIBCPP_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER -typedef pthread_mutex_t __libcpp_recursive_mutex_t; +typedef pthread_mutex_t __libcpp_recursive_mutex_t +_LIBCPP_THREAD_SAFETY_ATTRIBUTE(capability("mutex")); // Condition Variable typedef pthread_cond_t __libcpp_condvar_t; @@ -71,10 +87,12 @@ #define _LIBCPP_TLS_DESTRUCTOR_CC #else // Mutex -typedef SRWLOCK __libcpp_mutex_t; +typedef SRWLOCK __libcpp_mutex_t +_LIBCPP_THREAD_SAFETY_ATTRIBUTE(capability("mutex")); #define _LIBCPP_MUTEX_INITIALIZER SRWLOCK_INIT -typedef CRITICAL_SECTION __libcpp_recursive_mutex_t; +typedef CRITICAL_SECTION __libcpp_recursive_mutex_t +_LIBCPP_THREAD_SAFETY_ATTRIBUTE(capability("mutex")); // Condition Variable typedef CONDITION_VARIABLE __libcpp_condvar_t; @@ -103,25 +121,31 @@ int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m); _LIBCPP_THREAD_ABI_VISIBILITY -int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m); +int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m) +_LIBCPP_THREAD_SAFETY_ATTRIBUTE(acquire_capability(*__m)); _LIBCPP_THREAD_ABI_VISIBILITY -bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m); +bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m) +_LIBCPP_THREAD_SAFETY_ATTRIBUTE(try_acquire_capability(true, *__m)); _LIBCPP_THREAD_ABI_VISIBILITY -int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m); +int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m) +_LIBCPP_THREAD_SAFETY_ATTRIBUTE(release_capability(*__m)); _LIBCPP_THREAD_ABI_VISIBILITY int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m); _LIBCPP_THREAD_ABI_VISIBILITY -int __libcpp_mutex_lock(__libcpp_mutex_t *__m); +int __libcpp_mutex_lock(__libcpp_mutex_t *__m) +_LIBCPP_THREAD_SAFETY_ATTRIBUTE(acquire_capability(*__m)); _LIBCPP_THREAD_ABI_VISIBILITY -bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m); +bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m) +_LIBCPP_THREAD_SAFETY_ATTRIBUTE(try_acquire_capability(true, *__m)); _LIBCPP_THREAD_ABI_VISIBILITY -int __libcpp_mutex_unlock(__libcpp_mutex_t *__m); +int __libcpp_mutex_unlock(__libcpp_mutex_t *__m) +_LIBCPP_THREAD_SAFETY_ATTRIBUTE(release_capability(*__m)); _LIBCPP_THREAD_ABI_VISIBILITY int __libcpp_mutex_destroy(__libcpp_mutex_t *__m); @@ -134,11 +158,13 @@ int __libcpp_condvar_broadcast(__libcpp_condvar_t* __cv); _LIBCPP_THREAD_ABI_VISIBILITY -int __libcpp_condvar_wait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m); +int __libcpp_condvar_wait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m) +_LIBCPP_THREAD_SAFETY_ATTRIBUTE(requires_capability(*__m)); _LIBCPP_THREAD_ABI_VISIBILITY int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m, - timespec *__ts); + timespec *__ts) +_LIBCPP_THREAD_SAFETY_ATTRIBUTE(requires_capability(*__m)); _LIBCPP_THREAD_ABI_VISIBILITY int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv);