[test] Add assert_raises_process_error to assert process errors
[bitcoinplatinum.git] / src / threadinterrupt.cpp
blob9d691079edbace09c7fed33e1361ecf2ad4cf775
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.
6 #include "threadinterrupt.h"
8 CThreadInterrupt::operator bool() const
10 return flag.load(std::memory_order_acquire);
13 void CThreadInterrupt::reset()
15 flag.store(false, std::memory_order_release);
18 void CThreadInterrupt::operator()()
21 std::unique_lock<std::mutex> lock(mut);
22 flag.store(true, std::memory_order_release);
24 cond.notify_all();
27 bool CThreadInterrupt::sleep_for(std::chrono::milliseconds rel_time)
29 std::unique_lock<std::mutex> lock(mut);
30 return !cond.wait_for(lock, rel_time, [this]() { return flag.load(std::memory_order_acquire); });
33 bool CThreadInterrupt::sleep_for(std::chrono::seconds rel_time)
35 return sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(rel_time));
38 bool CThreadInterrupt::sleep_for(std::chrono::minutes rel_time)
40 return sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(rel_time));