mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-20 12:12:41 -05:00

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.
52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
// Copyright (c) 2024-present The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#ifndef BITCOIN_UTIL_TASK_RUNNER_H
|
|
#define BITCOIN_UTIL_TASK_RUNNER_H
|
|
|
|
#include <cstddef>
|
|
#include <functional>
|
|
|
|
namespace util {
|
|
|
|
/** @file
|
|
* This header provides an interface and simple implementation for a task
|
|
* runner. Another threaded, serial implementation using a queue is available in
|
|
* the scheduler module's SerialTaskRunner.
|
|
*/
|
|
|
|
class TaskRunnerInterface
|
|
{
|
|
public:
|
|
virtual ~TaskRunnerInterface() {}
|
|
|
|
/**
|
|
* The callback can either be queued for later/asynchronous/threaded
|
|
* processing, or be executed immediately for synchronous processing.
|
|
*/
|
|
|
|
virtual void insert(std::function<void()> func) = 0;
|
|
|
|
/**
|
|
* Forces the processing of all pending events.
|
|
*/
|
|
virtual void flush() = 0;
|
|
|
|
/**
|
|
* Returns the number of currently pending events.
|
|
*/
|
|
virtual size_t size() = 0;
|
|
};
|
|
|
|
class ImmediateTaskRunner : public TaskRunnerInterface
|
|
{
|
|
public:
|
|
void insert(std::function<void()> func) override { func(); }
|
|
void flush() override {}
|
|
size_t size() override { return 0; }
|
|
};
|
|
|
|
} // namespace util
|
|
|
|
#endif // BITCOIN_UTIL_TASK_RUNNER_H
|