Changeset View
Changeset View
Standalone View
Standalone View
src/eventloop.h
// Copyright (c) 2020 The Bitcoin developers | // Copyright (c) 2020 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_EVENTLOOP_H | #ifndef BITCOIN_EVENTLOOP_H | ||||
#define BITCOIN_EVENTLOOP_H | #define BITCOIN_EVENTLOOP_H | ||||
#include <sync.h> | #include <sync.h> | ||||
#include <atomic> | #include <atomic> | ||||
#include <chrono> | |||||
#include <condition_variable> | #include <condition_variable> | ||||
#include <functional> | #include <functional> | ||||
class CScheduler; | class CScheduler; | ||||
struct EventLoop { | struct EventLoop { | ||||
public: | public: | ||||
EventLoop() {} | EventLoop() {} | ||||
~EventLoop(); | ~EventLoop(); | ||||
bool startEventLoop(CScheduler &scheduler, | bool startEventLoop(CScheduler &scheduler, | ||||
std::function<void()> runEventLoop, | std::function<void()> runEventLoop, | ||||
int64_t deltaMilliSeconds); | std::chrono::milliseconds delta); | ||||
bool stopEventLoop(); | bool stopEventLoop(); | ||||
private: | private: | ||||
/** | /** | ||||
* Start stop machinery. | * Start stop machinery. | ||||
*/ | */ | ||||
std::atomic<bool> stopRequest{false}; | std::atomic<bool> stopRequest{false}; | ||||
bool running GUARDED_BY(cs_running) = false; | bool running GUARDED_BY(cs_running) = false; | ||||
Mutex cs_running; | Mutex cs_running; | ||||
std::condition_variable cond_running; | std::condition_variable cond_running; | ||||
}; | }; | ||||
#endif // BITCOIN_EVENTLOOP_H | #endif // BITCOIN_EVENTLOOP_H |