Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
util
stdmutex.h
Go to the documentation of this file.
1
// Copyright (c) 2009-2010 Satoshi Nakamoto
2
// Copyright (c) 2009-present The Bitcoin Core developers
3
// Distributed under the MIT software license, see the accompanying
4
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6
#ifndef BITCOIN_UTIL_STDMUTEX_H
7
#define BITCOIN_UTIL_STDMUTEX_H
8
9
// This header declares threading primitives compatible with Clang
10
// Thread Safety Analysis and provides appropriate annotation macros.
11
#include <
threadsafety.h
>
// IWYU pragma: export
12
13
#include <
util/macros.h
>
14
15
#include <mutex>
16
17
// StdMutex provides an annotated version of std::mutex for us,
18
// and should only be used when sync.h Mutex/LOCK/etc are not usable.
19
class
LOCKABLE
StdMutex
:
public
std::mutex
20
{
21
public
:
22
#ifdef __clang__
26
const
StdMutex
& operator!()
const
{
return
*
this
; }
27
#endif
// __clang__
28
29
// StdMutex::Guard provides an annotated version of std::lock_guard for us.
30
class
SCOPED_LOCKABLE
Guard
:
public
std::lock_guard<StdMutex>
31
{
32
public
:
33
explicit
Guard
(
StdMutex
&
cs
)
EXCLUSIVE_LOCK_FUNCTION
(
cs
) :
std
::lock_guard<
StdMutex
>(
cs
) {}
34
~Guard
()
UNLOCK_FUNCTION
() = default;
35
};
36
37
static inline
StdMutex
&
CheckNotHeld
(
StdMutex
&
cs
)
EXCLUSIVE_LOCKS_REQUIRED
(!
cs
)
LOCK_RETURNED
(
cs
) {
return
cs
; }
38
};
39
40
// Provide STDLOCK(..) wrapper around StdMutex::Guard that checks the lock is not already held
41
#define STDLOCK(cs) StdMutex::Guard BITCOIN_UNIQUE_NAME(criticalblock){StdMutex::CheckNotHeld(cs)}
42
43
#endif
// BITCOIN_UTIL_STDMUTEX_H
cs
static void pool cs
Definition
blockencodings.cpp:31
StdMutex::Guard::Guard
Guard(StdMutex &cs) EXCLUSIVE_LOCK_FUNCTION(cs)
Definition
stdmutex.h:33
StdMutex::Guard::~Guard
~Guard() UNLOCK_FUNCTION()=default
StdMutex
Definition
stdmutex.h:20
StdMutex::CheckNotHeld
static StdMutex & CheckNotHeld(StdMutex &cs) EXCLUSIVE_LOCKS_REQUIRED(!cs) LOCK_RETURNED(cs)
Definition
stdmutex.h:37
macros.h
std
Definition
transaction.h:420
threadsafety.h
EXCLUSIVE_LOCKS_REQUIRED
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition
threadsafety.h:49
EXCLUSIVE_LOCK_FUNCTION
#define EXCLUSIVE_LOCK_FUNCTION(...)
Definition
threadsafety.h:41
SCOPED_LOCKABLE
#define SCOPED_LOCKABLE
Definition
threadsafety.h:36
LOCKABLE
#define LOCKABLE
Definition
threadsafety.h:35
LOCK_RETURNED
#define LOCK_RETURNED(x)
Definition
threadsafety.h:47
UNLOCK_FUNCTION
#define UNLOCK_FUNCTION(...)
Definition
threadsafety.h:45
Generated on
for Bitcoin Core by
1.18.0