LCOV - code coverage report
Current view: top level - src - threadinterrupt.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 16 18 88.9 %
Date: 2025-02-23 09:33:43 Functions: 5 6 83.3 %

          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 "threadinterrupt.h"
       7             : 
       8    11814100 : CThreadInterrupt::operator bool() const
       9             : {
      10    11814100 :     return flag.load(std::memory_order_acquire);
      11             : }
      12             : 
      13        1185 : void CThreadInterrupt::reset()
      14             : {
      15        1185 :     flag.store(false, std::memory_order_release);
      16        1185 : }
      17             : 
      18        2175 : void CThreadInterrupt::operator()()
      19             : {
      20        2175 :     {
      21        2175 :         std::unique_lock<std::mutex> lock(mut);
      22        2175 :         flag.store(true, std::memory_order_release);
      23             :     }
      24        2175 :     cond.notify_all();
      25        2175 : }
      26             : 
      27      315294 : bool CThreadInterrupt::sleep_for(std::chrono::milliseconds rel_time)
      28             : {
      29      315294 :     std::unique_lock<std::mutex> lock(mut);
      30     1261180 :     return !cond.wait_for(lock, rel_time, [this]() { return flag.load(std::memory_order_acquire); });
      31             : }
      32             : 
      33        9710 : bool CThreadInterrupt::sleep_for(std::chrono::seconds rel_time)
      34             : {
      35        9710 :     return sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(rel_time));
      36             : }
      37             : 
      38           0 : bool CThreadInterrupt::sleep_for(std::chrono::minutes rel_time)
      39             : {
      40           0 :     return sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(rel_time));
      41             : }

Generated by: LCOV version 1.14