Coverage Report

Created: 2026-07-14 18:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
135
CThreadInterrupt::CThreadInterrupt() : flag(false) {}
11
12
bool CThreadInterrupt::interrupted() const
13
137M
{
14
137M
    return flag.load(std::memory_order_acquire);
15
137M
}
16
17
CThreadInterrupt::operator bool() const
18
6.90M
{
19
6.90M
    return interrupted();
20
6.90M
}
21
22
void CThreadInterrupt::reset()
23
150k
{
24
150k
    flag.store(false, std::memory_order_release);
25
150k
}
26
27
void CThreadInterrupt::operator()()
28
1.20M
{
29
1.20M
    {
30
1.20M
        LOCK(mut);
31
1.20M
        flag.store(true, std::memory_order_release);
32
1.20M
    }
33
1.20M
    cond.notify_all();
34
1.20M
}
35
36
bool CThreadInterrupt::sleep_for(Clock::duration rel_time)
37
8.08k
{
38
8.08k
    WAIT_LOCK(mut, lock);
39
316k
    return !cond.wait_for(lock, rel_time, [this]() { return flag.load(std::memory_order_acquire); });
40
8.08k
}