/Users/eugenesiegel/btc/bitcoin/src/util/threadinterrupt.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) 2009-2010 Satoshi Nakamoto |
2 | | // Copyright (c) 2009-2022 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 | | #include <util/threadinterrupt.h> |
7 | | |
8 | | #include <sync.h> |
9 | | |
10 | 49.9k | CThreadInterrupt::CThreadInterrupt() : flag(false) {} |
11 | | |
12 | | CThreadInterrupt::operator bool() const |
13 | 0 | { |
14 | 0 | return flag.load(std::memory_order_acquire); |
15 | 0 | } |
16 | | |
17 | | void CThreadInterrupt::reset() |
18 | 0 | { |
19 | 0 | flag.store(false, std::memory_order_release); |
20 | 0 | } |
21 | | |
22 | | void CThreadInterrupt::operator()() |
23 | 99.9k | { |
24 | 99.9k | { |
25 | 99.9k | LOCK(mut); Line | Count | Source | 257 | 99.9k | #define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 99.9k | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 99.9k | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 99.9k | #define PASTE(x, y) x ## y |
|
|
|
|
26 | 99.9k | flag.store(true, std::memory_order_release); |
27 | 99.9k | } |
28 | 99.9k | cond.notify_all(); |
29 | 99.9k | } |
30 | | |
31 | | bool CThreadInterrupt::sleep_for(Clock::duration rel_time) |
32 | 0 | { |
33 | 0 | WAIT_LOCK(mut, lock); Line | Count | Source | 262 | 0 | #define WAIT_LOCK(cs, name) UniqueLock name(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__) |
|
34 | 0 | return !cond.wait_for(lock, rel_time, [this]() { return flag.load(std::memory_order_acquire); }); |
35 | 0 | } |