From cbc6186b6499384f1086d1ca45b8d5a6e15e9a50 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Tue, 9 Jun 2020 16:50:45 +0300 Subject: [PATCH] merge #19249: Add means to handle negative capabilities in thread safety annotations --- src/sync.h | 6 ++++++ src/threadsafety.h | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/src/sync.h b/src/sync.h index 916633c4f0..c17b344569 100644 --- a/src/sync.h +++ b/src/sync.h @@ -100,6 +100,12 @@ public: } using UniqueLock = std::unique_lock; +#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 300ea44298..b0ab1f315d 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,