LCOV - code coverage report
Current view: top level - src/util - threadinterrupt.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 16 16 100.0 %
Date: 2026-06-25 07:23:43 Functions: 7 7 100.0 %

          Line data    Source code
       1             : // Copyright (c) 2009-2010 Satoshi Nakamoto
       2             : // Copyright (c) 2009-2016 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             : #include <sync.h>
       8             : 
       9       37692 : CThreadInterrupt::CThreadInterrupt() : flag(false) {}
      10             : 
      11   159276717 : CThreadInterrupt::operator bool() const
      12             : {
      13   159276717 :     return flag.load(std::memory_order_acquire);
      14             : }
      15             : 
      16       14457 : void CThreadInterrupt::reset()
      17             : {
      18       14457 :     flag.store(false, std::memory_order_release);
      19       14457 : }
      20             : 
      21       33959 : void CThreadInterrupt::operator()()
      22             : {
      23             :     {
      24       33959 :         LOCK(mut);
      25       33959 :         flag.store(true, std::memory_order_release);
      26       33959 :     }
      27       33959 :     cond.notify_all();
      28       33959 : }
      29             : 
      30     2236130 : bool CThreadInterrupt::sleep_for(Clock::duration rel_time)
      31             : {
      32     2236130 :     WAIT_LOCK(mut, lock);
      33     6707308 :     return !cond.wait_for(lock, rel_time, [this]() { return flag.load(std::memory_order_acquire); });
      34     2236130 : }

Generated by: LCOV version 1.16