Coverage Report

Created: 2026-06-01 18:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/bitcoin/src/sync.h
Line
Count
Source
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_SYNC_H
7
#define BITCOIN_SYNC_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
#include <util/macros.h>
13
14
#include <cassert>
15
#include <condition_variable>
16
#include <mutex>
17
#include <string>
18
#include <thread>
19
20
////////////////////////////////////////////////
21
//                                            //
22
// THE SIMPLE DEFINITION, EXCLUDING DEBUG CODE //
23
//                                            //
24
////////////////////////////////////////////////
25
26
/*
27
RecursiveMutex mutex;
28
    std::recursive_mutex mutex;
29
30
LOCK(mutex);
31
    std::unique_lock<std::recursive_mutex> criticalblock(mutex);
32
33
LOCK2(mutex1, mutex2);
34
    std::unique_lock<std::recursive_mutex> criticalblock1(mutex1);
35
    std::unique_lock<std::recursive_mutex> criticalblock2(mutex2);
36
37
TRY_LOCK(mutex, name);
38
    std::unique_lock<std::recursive_mutex> name(mutex, std::try_to_lock_t);
39
 */
40
41
///////////////////////////////
42
//                           //
43
// THE ACTUAL IMPLEMENTATION //
44
//                           //
45
///////////////////////////////
46
47
#ifdef DEBUG_LOCKORDER
48
template <typename MutexType>
49
void EnterCritical(const char* pszName, const char* pszFile, int nLine, MutexType* cs, bool fTry = false);
50
void LeaveCritical();
51
void CheckLastCritical(void* cs, std::string& lockname, const char* guardname, const char* file, int line);
52
template <typename MutexType>
53
void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs) EXCLUSIVE_LOCKS_REQUIRED(cs);
54
template <typename MutexType>
55
void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs) LOCKS_EXCLUDED(cs);
56
void DeleteLock(void* cs);
57
bool LockStackEmpty();
58
59
/**
60
 * Call abort() if a potential lock order deadlock bug is detected, instead of
61
 * just logging information and throwing a logic_error. Defaults to true, and
62
 * set to false in DEBUG_LOCKORDER unit tests.
63
 */
64
extern bool g_debug_lockorder_abort;
65
#else
66
template <typename MutexType>
67
400k
inline void EnterCritical(const char* pszName, const char* pszFile, int nLine, MutexType* cs, bool fTry = false) {}
void EnterCritical<std::mutex>(char const*, char const*, int, std::mutex*, bool)
Line
Count
Source
67
392k
inline void EnterCritical(const char* pszName, const char* pszFile, int nLine, MutexType* cs, bool fTry = false) {}
void EnterCritical<std::recursive_mutex>(char const*, char const*, int, std::recursive_mutex*, bool)
Line
Count
Source
67
7.93k
inline void EnterCritical(const char* pszName, const char* pszFile, int nLine, MutexType* cs, bool fTry = false) {}
68
404k
inline void LeaveCritical() {}
69
1.86k
inline void CheckLastCritical(void* cs, std::string& lockname, const char* guardname, const char* file, int line) {}
70
template <typename MutexType>
71
15.5k
inline void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs) EXCLUSIVE_LOCKS_REQUIRED(cs) {}
void AssertLockHeldInternal<AnnotatedMixin<std::mutex> >(char const*, char const*, int, AnnotatedMixin<std::mutex>*)
Line
Count
Source
71
7.31k
inline void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs) EXCLUSIVE_LOCKS_REQUIRED(cs) {}
void AssertLockHeldInternal<AnnotatedMixin<std::recursive_mutex> >(char const*, char const*, int, AnnotatedMixin<std::recursive_mutex>*)
Line
Count
Source
71
8.23k
inline void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs) EXCLUSIVE_LOCKS_REQUIRED(cs) {}
72
template <typename MutexType>
73
4.46k
void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs) LOCKS_EXCLUDED(cs) {}
void AssertLockNotHeldInternal<AnnotatedMixin<std::mutex> >(char const*, char const*, int, AnnotatedMixin<std::mutex>*)
Line
Count
Source
73
3.85k
void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs) LOCKS_EXCLUDED(cs) {}
void AssertLockNotHeldInternal<AnnotatedMixin<std::recursive_mutex> >(char const*, char const*, int, AnnotatedMixin<std::recursive_mutex>*)
Line
Count
Source
73
609
void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs) LOCKS_EXCLUDED(cs) {}
Unexecuted instantiation: void AssertLockNotHeldInternal<GlobalMutex>(char const*, char const*, int, GlobalMutex*)
74
39.5k
inline void DeleteLock(void* cs) {}
75
0
inline bool LockStackEmpty() { return true; }
76
#endif
77
78
/*
79
 * Called when a mutex fails to lock immediately because it is held by another
80
 * thread, or spuriously. Responsible for locking the lock before returning.
81
 */
82
#ifdef DEBUG_LOCKCONTENTION
83
84
template <typename LockType>
85
void ContendedLock(std::string_view name, std::string_view file, int nLine, LockType& lock);
86
#endif
87
88
/**
89
 * Template mixin that adds -Wthread-safety locking annotations and lock order
90
 * checking to a subset of the mutex API.
91
 */
92
template <typename PARENT>
93
class LOCKABLE AnnotatedMixin : public PARENT
94
{
95
public:
96
39.5k
    ~AnnotatedMixin() {
97
39.5k
        DeleteLock((void*)this);
98
39.5k
    }
AnnotatedMixin<std::mutex>::~AnnotatedMixin()
Line
Count
Source
96
35.8k
    ~AnnotatedMixin() {
97
35.8k
        DeleteLock((void*)this);
98
35.8k
    }
AnnotatedMixin<std::recursive_mutex>::~AnnotatedMixin()
Line
Count
Source
96
3.66k
    ~AnnotatedMixin() {
97
3.66k
        DeleteLock((void*)this);
98
3.66k
    }
99
100
    void lock() EXCLUSIVE_LOCK_FUNCTION()
101
    {
102
        PARENT::lock();
103
    }
104
105
    void unlock() UNLOCK_FUNCTION()
106
    {
107
        PARENT::unlock();
108
    }
109
110
    bool try_lock() EXCLUSIVE_TRYLOCK_FUNCTION(true)
111
    {
112
        return PARENT::try_lock();
113
    }
114
115
    using unique_lock = std::unique_lock<PARENT>;
116
#ifdef __clang__
117
    //! For negative capabilities in the Clang Thread Safety Analysis.
118
    //! A negative requirement uses the EXCLUSIVE_LOCKS_REQUIRED attribute, in conjunction
119
    //! with the ! operator, to indicate that a mutex should not be held.
120
    const AnnotatedMixin& operator!() const { return *this; }
121
#endif // __clang__
122
};
123
124
/**
125
 * Wrapped mutex: supports recursive locking, but no waiting
126
 * TODO: We should move away from using the recursive lock by default.
127
 */
128
using RecursiveMutex = AnnotatedMixin<std::recursive_mutex>;
129
130
/** Wrapped mutex: supports waiting but not recursive locking */
131
using Mutex = AnnotatedMixin<std::mutex>;
132
133
/** Different type to mark Mutex at global scope
134
 *
135
 * Thread safety analysis can't handle negative assertions about mutexes
136
 * with global scope well, so mark them with a separate type, and
137
 * eventually move all the mutexes into classes so they are not globally
138
 * visible.
139
 *
140
 * See: https://github.com/bitcoin/bitcoin/pull/20272#issuecomment-720755781
141
 */
142
class GlobalMutex : public Mutex { };
143
144
15.5k
#define AssertLockHeld(cs) AssertLockHeldInternal(#cs, __FILE__, __LINE__, &cs)
145
146
3.85k
inline void AssertLockNotHeldInline(const char* name, const char* file, int line, Mutex* cs) EXCLUSIVE_LOCKS_REQUIRED(!cs) { AssertLockNotHeldInternal(name, file, line, cs); }
147
609
inline void AssertLockNotHeldInline(const char* name, const char* file, int line, RecursiveMutex* cs) LOCKS_EXCLUDED(cs) { AssertLockNotHeldInternal(name, file, line, cs); }
148
0
inline void AssertLockNotHeldInline(const char* name, const char* file, int line, GlobalMutex* cs) LOCKS_EXCLUDED(cs) { AssertLockNotHeldInternal(name, file, line, cs); }
149
4.46k
#define AssertLockNotHeld(cs) AssertLockNotHeldInline(#cs, __FILE__, __LINE__, &cs)
150
151
/** Wrapper around std::unique_lock style lock for MutexType. */
152
template <typename MutexType>
153
class SCOPED_LOCKABLE UniqueLock : public MutexType::unique_lock
154
{
155
private:
156
    using Base = typename MutexType::unique_lock;
157
158
    void Enter(const char* pszName, const char* pszFile, int nLine)
159
398k
    {
160
398k
        EnterCritical(pszName, pszFile, nLine, Base::mutex());
161
#ifdef DEBUG_LOCKCONTENTION
162
        if (!Base::try_lock()) {
163
            ContendedLock(pszName, pszFile, nLine, static_cast<Base&>(*this));
164
        }
165
#else
166
398k
        Base::lock();
167
398k
#endif
168
398k
    }
UniqueLock<AnnotatedMixin<std::mutex> >::Enter(char const*, char const*, int)
Line
Count
Source
159
382k
    {
160
382k
        EnterCritical(pszName, pszFile, nLine, Base::mutex());
161
#ifdef DEBUG_LOCKCONTENTION
162
        if (!Base::try_lock()) {
163
            ContendedLock(pszName, pszFile, nLine, static_cast<Base&>(*this));
164
        }
165
#else
166
382k
        Base::lock();
167
382k
#endif
168
382k
    }
UniqueLock<AnnotatedMixin<std::recursive_mutex> >::Enter(char const*, char const*, int)
Line
Count
Source
159
7.93k
    {
160
7.93k
        EnterCritical(pszName, pszFile, nLine, Base::mutex());
161
#ifdef DEBUG_LOCKCONTENTION
162
        if (!Base::try_lock()) {
163
            ContendedLock(pszName, pszFile, nLine, static_cast<Base&>(*this));
164
        }
165
#else
166
7.93k
        Base::lock();
167
7.93k
#endif
168
7.93k
    }
UniqueLock<GlobalMutex>::Enter(char const*, char const*, int)
Line
Count
Source
159
7.71k
    {
160
7.71k
        EnterCritical(pszName, pszFile, nLine, Base::mutex());
161
#ifdef DEBUG_LOCKCONTENTION
162
        if (!Base::try_lock()) {
163
            ContendedLock(pszName, pszFile, nLine, static_cast<Base&>(*this));
164
        }
165
#else
166
7.71k
        Base::lock();
167
7.71k
#endif
168
7.71k
    }
169
170
    bool TryEnter(const char* pszName, const char* pszFile, int nLine)
171
305
    {
172
305
        EnterCritical(pszName, pszFile, nLine, Base::mutex(), true);
173
305
        if (Base::try_lock()) {
  Branch (173:13): [True: 305, False: 0]
  Branch (173:13): [True: 0, False: 0]
  Branch (173:13): [True: 0, False: 0]
174
305
            return true;
175
305
        }
176
0
        LeaveCritical();
177
0
        return false;
178
305
    }
UniqueLock<AnnotatedMixin<std::mutex> >::TryEnter(char const*, char const*, int)
Line
Count
Source
171
305
    {
172
305
        EnterCritical(pszName, pszFile, nLine, Base::mutex(), true);
173
305
        if (Base::try_lock()) {
  Branch (173:13): [True: 305, False: 0]
174
305
            return true;
175
305
        }
176
0
        LeaveCritical();
177
0
        return false;
178
305
    }
Unexecuted instantiation: UniqueLock<AnnotatedMixin<std::recursive_mutex> >::TryEnter(char const*, char const*, int)
Unexecuted instantiation: UniqueLock<GlobalMutex>::TryEnter(char const*, char const*, int)
179
180
public:
181
398k
    UniqueLock(MutexType& mutexIn, const char* pszName, const char* pszFile, int nLine, bool fTry = false) EXCLUSIVE_LOCK_FUNCTION(mutexIn) : Base(mutexIn, std::defer_lock)
182
398k
    {
183
398k
        if (fTry)
  Branch (183:13): [True: 305, False: 382k]
  Branch (183:13): [True: 0, False: 7.93k]
  Branch (183:13): [True: 0, False: 7.71k]
184
305
            TryEnter(pszName, pszFile, nLine);
185
398k
        else
186
398k
            Enter(pszName, pszFile, nLine);
187
398k
    }
UniqueLock<AnnotatedMixin<std::mutex> >::UniqueLock(AnnotatedMixin<std::mutex>&, char const*, char const*, int, bool)
Line
Count
Source
181
382k
    UniqueLock(MutexType& mutexIn, const char* pszName, const char* pszFile, int nLine, bool fTry = false) EXCLUSIVE_LOCK_FUNCTION(mutexIn) : Base(mutexIn, std::defer_lock)
182
382k
    {
183
382k
        if (fTry)
  Branch (183:13): [True: 305, False: 382k]
184
305
            TryEnter(pszName, pszFile, nLine);
185
382k
        else
186
382k
            Enter(pszName, pszFile, nLine);
187
382k
    }
UniqueLock<AnnotatedMixin<std::recursive_mutex> >::UniqueLock(AnnotatedMixin<std::recursive_mutex>&, char const*, char const*, int, bool)
Line
Count
Source
181
7.93k
    UniqueLock(MutexType& mutexIn, const char* pszName, const char* pszFile, int nLine, bool fTry = false) EXCLUSIVE_LOCK_FUNCTION(mutexIn) : Base(mutexIn, std::defer_lock)
182
7.93k
    {
183
7.93k
        if (fTry)
  Branch (183:13): [True: 0, False: 7.93k]
184
0
            TryEnter(pszName, pszFile, nLine);
185
7.93k
        else
186
7.93k
            Enter(pszName, pszFile, nLine);
187
7.93k
    }
UniqueLock<GlobalMutex>::UniqueLock(GlobalMutex&, char const*, char const*, int, bool)
Line
Count
Source
181
7.71k
    UniqueLock(MutexType& mutexIn, const char* pszName, const char* pszFile, int nLine, bool fTry = false) EXCLUSIVE_LOCK_FUNCTION(mutexIn) : Base(mutexIn, std::defer_lock)
182
7.71k
    {
183
7.71k
        if (fTry)
  Branch (183:13): [True: 0, False: 7.71k]
184
0
            TryEnter(pszName, pszFile, nLine);
185
7.71k
        else
186
7.71k
            Enter(pszName, pszFile, nLine);
187
7.71k
    }
188
189
    UniqueLock(MutexType* pmutexIn, const char* pszName, const char* pszFile, int nLine, bool fTry = false) EXCLUSIVE_LOCK_FUNCTION(pmutexIn)
190
0
    {
191
0
        if (!pmutexIn) return;
  Branch (191:13): [True: 0, False: 0]
192
193
0
        *static_cast<Base*>(this) = Base(*pmutexIn, std::defer_lock);
194
0
        if (fTry)
  Branch (194:13): [True: 0, False: 0]
195
0
            TryEnter(pszName, pszFile, nLine);
196
0
        else
197
0
            Enter(pszName, pszFile, nLine);
198
0
    }
199
200
    ~UniqueLock() UNLOCK_FUNCTION()
201
404k
    {
202
404k
        if (Base::owns_lock())
  Branch (202:13): [True: 386k, False: 1.86k]
  Branch (202:13): [True: 7.93k, False: 0]
  Branch (202:13): [True: 7.71k, False: 0]
203
402k
            LeaveCritical();
204
404k
    }
UniqueLock<AnnotatedMixin<std::mutex> >::~UniqueLock()
Line
Count
Source
201
388k
    {
202
388k
        if (Base::owns_lock())
  Branch (202:13): [True: 386k, False: 1.86k]
203
386k
            LeaveCritical();
204
388k
    }
UniqueLock<AnnotatedMixin<std::recursive_mutex> >::~UniqueLock()
Line
Count
Source
201
7.93k
    {
202
7.93k
        if (Base::owns_lock())
  Branch (202:13): [True: 7.93k, False: 0]
203
7.93k
            LeaveCritical();
204
7.93k
    }
UniqueLock<GlobalMutex>::~UniqueLock()
Line
Count
Source
201
7.71k
    {
202
7.71k
        if (Base::owns_lock())
  Branch (202:13): [True: 7.71k, False: 0]
203
7.71k
            LeaveCritical();
204
7.71k
    }
205
206
    operator bool()
207
305
    {
208
305
        return Base::owns_lock();
209
305
    }
UniqueLock<AnnotatedMixin<std::mutex> >::operator bool()
Line
Count
Source
207
305
    {
208
305
        return Base::owns_lock();
209
305
    }
Unexecuted instantiation: UniqueLock<AnnotatedMixin<std::recursive_mutex> >::operator bool()
210
211
protected:
212
    // needed for reverse_lock
213
1.86k
    UniqueLock() = default;
UniqueLock<AnnotatedMixin<std::mutex> >::UniqueLock()
Line
Count
Source
213
1.86k
    UniqueLock() = default;
Unexecuted instantiation: UniqueLock<AnnotatedMixin<std::recursive_mutex> >::UniqueLock()
214
215
public:
216
    /**
217
     * An RAII-style reverse lock. Unlocks on construction and locks on destruction.
218
     */
219
    class SCOPED_LOCKABLE reverse_lock {
220
    public:
221
1.86k
        explicit reverse_lock(UniqueLock& _lock, const MutexType& mutex, const char* _guardname, const char* _file, int _line) UNLOCK_FUNCTION(mutex) : lock(_lock), file(_file), line(_line) {
222
            // Ensure that mutex passed back for thread-safety analysis is indeed the original
223
1.86k
            assert(std::addressof(mutex) == lock.mutex());
  Branch (223:13): [True: 1.86k, False: 0]
  Branch (223:13): [True: 0, False: 0]
224
225
1.86k
            CheckLastCritical((void*)lock.mutex(), lockname, _guardname, _file, _line);
226
1.86k
            lock.unlock();
227
1.86k
            LeaveCritical();
228
1.86k
            lock.swap(templock);
229
1.86k
        }
UniqueLock<AnnotatedMixin<std::mutex> >::reverse_lock::reverse_lock(UniqueLock<AnnotatedMixin<std::mutex> >&, AnnotatedMixin<std::mutex> const&, char const*, char const*, int)
Line
Count
Source
221
1.86k
        explicit reverse_lock(UniqueLock& _lock, const MutexType& mutex, const char* _guardname, const char* _file, int _line) UNLOCK_FUNCTION(mutex) : lock(_lock), file(_file), line(_line) {
222
            // Ensure that mutex passed back for thread-safety analysis is indeed the original
223
1.86k
            assert(std::addressof(mutex) == lock.mutex());
  Branch (223:13): [True: 1.86k, False: 0]
224
225
1.86k
            CheckLastCritical((void*)lock.mutex(), lockname, _guardname, _file, _line);
226
1.86k
            lock.unlock();
227
1.86k
            LeaveCritical();
228
1.86k
            lock.swap(templock);
229
1.86k
        }
Unexecuted instantiation: UniqueLock<AnnotatedMixin<std::recursive_mutex> >::reverse_lock::reverse_lock(UniqueLock<AnnotatedMixin<std::recursive_mutex> >&, AnnotatedMixin<std::recursive_mutex> const&, char const*, char const*, int)
230
231
1.86k
        ~reverse_lock() UNLOCK_FUNCTION() {
232
1.86k
            templock.swap(lock);
233
1.86k
            EnterCritical(lockname.c_str(), file.c_str(), line, lock.mutex());
234
1.86k
            lock.lock();
235
1.86k
        }
UniqueLock<AnnotatedMixin<std::mutex> >::reverse_lock::~reverse_lock()
Line
Count
Source
231
1.86k
        ~reverse_lock() UNLOCK_FUNCTION() {
232
1.86k
            templock.swap(lock);
233
1.86k
            EnterCritical(lockname.c_str(), file.c_str(), line, lock.mutex());
234
1.86k
            lock.lock();
235
1.86k
        }
Unexecuted instantiation: UniqueLock<AnnotatedMixin<std::recursive_mutex> >::reverse_lock::~reverse_lock()
236
237
     private:
238
        reverse_lock(reverse_lock const&);
239
        reverse_lock& operator=(reverse_lock const&);
240
241
        UniqueLock& lock;
242
        UniqueLock templock;
243
        std::string lockname;
244
        const std::string file;
245
        const int line;
246
     };
247
     friend class reverse_lock;
248
};
249
250
// clang's thread-safety analyzer is unable to deal with aliases of mutexes, so
251
// it is not possible to use the lock's copy of the mutex for that purpose.
252
// Instead, the original mutex needs to be passed back to the reverse_lock for
253
// the sake of thread-safety analysis, but it is not actually used otherwise.
254
341
#define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__)
255
256
// When locking a Mutex, require negative capability to ensure the lock
257
// is not already held
258
733k
inline Mutex& MaybeCheckNotHeld(Mutex& cs) EXCLUSIVE_LOCKS_REQUIRED(!cs) LOCK_RETURNED(cs) { return cs; }
259
0
inline Mutex* MaybeCheckNotHeld(Mutex* cs) EXCLUSIVE_LOCKS_REQUIRED(!cs) LOCK_RETURNED(cs) { return cs; }
260
261
// When locking a GlobalMutex or RecursiveMutex, just check it is not
262
// locked in the surrounding scope.
263
template <typename MutexType>
264
16.5k
inline MutexType& MaybeCheckNotHeld(MutexType& m) LOCKS_EXCLUDED(m) LOCK_RETURNED(m) { return m; }
AnnotatedMixin<std::recursive_mutex>& MaybeCheckNotHeld<AnnotatedMixin<std::recursive_mutex> >(AnnotatedMixin<std::recursive_mutex>&)
Line
Count
Source
264
8.84k
inline MutexType& MaybeCheckNotHeld(MutexType& m) LOCKS_EXCLUDED(m) LOCK_RETURNED(m) { return m; }
GlobalMutex& MaybeCheckNotHeld<GlobalMutex>(GlobalMutex&)
Line
Count
Source
264
7.71k
inline MutexType& MaybeCheckNotHeld(MutexType& m) LOCKS_EXCLUDED(m) LOCK_RETURNED(m) { return m; }
265
template <typename MutexType>
266
0
inline MutexType* MaybeCheckNotHeld(MutexType* m) LOCKS_EXCLUDED(m) LOCK_RETURNED(m) { return m; }
267
268
397k
#define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__)
269
#define LOCK2(cs1, cs2)                                               \
270
0
    UniqueLock criticalblock1(MaybeCheckNotHeld(cs1), #cs1, __FILE__, __LINE__); \
271
0
    UniqueLock criticalblock2(MaybeCheckNotHeld(cs2), #cs2, __FILE__, __LINE__)
272
1.57k
#define LOCK_ARGS(cs) MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__
273
305
#define TRY_LOCK(cs, name) UniqueLock name(LOCK_ARGS(cs), true)
274
1.26k
#define WAIT_LOCK(cs, name) UniqueLock name(LOCK_ARGS(cs))
275
276
//! Run code while locking a mutex.
277
//!
278
//! Examples:
279
//!
280
//!   WITH_LOCK(cs, shared_val = shared_val + 1);
281
//!
282
//!   int val = WITH_LOCK(cs, return shared_val);
283
//!
284
//! Note:
285
//!
286
//! Since the return type deduction follows that of decltype(auto), while the
287
//! deduced type of:
288
//!
289
//!   WITH_LOCK(cs, int i = 1; return i);
290
//!
291
//! is int, the deduced type of:
292
//!
293
//!   WITH_LOCK(cs, int j = 1; return (j));
294
//!
295
//! is &int, a reference to a local variable
296
//!
297
//! The above is detectable at compile-time with the -Wreturn-local-addr flag in
298
//! gcc and the -Wreturn-stack-address flag in clang, both enabled by default.
299
351k
#define WITH_LOCK(cs, code) (MaybeCheckNotHeld(cs), [&]() -> decltype(auto) { LOCK(cs); code; }())
init.cpp:Interrupt(node::NodeContext&)::$_0::operator()() const
Line
Count
Source
299
305
#define WITH_LOCK(cs, code) (MaybeCheckNotHeld(cs), [&]() -> decltype(auto) { LOCK(cs); code; }())
CScheduler::stop()::{lambda()#1}::operator()() const
Line
Count
Source
299
305
#define WITH_LOCK(cs, code) (MaybeCheckNotHeld(cs), [&]() -> decltype(auto) { LOCK(cs); code; }())
Unexecuted instantiation: init.cpp:AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_8::operator()() const
Unexecuted instantiation: init.cpp:AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_9::operator()() const
Unexecuted instantiation: init.cpp:StartIndexBackgroundSync(node::NodeContext&)::$_0::operator()() const
Unexecuted instantiation: init.cpp:StartIndexBackgroundSync(node::NodeContext&)::$_1::operator()() const
Unexecuted instantiation: init.cpp:AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_10::operator()() const::{lambda()#1}::operator()() const
httpserver.cpp:http_bitcoin::HTTPServer::SocketHandlerConnected(http_bitcoin::HTTPServer::IOReadiness const&) const::$_0::operator()() const
Line
Count
Source
299
10.0k
#define WITH_LOCK(cs, code) (MaybeCheckNotHeld(cs), [&]() -> decltype(auto) { LOCK(cs); code; }())
httpserver.cpp:http_bitcoin::HTTPServer::GenerateWaitSockets() const::$_0::operator()() const
Line
Count
Source
299
337k
#define WITH_LOCK(cs, code) (MaybeCheckNotHeld(cs), [&]() -> decltype(auto) { LOCK(cs); code; }())
ThreadPool::WorkQueueSize()::{lambda()#1}::operator()() const
Line
Count
Source
299
952
#define WITH_LOCK(cs, code) (MaybeCheckNotHeld(cs), [&]() -> decltype(auto) { LOCK(cs); code; }())
http_bitcoin::HTTPServer::SetRequestHandler(std::function<void (std::unique_ptr<http_bitcoin::HTTPRequest, std::default_delete<http_bitcoin::HTTPRequest> >&&)>)::{lambda()#1}::operator()() const
Line
Count
Source
299
305
#define WITH_LOCK(cs, code) (MaybeCheckNotHeld(cs), [&]() -> decltype(auto) { LOCK(cs); code; }())
ThreadPool::Interrupt()::{lambda()#1}::operator()() const
Line
Count
Source
299
305
#define WITH_LOCK(cs, code) (MaybeCheckNotHeld(cs), [&]() -> decltype(auto) { LOCK(cs); code; }())
Unexecuted instantiation: base.cpp:BaseIndex::Init()::$_0::operator()() const
Unexecuted instantiation: base.cpp:BaseIndex::Sync()::$_0::operator()() const
Unexecuted instantiation: base.cpp:BaseIndex::SetBestBlockIndex(CBlockIndex const*)::$_0::operator()() const
Unexecuted instantiation: V1Transport::ReceivedMessageComplete() const::{lambda()#1}::operator()() const
Unexecuted instantiation: net.cpp:CConnman::AddConnection(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ConnectionType, bool)::$_0::operator()() const
Unexecuted instantiation: net.cpp:CConnman::SocketHandlerConnected(std::vector<CNode*, std::allocator<CNode*> > const&, std::unordered_map<std::shared_ptr<Sock const>, Sock::Events, Sock::HashSharedPtrSock, Sock::EqualSharedPtrSock, std::allocator<std::pair<std::shared_ptr<Sock const> const, Sock::Events> > > const&)::$_0::operator()() const
net.cpp:CConnman::StopNodes()::$_0::operator()() const
Line
Count
Source
299
610
#define WITH_LOCK(cs, code) (MaybeCheckNotHeld(cs), [&]() -> decltype(auto) { LOCK(cs); code; }())
net.cpp:CConnman::StopNodes()::$_1::operator()() const
Line
Count
Source
299
610
#define WITH_LOCK(cs, code) (MaybeCheckNotHeld(cs), [&]() -> decltype(auto) { LOCK(cs); code; }())
Unexecuted instantiation: net_processing.cpp:(anonymous namespace)::Peer::GetTxRelay()::{lambda()#1}::operator()() const
Unexecuted instantiation: net_processing.cpp:(anonymous namespace)::PeerManagerImpl::GetNodeStateStats(long, CNodeStateStats&) const::$_0::operator()() const
Unexecuted instantiation: net_processing.cpp:(anonymous namespace)::PeerManagerImpl::InitializeNode(CNode const&, ServiceFlags)::$_0::operator()() const
Unexecuted instantiation: net_processing.cpp:(anonymous namespace)::PeerManagerImpl::FinalizeNode(CNode const&)::$_0::operator()() const
Unexecuted instantiation: net_processing.cpp:(anonymous namespace)::PeerManagerImpl::FindTxForGetData((anonymous namespace)::Peer::TxRelay const&, GenTxid const&)::$_0::operator()<transaction_identifier<false> >(transaction_identifier<false> const&) const::{lambda()#1}::operator()() const
Unexecuted instantiation: net_processing.cpp:(anonymous namespace)::PeerManagerImpl::FindTxForGetData((anonymous namespace)::Peer::TxRelay const&, GenTxid const&)::$_0::operator()<transaction_identifier<true> >(transaction_identifier<true> const&) const::{lambda()#1}::operator()() const
Unexecuted instantiation: net_processing.cpp:(anonymous namespace)::PeerManagerImpl::ProcessGetBlockData(CNode&, (anonymous namespace)::Peer&, CInv const&)::$_0::operator()() const
Unexecuted instantiation: net_processing.cpp:(anonymous namespace)::PeerManagerImpl::ProcessGetBlockData(CNode&, (anonymous namespace)::Peer&, CInv const&)::$_1::operator()() const
Unexecuted instantiation: net_processing.cpp:(anonymous namespace)::PeerManagerImpl::ProcessMessage((anonymous namespace)::Peer&, CNode&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, DataStream&, std::chrono::time_point<NodeClock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > >, std::atomic<bool> const&)::$_0::operator()() const
Unexecuted instantiation: net_processing.cpp:(anonymous namespace)::PeerManagerImpl::ProcessMessage((anonymous namespace)::Peer&, CNode&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, DataStream&, std::chrono::time_point<NodeClock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > >, std::atomic<bool> const&)::$_3::operator()() const
Unexecuted instantiation: net_processing.cpp:(anonymous namespace)::PeerManagerImpl::ProcessMessage((anonymous namespace)::Peer&, CNode&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, DataStream&, std::chrono::time_point<NodeClock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > >, std::atomic<bool> const&)::$_4::operator()() const
Unexecuted instantiation: net_processing.cpp:(anonymous namespace)::PeerManagerImpl::ProcessMessage((anonymous namespace)::Peer&, CNode&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, DataStream&, std::chrono::time_point<NodeClock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > >, std::atomic<bool> const&)::$_5::operator()() const
Unexecuted instantiation: net_processing.cpp:(anonymous namespace)::PeerManagerImpl::ProcessMessage((anonymous namespace)::Peer&, CNode&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, DataStream&, std::chrono::time_point<NodeClock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > >, std::atomic<bool> const&)::$_6::operator()() const
Unexecuted instantiation: net_processing.cpp:(anonymous namespace)::PeerManagerImpl::ProcessHeadersMessage(CNode&, (anonymous namespace)::Peer&, std::vector<CBlockHeader, std::allocator<CBlockHeader> >&&, bool)::$_0::operator()() const
Unexecuted instantiation: net_processing.cpp:(anonymous namespace)::PeerManagerImpl::HandleUnconnectingHeaders(CNode&, (anonymous namespace)::Peer&, std::vector<CBlockHeader, std::allocator<CBlockHeader> > const&)::$_0::operator()() const
Unexecuted instantiation: net_processing.cpp:(anonymous namespace)::PeerManagerImpl::HandleUnconnectingHeaders(CNode&, (anonymous namespace)::Peer&, std::vector<CBlockHeader, std::allocator<CBlockHeader> > const&)::$_1::operator()() const
Unexecuted instantiation: net_processing.cpp:(anonymous namespace)::PeerManagerImpl::ProcessMessage((anonymous namespace)::Peer&, CNode&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, DataStream&, std::chrono::time_point<NodeClock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > >, std::atomic<bool> const&)::$_7::operator()() const
Unexecuted instantiation: net_processing.cpp:(anonymous namespace)::PeerManagerImpl::ProcessMessage((anonymous namespace)::Peer&, CNode&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, DataStream&, std::chrono::time_point<NodeClock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > >, std::atomic<bool> const&)::$_8::operator()() const
blockstorage.cpp:node::BlockManager::WriteBlockIndexDB()::$_0::operator()() const
Line
Count
Source
299
610
#define WITH_LOCK(cs, code) (MaybeCheckNotHeld(cs), [&]() -> decltype(auto) { LOCK(cs); code; }())
Unexecuted instantiation: blockstorage.cpp:node::BlockManager::ScanAndUnlinkAlreadyPrunedFiles()::$_0::operator()() const
Unexecuted instantiation: blockstorage.cpp:node::BlockManager::ReadBlockUndo(CBlockUndo&, CBlockIndex const&) const::$_0::operator()() const
Unexecuted instantiation: blockstorage.cpp:node::BlockManager::ReadBlock(CBlock&, CBlockIndex const&) const::$_0::operator()() const
Unexecuted instantiation: blockstorage.cpp:node::ImportBlocks(ChainstateManager&, std::span<fs::path const, 18446744073709551615ul>)::$_0::operator()() const
Unexecuted instantiation: interfaces.cpp:node::(anonymous namespace)::NodeImpl::getBestBlockHash()::{lambda()#1}::operator()() const
Unexecuted instantiation: interfaces.cpp:node::(anonymous namespace)::ChainImpl::getHeight()::{lambda()#1}::operator()() const
Unexecuted instantiation: interfaces.cpp:node::(anonymous namespace)::ChainImpl::blockFilterMatchesAny(BlockFilterType, uint256 const&, std::unordered_set<std::vector<unsigned char, std::allocator<unsigned char> >, ByteVectorHash, std::equal_to<std::vector<unsigned char, std::allocator<unsigned char> > >, std::allocator<std::vector<unsigned char, std::allocator<unsigned char> > > > const&)::{lambda()#1}::operator()() const
Unexecuted instantiation: interfaces.cpp:node::(anonymous namespace)::ChainImpl::waitForNotificationsIfTipChanged(uint256 const&)::{lambda()#1}::operator()() const
Unexecuted instantiation: interfaces.cpp:node::(anonymous namespace)::MinerImpl::createNewBlock(node::BlockCreateOptions const&, bool)::{lambda()#1}::operator()() const
Unexecuted instantiation: miner.cpp:node::RegenerateCommitments(CBlock&, ChainstateManager&)::$_0::operator()() const
Unexecuted instantiation: warnings.cpp:node::Warnings::Set(std::variant<kernel::Warning, node::Warning>, bilingual_str)::$_0::operator()() const
Unexecuted instantiation: warnings.cpp:node::Warnings::Unset(std::variant<kernel::Warning, node::Warning>)::$_0::operator()() const
Unexecuted instantiation: block_policy_estimator.cpp:FeeFilterRounder::round(long)::$_0::operator()() const
Unexecuted instantiation: rest.cpp:rest_deploymentinfo(std::any const&, http_bitcoin::HTTPRequest*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)::$_0::operator()() const
Unexecuted instantiation: rest.cpp:rest_spent_txouts(std::any const&, http_bitcoin::HTTPRequest*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)::$_0::operator()() const
Unexecuted instantiation: blockchain.cpp:blockToJSON(node::BlockManager&, CBlock const&, CBlockIndex const&, CBlockIndex const&, TxVerbosity, uint256)::$_0::operator()() const
Unexecuted instantiation: blockchain.cpp:blockToJSON(node::BlockManager&, CBlock const&, CBlockIndex const&, CBlockIndex const&, TxVerbosity, uint256)::$_1::operator()() const
Unexecuted instantiation: blockchain.cpp:CreateRolledBackUTXOSnapshot(node::NodeContext&, Chainstate&, CBlockIndex const*, AutoFile&&, fs::path const&, fs::path const&, bool)::$_0::operator()() const
Unexecuted instantiation: blockchain.cpp:CreateUTXOSnapshot(node::NodeContext&, Chainstate&, AutoFile&&, fs::path const&, fs::path const&)::$_0::operator()() const
Unexecuted instantiation: blockchain.cpp:getblockfrompeer()::$_0::operator()(RPCMethod const&, JSONRPCRequest const&) const::{lambda()#1}::operator()() const
Unexecuted instantiation: blockchain.cpp:getblockfrompeer()::$_0::operator()(RPCMethod const&, JSONRPCRequest const&) const::{lambda()#2}::operator()() const
Unexecuted instantiation: blockchain.cpp:getblockfrompeer()::$_0::operator()(RPCMethod const&, JSONRPCRequest const&) const::{lambda()#3}::operator()() const
Unexecuted instantiation: blockchain.cpp:scanblocks()::$_0::operator()(RPCMethod const&, JSONRPCRequest const&) const::{lambda()#1}::operator()() const
Unexecuted instantiation: blockchain.cpp:dumptxoutset()::$_0::operator()(RPCMethod const&, JSONRPCRequest const&) const::{lambda()#1}::operator()() const
Unexecuted instantiation: mempool.cpp:submitpackage()::$_0::operator()(RPCMethod const&, JSONRPCRequest const&) const::{lambda()#1}::operator()() const
Unexecuted instantiation: rawtransaction.cpp:getrawtransaction()::$_0::operator()(RPCMethod const&, JSONRPCRequest const&) const::{lambda()#1}::operator()() const
Unexecuted instantiation: rawtransaction.cpp:getrawtransaction()::$_0::operator()(RPCMethod const&, JSONRPCRequest const&) const::{lambda()#2}::operator()() const
Unexecuted instantiation: validation.cpp:Chainstate::ActivateBestChain(BlockValidationState&, std::shared_ptr<CBlock const>)::$_0::operator()() const
Unexecuted instantiation: validation.cpp:Chainstate::InvalidateBlock(BlockValidationState&, CBlockIndex*)::$_0::operator()() const
Unexecuted instantiation: validation.cpp:ChainstateManager::ProcessNewBlock(std::shared_ptr<CBlock const> const&, bool, bool, bool*)::$_0::operator()() const
Unexecuted instantiation: validation.cpp:ChainstateManager::LoadExternalBlockFile(AutoFile&, FlatFilePos*, std::multimap<uint256, FlatFilePos, std::less<uint256>, std::allocator<std::pair<uint256 const, FlatFilePos> > >*)::$_0::operator()() const
Unexecuted instantiation: validation.cpp:ChainstateManager::ActivateSnapshot(AutoFile&, node::SnapshotMetadata const&, bool)::$_1::operator()() const
Unexecuted instantiation: validation.cpp:ChainstateManager::PopulateAndValidateSnapshot(Chainstate&, AutoFile&, node::SnapshotMetadata const&)::$_1::operator()() const
Unexecuted instantiation: validation.cpp:ChainstateManager::PopulateAndValidateSnapshot(Chainstate&, AutoFile&, node::SnapshotMetadata const&)::$_2::operator()() const
Unexecuted instantiation: validation.cpp:ChainstateManager::PopulateAndValidateSnapshot(Chainstate&, AutoFile&, node::SnapshotMetadata const&)::$_3::operator()() const
Unexecuted instantiation: validation.cpp:ChainstateManager::PopulateAndValidateSnapshot(Chainstate&, AutoFile&, node::SnapshotMetadata const&)::$_4::operator()() const
Unexecuted instantiation: validation.cpp:ChainstateManager::PopulateAndValidateSnapshot(Chainstate&, AutoFile&, node::SnapshotMetadata const&)::$_5::operator()() const
CCheckQueue<CScriptCheck, std::pair<ScriptError_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::~CCheckQueue()::{lambda()#1}::operator()() const
Line
Count
Source
299
305
#define WITH_LOCK(cs, code) (MaybeCheckNotHeld(cs), [&]() -> decltype(auto) { LOCK(cs); code; }())
Unexecuted instantiation: scriptpubkeyman.cpp:wallet::LegacyDataSPKM::MigrateToDescriptor()::$_0::operator()() const
Unexecuted instantiation: scriptpubkeyman.cpp:wallet::LegacyDataSPKM::MigrateToDescriptor()::$_1::operator()() const
Unexecuted instantiation: scriptpubkeyman.cpp:wallet::LegacyDataSPKM::MigrateToDescriptor()::$_2::operator()() const
wallet.cpp:wallet::RemoveWallet(wallet::WalletContext&, std::shared_ptr<wallet::CWallet> const&, std::optional<bool>, std::vector<bilingual_str, std::allocator<bilingual_str> >&)::$_0::operator()() const
Line
Count
Source
299
305
#define WITH_LOCK(cs, code) (MaybeCheckNotHeld(cs), [&]() -> decltype(auto) { LOCK(cs); code; }())
Unexecuted instantiation: wallet.cpp:wallet::LoadWallet(wallet::WalletContext&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::optional<bool>, wallet::DatabaseOptions const&, wallet::DatabaseStatus&, bilingual_str&, std::vector<bilingual_str, std::allocator<bilingual_str> >&)::$_0::operator()[abi:cxx11]() const
Unexecuted instantiation: wallet.cpp:wallet::LoadWallet(wallet::WalletContext&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::optional<bool>, wallet::DatabaseOptions const&, wallet::DatabaseStatus&, bilingual_str&, std::vector<bilingual_str, std::allocator<bilingual_str> >&)::$_1::operator()() const
Unexecuted instantiation: wallet.cpp:wallet::CreateWallet(wallet::WalletContext&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::optional<bool>, wallet::DatabaseOptions&, wallet::DatabaseStatus&, bilingual_str&, std::vector<bilingual_str, std::allocator<bilingual_str> >&)::$_0::operator()() const
Unexecuted instantiation: wallet.cpp:wallet::CWallet::BlockUntilSyncedToCurrentChain() const::$_0::operator()() const
Unexecuted instantiation: wallet.cpp:wallet::CWallet::RescanFromTime(long, wallet::WalletRescanReserver const&)::$_0::operator()() const
Unexecuted instantiation: wallet.cpp:wallet::CWallet::ScanForWalletTransactions(uint256 const&, int, std::optional<int>, wallet::WalletRescanReserver const&, bool)::$_0::operator()() const
Unexecuted instantiation: wallet.cpp:wallet::CWallet::ScanForWalletTransactions(uint256 const&, int, std::optional<int>, wallet::WalletRescanReserver const&, bool)::$_1::operator()() const
Unexecuted instantiation: wallet.cpp:wallet::CWallet::ScanForWalletTransactions(uint256 const&, int, std::optional<int>, wallet::WalletRescanReserver const&, bool)::$_2::operator()() const
Unexecuted instantiation: wallet.cpp:wallet::CWallet::ScanForWalletTransactions(uint256 const&, int, std::optional<int>, wallet::WalletRescanReserver const&, bool)::$_3::operator()() const
Unexecuted instantiation: wallet.cpp:wallet::CWallet::LoadExisting(wallet::WalletContext&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::unique_ptr<wallet::WalletDatabase, std::default_delete<wallet::WalletDatabase> >, bilingual_str&, std::vector<bilingual_str, std::allocator<bilingual_str> >&)::$_0::operator()() const
Unexecuted instantiation: wallet.cpp:wallet::CWallet::postInitProcess()::$_0::operator()() const
Unexecuted instantiation: wallet.cpp:wallet::CWallet::BackupWallet(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const::$_0::operator()() const
300
301
#endif // BITCOIN_SYNC_H