Bitcoin Core
31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
src
util
threadinterrupt.cpp
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
#include <util/threadinterrupt.h>
7
8
#include <
sync.h
>
9
10
CThreadInterrupt::CThreadInterrupt
() :
flag
(false) {}
11
12
bool
CThreadInterrupt::interrupted
()
const
13
{
14
return
flag
.load(std::memory_order_acquire);
15
}
16
17
CThreadInterrupt::operator bool()
const
18
{
19
return
interrupted
();
20
}
21
22
void
CThreadInterrupt::reset
()
23
{
24
flag
.store(
false
, std::memory_order_release);
25
}
26
27
void
CThreadInterrupt::operator()
()
28
{
29
{
30
LOCK
(
mut
);
31
flag
.store(
true
, std::memory_order_release);
32
}
33
cond
.notify_all();
34
}
35
36
bool
CThreadInterrupt::sleep_for
(Clock::duration rel_time)
37
{
38
WAIT_LOCK
(
mut
, lock);
39
return
!
cond
.wait_for(lock, rel_time, [
this
]() {
return
flag
.load(std::memory_order_acquire); });
40
}
CThreadInterrupt::operator()
virtual void operator()() EXCLUSIVE_LOCKS_REQUIRED(!mut)
Interrupt any sleeps. After this interrupted() will return true.
Definition
threadinterrupt.cpp:27
CThreadInterrupt::reset
virtual void reset()
Reset to an non-interrupted state.
Definition
threadinterrupt.cpp:22
CThreadInterrupt::flag
std::atomic< bool > flag
Definition
threadinterrupt.h:55
CThreadInterrupt::mut
Mutex mut
Definition
threadinterrupt.h:54
CThreadInterrupt::sleep_for
virtual bool sleep_for(Clock::duration rel_time) EXCLUSIVE_LOCKS_REQUIRED(!mut)
Sleep for the given duration.
Definition
threadinterrupt.cpp:36
CThreadInterrupt::interrupted
virtual bool interrupted() const
Return true if operator()() has been called.
Definition
threadinterrupt.cpp:12
CThreadInterrupt::cond
std::condition_variable cond
Definition
threadinterrupt.h:53
CThreadInterrupt::CThreadInterrupt
CThreadInterrupt()
Definition
threadinterrupt.cpp:10
sync.h
WAIT_LOCK
#define WAIT_LOCK(cs, name)
Definition
sync.h:264
LOCK
#define LOCK(cs)
Definition
sync.h:258
Generated on
for Bitcoin Core by
1.16.1