Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2009-2010 Satoshi Nakamoto2// Copyright (c) 2009-present The Bitcoin Core developers3// Distributed under the MIT software license, see the accompanying4// file COPYING or http://www.opensource.org/licenses/mit-license.php.6#include <util/threadinterrupt.h>8#include <sync.h>10CThreadInterrupt::CThreadInterrupt() : flag(false) {}12bool CThreadInterrupt::interrupted() const13{14return flag.load(std::memory_order_acquire);15}17CThreadInterrupt::operator bool() const18{19return interrupted();20}22void CThreadInterrupt::reset()23{24flag.store(false, std::memory_order_release);25}27void CThreadInterrupt::operator()()28{29{30LOCK(mut);31flag.store(true, std::memory_order_release);32}33cond.notify_all();34}36bool CThreadInterrupt::sleep_for(Clock::duration rel_time)37{38WAIT_LOCK(mut, lock);39return !cond.wait_for(lock, rel_time, [this]() { return flag.load(std::memory_order_acquire); });40}