LCOV - code coverage report
Current view: top level - src/util - threadinterrupt.cpp (source / functions) Coverage Total Hit
Test: test_bitcoin_coverage.info Lines: 76.5 % 17 13
Test Date: 2024-08-28 04:44:32 Functions: 80.0 % 5 4
Branches: 12.5 % 8 1

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

Generated by: LCOV version 2.0-1