mirror of
https://github.com/dashpay/dash.git
synced 2024-12-28 13:32:47 +01:00
42c784dc7a
* net: a few small cleanups before replacing boost threads - Drop the interruption point directly after the pnode allocation. This would be leaky if hit. - Rearrange thread creation so that the socket handler comes first * net: add CThreadInterrupt and InterruptibleSleep * net: make net interruptible Also now that net threads are interruptible, switch them to use std threads/binds/mutexes/condvars. * net: make net processing interruptible * net: remove thread_interrupted catch This is now a std::thread, so there's no hope of catching a boost interruption point. * net: make proxy receives interruptible * net: misc header cleanups
35 lines
921 B
C++
35 lines
921 B
C++
// Copyright (c) 2016 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#ifndef BITCOIN_THREADINTERRUPT_H
|
|
#define BITCOIN_THREADINTERRUPT_H
|
|
|
|
#include <atomic>
|
|
#include <chrono>
|
|
#include <condition_variable>
|
|
#include <mutex>
|
|
|
|
/*
|
|
A helper class for interruptible sleeps. Calling operator() will interrupt
|
|
any current sleep, and after that point operator bool() will return true
|
|
until reset.
|
|
*/
|
|
class CThreadInterrupt
|
|
{
|
|
public:
|
|
explicit operator bool() const;
|
|
void operator()();
|
|
void reset();
|
|
bool sleep_for(std::chrono::milliseconds rel_time);
|
|
bool sleep_for(std::chrono::seconds rel_time);
|
|
bool sleep_for(std::chrono::minutes rel_time);
|
|
|
|
private:
|
|
std::condition_variable cond;
|
|
std::mutex mut;
|
|
std::atomic<bool> flag;
|
|
};
|
|
|
|
#endif //BITCOIN_THREADINTERRUPT_H
|