Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@

// Enable thread safety attributes only with clang.
// The attributes can be safely erased when compiling with other compilers.
#if defined(HAVE_THREAD_SAFETY_ATTRIBUTES)
#if !defined(HAVE_THREAD_SAFETY_ATTRIBUTES)
#if defined(__clang__) && defined(__has_attribute)
#if __has_attribute(capability) && __has_attribute(scoped_lockable) && \
__has_attribute(guarded_by)
#define HAVE_THREAD_SAFETY_ATTRIBUTES 1
#endif
#endif
#endif

#if defined(HAVE_THREAD_SAFETY_ATTRIBUTES) && HAVE_THREAD_SAFETY_ATTRIBUTES
#define THREAD_ANNOTATION_ATTRIBUTE_(x) __attribute__((x))
#else
#define THREAD_ANNOTATION_ATTRIBUTE_(x) // no-op
Expand Down Expand Up @@ -76,8 +85,8 @@ class CAPABILITY("mutex") Mutex {
public:
Mutex() {}

void lock() ACQUIRE() { mut_.lock(); }
void unlock() RELEASE() { mut_.unlock(); }
void lock() ACQUIRE() NO_THREAD_SAFETY_ANALYSIS { mut_.lock(); }
void unlock() RELEASE() NO_THREAD_SAFETY_ANALYSIS { mut_.unlock(); }
std::mutex& native_handle() { return mut_; }

private:
Expand Down