Skip to content

Commit

Permalink
merge bitcoin#19249: Add means to handle negative capabilities in thr…
Browse files Browse the repository at this point in the history
…ead safety annotations
  • Loading branch information
kwvg committed Jun 8, 2021
1 parent 5d9e69f commit 5e7cf89
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ class LOCKABLE AnnotatedMixin : public PARENT
}

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__
};

/**
Expand Down
7 changes: 7 additions & 0 deletions src/threadsafety.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5e7cf89

Please sign in to comment.