aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/sync.h6
-rw-r--r--src/threadsafety.h7
2 files changed, 13 insertions, 0 deletions
diff --git a/src/sync.h b/src/sync.h
index 60e5a87aec..77327d8bfe 100644
--- a/src/sync.h
+++ b/src/sync.h
@@ -103,6 +103,12 @@ public:
}
using UniqueLock = std::unique_lock<PARENT>;
+#ifdef __clang__
+ //! For negative capabilities in the Clang Thread Safety Analysis.
+ //! A negative requirement uses the EXCLUSIVE_LOCKS_REQUIRED attribute, in conjunction
+ //! with the ! operator, to indicate that a mutex should not be held.
+ const AnnotatedMixin& operator!() const { return *this; }
+#endif // __clang__
};
/**
diff --git a/src/threadsafety.h b/src/threadsafety.h
index 942aa3fdcd..5f2c40bac6 100644
--- a/src/threadsafety.h
+++ b/src/threadsafety.h
@@ -60,6 +60,13 @@
// and should only be used when sync.h Mutex/LOCK/etc are not usable.
class LOCKABLE StdMutex : public std::mutex
{
+public:
+#ifdef __clang__
+ //! For negative capabilities in the Clang Thread Safety Analysis.
+ //! A negative requirement uses the EXCLUSIVE_LOCKS_REQUIRED attribute, in conjunction
+ //! with the ! operator, to indicate that a mutex should not be held.
+ const StdMutex& operator!() const { return *this; }
+#endif // __clang__
};
// StdLockGuard provides an annotated version of std::lock_guard for us,