aboutsummaryrefslogtreecommitdiff
path: root/src/scheduler.h
diff options
context:
space:
mode:
authorTheCharlatan <seb.kung@gmail.com>2023-11-27 17:15:11 +0100
committerTheCharlatan <seb.kung@gmail.com>2024-02-16 17:12:52 +0100
commitd5228efb5391b31a9a0673019e43e7fa2cd4ac07 (patch)
tree300d36fe4b3143c435d36d2e6d617bd714ac0b00 /src/scheduler.h
parent06069b3913dda048f5d640a662b0852f86346ace (diff)
kernel: Remove dependency on CScheduler
By defining a virtual interface class for the scheduler client, users of the kernel can now define their own event consuming infrastructure, without having to spawn threads or rely on the scheduler design. Removing CScheduler also allows removing the thread and exception modules from the kernel library.
Diffstat (limited to 'src/scheduler.h')
-rw-r--r--src/scheduler.h13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/scheduler.h b/src/scheduler.h
index 940ce08ecf..454c083b31 100644
--- a/src/scheduler.h
+++ b/src/scheduler.h
@@ -8,6 +8,7 @@
#include <attributes.h>
#include <sync.h>
#include <threadsafety.h>
+#include <util/task_runner.h>
#include <chrono>
#include <condition_variable>
@@ -120,12 +121,16 @@ private:
* B() will be able to observe all of the effects of callback A() which executed
* before it.
*/
-class SerialTaskRunner
+class SerialTaskRunner : public util::TaskRunnerInterface
{
private:
CScheduler& m_scheduler;
Mutex m_callbacks_mutex;
+
+ // We are not allowed to assume the scheduler only runs in one thread,
+ // but must ensure all callbacks happen in-order, so we end up creating
+ // our own queue here :(
std::list<std::function<void()>> m_callbacks_pending GUARDED_BY(m_callbacks_mutex);
bool m_are_callbacks_running GUARDED_BY(m_callbacks_mutex) = false;
@@ -141,15 +146,15 @@ public:
* Practically, this means that callbacks can behave as if they are executed
* in order by a single thread.
*/
- void insert(std::function<void()> func) EXCLUSIVE_LOCKS_REQUIRED(!m_callbacks_mutex);
+ void insert(std::function<void()> func) override EXCLUSIVE_LOCKS_REQUIRED(!m_callbacks_mutex);
/**
* Processes all remaining queue members on the calling thread, blocking until queue is empty
* Must be called after the CScheduler has no remaining processing threads!
*/
- void flush() EXCLUSIVE_LOCKS_REQUIRED(!m_callbacks_mutex);
+ void flush() override EXCLUSIVE_LOCKS_REQUIRED(!m_callbacks_mutex);
- size_t size() EXCLUSIVE_LOCKS_REQUIRED(!m_callbacks_mutex);
+ size_t size() override EXCLUSIVE_LOCKS_REQUIRED(!m_callbacks_mutex);
};
#endif // BITCOIN_SCHEDULER_H