Branch data Line data Source code
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 : 633 : CThreadInterrupt::CThreadInterrupt() : flag(false) {}
11 : :
12 : 675 : bool CThreadInterrupt::interrupted() const
13 : : {
14 : 675 : return flag.load(std::memory_order_acquire);
15 : : }
16 : :
17 : 662 : CThreadInterrupt::operator bool() const
18 : : {
19 : 662 : return interrupted();
20 : : }
21 : :
22 : 8 : void CThreadInterrupt::reset()
23 : : {
24 : 8 : flag.store(false, std::memory_order_release);
25 : 8 : }
26 : :
27 : 375 : void CThreadInterrupt::operator()()
28 : : {
29 : 375 : {
30 : 375 : LOCK(mut);
31 [ + - ]: 375 : flag.store(true, std::memory_order_release);
32 : 375 : }
33 : 375 : cond.notify_all();
34 : 375 : }
35 : :
36 : 3 : bool CThreadInterrupt::sleep_for(Clock::duration rel_time)
37 : : {
38 : 3 : WAIT_LOCK(mut, lock);
39 [ + + + - : 7 : return !cond.wait_for(lock, rel_time, [this]() { return flag.load(std::memory_order_acquire); });
+ - ]
40 : 3 : }
|