Add means to handle negative capabilities in thread safety annotations

This commit is contained in:
Hennadii Stepanov 2020-06-09 16:50:45 +03:00
parent 45a6811d36
commit f8213c05f0
No known key found for this signature in database
GPG Key ID: 410108112E7EA81F
2 changed files with 13 additions and 0 deletions

View File

@ -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__
};
/**

View File

@ -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,