mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 22:18:54 +01:00
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.
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
|
||||
#include <validationinterface.h>
|
||||
|
||||
#include <attributes.h>
|
||||
#include <chain.h>
|
||||
#include <consensus/validation.h>
|
||||
#include <kernel/chain.h>
|
||||
@@ -13,7 +12,8 @@
|
||||
#include <logging.h>
|
||||
#include <primitives/block.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <scheduler.h>
|
||||
#include <util/check.h>
|
||||
#include <util/task_runner.h>
|
||||
|
||||
#include <future>
|
||||
#include <unordered_map>
|
||||
@@ -42,12 +42,10 @@ private:
|
||||
std::unordered_map<CValidationInterface*, std::list<ListEntry>::iterator> m_map GUARDED_BY(m_mutex);
|
||||
|
||||
public:
|
||||
// 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 :(
|
||||
SerialTaskRunner m_task_runner;
|
||||
std::unique_ptr<util::TaskRunnerInterface> m_task_runner;
|
||||
|
||||
explicit ValidationSignalsImpl(CScheduler& scheduler LIFETIMEBOUND) : m_task_runner(scheduler) {}
|
||||
explicit ValidationSignalsImpl(std::unique_ptr<util::TaskRunnerInterface> task_runner)
|
||||
: m_task_runner{std::move(Assert(task_runner))} {}
|
||||
|
||||
void Register(std::shared_ptr<CValidationInterface> callbacks) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
|
||||
{
|
||||
@@ -94,19 +92,19 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
ValidationSignals::ValidationSignals(CScheduler& scheduler)
|
||||
: m_internals{std::make_unique<ValidationSignalsImpl>(scheduler)} {}
|
||||
ValidationSignals::ValidationSignals(std::unique_ptr<util::TaskRunnerInterface> task_runner)
|
||||
: m_internals{std::make_unique<ValidationSignalsImpl>(std::move(task_runner))} {}
|
||||
|
||||
ValidationSignals::~ValidationSignals() {}
|
||||
|
||||
void ValidationSignals::FlushBackgroundCallbacks()
|
||||
{
|
||||
m_internals->m_task_runner.flush();
|
||||
m_internals->m_task_runner->flush();
|
||||
}
|
||||
|
||||
size_t ValidationSignals::CallbacksPending()
|
||||
{
|
||||
return m_internals->m_task_runner.size();
|
||||
return m_internals->m_task_runner->size();
|
||||
}
|
||||
|
||||
void ValidationSignals::RegisterSharedValidationInterface(std::shared_ptr<CValidationInterface> callbacks)
|
||||
@@ -140,7 +138,7 @@ void ValidationSignals::UnregisterAllValidationInterfaces()
|
||||
|
||||
void ValidationSignals::CallFunctionInValidationInterfaceQueue(std::function<void()> func)
|
||||
{
|
||||
m_internals->m_task_runner.insert(std::move(func));
|
||||
m_internals->m_task_runner->insert(std::move(func));
|
||||
}
|
||||
|
||||
void ValidationSignals::SyncWithValidationInterfaceQueue()
|
||||
@@ -162,7 +160,7 @@ void ValidationSignals::SyncWithValidationInterfaceQueue()
|
||||
do { \
|
||||
auto local_name = (name); \
|
||||
LOG_EVENT("Enqueuing " fmt, local_name, __VA_ARGS__); \
|
||||
m_internals->m_task_runner.insert([=] { \
|
||||
m_internals->m_task_runner->insert([=] { \
|
||||
LOG_EVENT(fmt, local_name, __VA_ARGS__); \
|
||||
event(); \
|
||||
}); \
|
||||
|
||||
Reference in New Issue
Block a user