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 #include <threadsafety.h>
10 
11 #include <atomic>
12 #include <chrono>
13 #include <condition_variable>
14 #include <functional>
15 
16 class CScheduler;
17 
18 struct EventLoop {
19 public:
20  EventLoop() {}
21  ~EventLoop();
22 
23  bool startEventLoop(CScheduler &scheduler,
24  std::function<void()> runEventLoop,
25  std::chrono::milliseconds delta)
28 
29 private:
33  std::atomic<bool> stopRequest{false};
34  bool running GUARDED_BY(cs_running) = false;
35 
37  std::condition_variable cond_running;
38 };
39 
40 #endif // BITCOIN_EVENTLOOP_H
Simple class for background tasks that should be run periodically or once "after a while".
Definition: scheduler.h:41
Implement std::hash so RCUPtr can be used as a key for maps or sets.
Definition: rcu.h:257
std::atomic< bool > stopRequest
Start stop machinery.
Definition: eventloop.h:33
bool running GUARDED_BY(cs_running)
EventLoop()
Definition: eventloop.h:20
std::condition_variable cond_running
Definition: eventloop.h:37
bool stopEventLoop() EXCLUSIVE_LOCKS_REQUIRED(!cs_running)
Definition: eventloop.cpp:45
~EventLoop()
Definition: eventloop.cpp:9
bool startEventLoop(CScheduler &scheduler, std::function< void()> runEventLoop, std::chrono::milliseconds delta) EXCLUSIVE_LOCKS_REQUIRED(!cs_running)
Definition: eventloop.cpp:13
Mutex cs_running
Definition: eventloop.h:36
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56