Skip to content

Commit f8213c0

Browse files
committed
Add means to handle negative capabilities in thread safety annotations
1 parent 45a6811 commit f8213c0

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/sync.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ class LOCKABLE AnnotatedMixin : public PARENT
103103
}
104104

105105
using UniqueLock = std::unique_lock<PARENT>;
106+
#ifdef __clang__
107+
//! For negative capabilities in the Clang Thread Safety Analysis.
108+
//! A negative requirement uses the EXCLUSIVE_LOCKS_REQUIRED attribute, in conjunction
109+
//! with the ! operator, to indicate that a mutex should not be held.
110+
const AnnotatedMixin& operator!() const { return *this; }
111+
#endif // __clang__
106112
};
107113

108114
/**

src/threadsafety.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@
6060
// and should only be used when sync.h Mutex/LOCK/etc are not usable.
6161
class LOCKABLE StdMutex : public std::mutex
6262
{
63+
public:
64+
#ifdef __clang__
65+
//! For negative capabilities in the Clang Thread Safety Analysis.
66+
//! A negative requirement uses the EXCLUSIVE_LOCKS_REQUIRED attribute, in conjunction
67+
//! with the ! operator, to indicate that a mutex should not be held.
68+
const StdMutex& operator!() const { return *this; }
69+
#endif // __clang__
6370
};
6471

6572
// StdLockGuard provides an annotated version of std::lock_guard for us,

0 commit comments

Comments
 (0)