LCOV - code coverage report
Current view: top level - src - threadinterrupt.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 18 20 90.0 %
Date: 2020-09-26 01:30:44 Functions: 8 9 88.9 %

          Line data    Source code
       1             : // Copyright (c) 2009-2010 Satoshi Nakamoto
       2             : // Copyright (c) 2009-2018 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             : #include <sync.h>
       9             : 
      10        2530 : CThreadInterrupt::CThreadInterrupt() : flag(false) {}
      11             : 
      12     1579268 : CThreadInterrupt::operator bool() const
      13             : {
      14     1579268 :     return flag.load(std::memory_order_acquire);
      15             : }
      16             : 
      17         492 : void CThreadInterrupt::reset()
      18             : {
      19         492 :     flag.store(false, std::memory_order_release);
      20         492 : }
      21             : 
      22        1143 : void CThreadInterrupt::operator()()
      23             : {
      24             :     {
      25        1143 :         LOCK(mut);
      26        1143 :         flag.store(true, std::memory_order_release);
      27        1143 :     }
      28        1143 :     cond.notify_all();
      29        1143 : }
      30             : 
      31       32691 : bool CThreadInterrupt::sleep_for(std::chrono::milliseconds rel_time)
      32             : {
      33       32691 :     WAIT_LOCK(mut, lock);
      34       98072 :     return !cond.wait_for(lock, rel_time, [this]() { return flag.load(std::memory_order_acquire); });
      35       32691 : }
      36             : 
      37        6738 : bool CThreadInterrupt::sleep_for(std::chrono::seconds rel_time)
      38             : {
      39        6738 :     return sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(rel_time));
      40             : }
      41             : 
      42           0 : bool CThreadInterrupt::sleep_for(std::chrono::minutes rel_time)
      43             : {
      44           0 :     return sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(rel_time));
      45             : }

Generated by: LCOV version 1.15