mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
Support more than one CScheduler thread for serial clients
This will be used by CValidationInterface soon. This requires a bit of work as we need to ensure that most of our callbacks happen in-order (to avoid synchronization issues in wallet) - we keep our own internal queue and push things onto it, scheduling a queue-draining function immediately upon new callbacks.
This commit is contained in:
@@ -6,6 +6,11 @@
|
||||
#include "validationinterface.h"
|
||||
#include "init.h"
|
||||
#include "scheduler.h"
|
||||
#include "sync.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <list>
|
||||
#include <atomic>
|
||||
|
||||
#include <boost/signals2/signal.hpp>
|
||||
|
||||
@@ -20,22 +25,23 @@ struct MainSignalsInstance {
|
||||
boost::signals2::signal<void (const CBlock&, const CValidationState&)> BlockChecked;
|
||||
boost::signals2::signal<void (const CBlockIndex *, const std::shared_ptr<const CBlock>&)> NewPoWValidBlock;
|
||||
|
||||
CScheduler *m_scheduler = NULL;
|
||||
// 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 :(
|
||||
SingleThreadedSchedulerClient m_schedulerClient;
|
||||
|
||||
MainSignalsInstance(CScheduler *pscheduler) : m_schedulerClient(pscheduler) {}
|
||||
};
|
||||
|
||||
static CMainSignals g_signals;
|
||||
|
||||
CMainSignals::CMainSignals() {
|
||||
m_internals.reset(new MainSignalsInstance());
|
||||
}
|
||||
|
||||
void CMainSignals::RegisterBackgroundSignalScheduler(CScheduler& scheduler) {
|
||||
assert(!m_internals->m_scheduler);
|
||||
m_internals->m_scheduler = &scheduler;
|
||||
assert(!m_internals);
|
||||
m_internals.reset(new MainSignalsInstance(&scheduler));
|
||||
}
|
||||
|
||||
void CMainSignals::UnregisterBackgroundSignalScheduler() {
|
||||
m_internals->m_scheduler = NULL;
|
||||
m_internals.reset(nullptr);
|
||||
}
|
||||
|
||||
CMainSignals& GetMainSignals()
|
||||
|
||||
Reference in New Issue
Block a user