LCOV - code coverage report
Current view: top level - src/util - threadinterrupt.cpp (source / functions) Coverage Total Hit
Test: test_bitcoin_coverage.info Lines: 100.0 % 19 19
Test Date: 2026-04-25 06:24:37 Functions: 100.0 % 6 6
Branches: 50.0 % 8 4

             Branch data     Line data    Source code
       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                 :         645 : CThreadInterrupt::CThreadInterrupt() : flag(false) {}
      11                 :             : 
      12                 :         789 : bool CThreadInterrupt::interrupted() const
      13                 :             : {
      14                 :         789 :     return flag.load(std::memory_order_acquire);
      15                 :             : }
      16                 :             : 
      17                 :         776 : CThreadInterrupt::operator bool() const
      18                 :             : {
      19                 :         776 :     return interrupted();
      20                 :             : }
      21                 :             : 
      22                 :           9 : void CThreadInterrupt::reset()
      23                 :             : {
      24                 :           9 :     flag.store(false, std::memory_order_release);
      25                 :           9 : }
      26                 :             : 
      27                 :         332 : void CThreadInterrupt::operator()()
      28                 :             : {
      29                 :         332 :     {
      30                 :         332 :         LOCK(mut);
      31         [ +  - ]:         332 :         flag.store(true, std::memory_order_release);
      32                 :         332 :     }
      33                 :         332 :     cond.notify_all();
      34                 :         332 : }
      35                 :             : 
      36                 :           2 : bool CThreadInterrupt::sleep_for(Clock::duration rel_time)
      37                 :             : {
      38                 :           2 :     WAIT_LOCK(mut, lock);
      39   [ -  +  +  -  :           4 :     return !cond.wait_for(lock, rel_time, [this]() { return flag.load(std::memory_order_acquire); });
                   +  - ]
      40                 :           2 : }
        

Generated by: LCOV version 2.0-1