/tmp/bitcoin/src/util/threadinterrupt.cpp
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 | | #include <util/threadinterrupt.h> |
7 | | |
8 | | #include <sync.h> |
9 | | |
10 | 4.03k | CThreadInterrupt::CThreadInterrupt() : flag(false) {} |
11 | | |
12 | | bool CThreadInterrupt::interrupted() const |
13 | 1.13M | { |
14 | 1.13M | return flag.load(std::memory_order_acquire); |
15 | 1.13M | } |
16 | | |
17 | | CThreadInterrupt::operator bool() const |
18 | 8.32k | { |
19 | 8.32k | return interrupted(); |
20 | 8.32k | } |
21 | | |
22 | | void CThreadInterrupt::reset() |
23 | 1.13k | { |
24 | 1.13k | flag.store(false, std::memory_order_release); |
25 | 1.13k | } |
26 | | |
27 | | void CThreadInterrupt::operator()() |
28 | 4.81k | { |
29 | 4.81k | { |
30 | 4.81k | LOCK(mut); |
31 | 4.81k | flag.store(true, std::memory_order_release); |
32 | 4.81k | } |
33 | 4.81k | cond.notify_all(); |
34 | 4.81k | } |
35 | | |
36 | | bool CThreadInterrupt::sleep_for(Clock::duration rel_time) |
37 | 5.34k | { |
38 | 5.34k | WAIT_LOCK(mut, lock); |
39 | 10.6k | return !cond.wait_for(lock, rel_time, [this]() { return flag.load(std::memory_order_acquire); }); |
40 | 5.34k | } |