Bitcoin Core
28.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-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
CThreadInterrupt::CThreadInterrupt
() : flag(false) {}
11
12
CThreadInterrupt::operator bool()
const
13
{
14
return
flag.load(std::memory_order_acquire);
15
}
16
17
void
CThreadInterrupt::reset
()
18
{
19
flag
.store(
false
, std::memory_order_release);
20
}
21
22
void
CThreadInterrupt::operator()
()
23
{
24
{
25
LOCK
(
mut
);
26
flag
.store(
true
, std::memory_order_release);
27
}
28
cond
.notify_all();
29
}
30
31
bool
CThreadInterrupt::sleep_for
(Clock::duration rel_time)
32
{
33
WAIT_LOCK
(
mut
, lock);
34
return
!
cond
.wait_for(lock, rel_time, [
this
]() {
return
flag
.load(std::memory_order_acquire); });
35
}
CThreadInterrupt::operator()
void operator()() EXCLUSIVE_LOCKS_REQUIRED(!mut)
Definition
threadinterrupt.cpp:22
CThreadInterrupt::reset
void reset()
Definition
threadinterrupt.cpp:17
CThreadInterrupt::flag
std::atomic< bool > flag
Definition
threadinterrupt.h:39
CThreadInterrupt::mut
Mutex mut
Definition
threadinterrupt.h:38
CThreadInterrupt::sleep_for
bool sleep_for(Clock::duration rel_time) EXCLUSIVE_LOCKS_REQUIRED(!mut)
Definition
threadinterrupt.cpp:31
CThreadInterrupt::cond
std::condition_variable cond
Definition
threadinterrupt.h:37
CThreadInterrupt::CThreadInterrupt
CThreadInterrupt()
Definition
threadinterrupt.cpp:10
sync.h
WAIT_LOCK
#define WAIT_LOCK(cs, name)
Definition
sync.h:262
LOCK
#define LOCK(cs)
Definition
sync.h:257
threadinterrupt.h
Generated on Thu Oct 3 2024 09:20:15 for Bitcoin Core by
1.12.0