Bitcoin ABC  0.26.3
P2P Digital Currency
eventloop.h
Go to the documentation of this file.
1 // Copyright (c) 2020 The Bitcoin developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_EVENTLOOP_H
6 #define BITCOIN_EVENTLOOP_H
7 
8 #include <sync.h>
9 
10 #include <atomic>
11 #include <chrono>
12 #include <condition_variable>
13 #include <functional>
14 
15 class CScheduler;
16 
17 struct EventLoop {
18 public:
19  EventLoop() {}
20  ~EventLoop();
21 
22  bool startEventLoop(CScheduler &scheduler,
23  std::function<void()> runEventLoop,
24  std::chrono::milliseconds delta);
25  bool stopEventLoop();
26 
27 private:
31  std::atomic<bool> stopRequest{false};
32  bool running GUARDED_BY(cs_running) = false;
33 
35  std::condition_variable cond_running;
36 };
37 
38 #endif // BITCOIN_EVENTLOOP_H
Simple class for background tasks that should be run periodically or once "after a while".
Definition: scheduler.h:41
std::atomic< bool > stopRequest
Start stop machinery.
Definition: eventloop.h:31
bool running GUARDED_BY(cs_running)
EventLoop()
Definition: eventloop.h:19
bool stopEventLoop()
Definition: eventloop.cpp:45
std::condition_variable cond_running
Definition: eventloop.h:35
~EventLoop()
Definition: eventloop.cpp:9
Mutex cs_running
Definition: eventloop.h:34
bool startEventLoop(CScheduler &scheduler, std::function< void()> runEventLoop, std::chrono::milliseconds delta)
Definition: eventloop.cpp:13