mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
Add thread safety annotated wrapper for std::mutex
Co-authored-by: Anthony Towns <aj@erisian.com.au>
This commit is contained in:
parent
55b4c65bd1
commit
79be487420
2 changed files with 9 additions and 3 deletions
|
@ -62,7 +62,7 @@ namespace BCLog {
|
||||||
class Logger
|
class Logger
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
mutable std::mutex m_cs; // Can not use Mutex from sync.h because in debug mode it would cause a deadlock when a potential deadlock was detected
|
mutable StdMutex m_cs; // Can not use Mutex from sync.h because in debug mode it would cause a deadlock when a potential deadlock was detected
|
||||||
|
|
||||||
FILE* m_fileout GUARDED_BY(m_cs) = nullptr;
|
FILE* m_fileout GUARDED_BY(m_cs) = nullptr;
|
||||||
std::list<std::string> m_msgs_before_open GUARDED_BY(m_cs);
|
std::list<std::string> m_msgs_before_open GUARDED_BY(m_cs);
|
||||||
|
|
|
@ -56,12 +56,18 @@
|
||||||
#define ASSERT_EXCLUSIVE_LOCK(...)
|
#define ASSERT_EXCLUSIVE_LOCK(...)
|
||||||
#endif // __GNUC__
|
#endif // __GNUC__
|
||||||
|
|
||||||
|
// StdMutex provides an annotated version of std::mutex for us,
|
||||||
|
// and should only be used when sync.h Mutex/LOCK/etc are not usable.
|
||||||
|
class LOCKABLE StdMutex : public std::mutex
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
// LockGuard provides an annotated version of lock_guard for us
|
// LockGuard provides an annotated version of lock_guard for us
|
||||||
// should only be used when sync.h Mutex/LOCK/etc aren't usable
|
// should only be used when sync.h Mutex/LOCK/etc aren't usable
|
||||||
class SCOPED_LOCKABLE LockGuard : public std::lock_guard<std::mutex>
|
class SCOPED_LOCKABLE LockGuard : public std::lock_guard<StdMutex>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit LockGuard(std::mutex& cs) EXCLUSIVE_LOCK_FUNCTION(cs) : std::lock_guard<std::mutex>(cs) { }
|
explicit LockGuard(StdMutex& cs) EXCLUSIVE_LOCK_FUNCTION(cs) : std::lock_guard<StdMutex>(cs) {}
|
||||||
~LockGuard() UNLOCK_FUNCTION() {};
|
~LockGuard() UNLOCK_FUNCTION() {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue