Branch data 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 : 1524 : CThreadInterrupt::CThreadInterrupt() : flag(false) {} # 11 : : # 12 : : CThreadInterrupt::operator bool() const # 13 : 1752569 : { # 14 : 1752569 : return flag.load(std::memory_order_acquire); # 15 : 1752569 : } # 16 : : # 17 : : void CThreadInterrupt::reset() # 18 : 618 : { # 19 : 618 : flag.store(false, std::memory_order_release); # 20 : 618 : } # 21 : : # 22 : : void CThreadInterrupt::operator()() # 23 : 1487 : { # 24 : 1487 : { # 25 : 1487 : LOCK(mut); # 26 : 1487 : flag.store(true, std::memory_order_release); # 27 : 1487 : } # 28 : 1487 : cond.notify_all(); # 29 : 1487 : } # 30 : : # 31 : : bool CThreadInterrupt::sleep_for(std::chrono::milliseconds rel_time) # 32 : 26353 : { # 33 : 26353 : WAIT_LOCK(mut, lock); # 34 : 52705 : return !cond.wait_for(lock, rel_time, [this]() { return flag.load(std::memory_order_acquire); }); # 35 : 26353 : } # 36 : : # 37 : : bool CThreadInterrupt::sleep_for(std::chrono::seconds rel_time) # 38 : 6881 : { # 39 : 6881 : return sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(rel_time)); # 40 : 6881 : } # 41 : : # 42 : : bool CThreadInterrupt::sleep_for(std::chrono::minutes rel_time) # 43 : 0 : { # 44 : 0 : return sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(rel_time)); # 45 : 0 : }