mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 20:03:34 -03:00
clang-format scheduler
Can easily be reviewed with the git options --ignore-all-space --word-diff-regex=. -U0
This commit is contained in:
parent
fa3d41b5ab
commit
fa8337fcdb
2 changed files with 25 additions and 17 deletions
|
@ -110,8 +110,8 @@ void CScheduler::scheduleEvery(CScheduler::Function f, std::chrono::milliseconds
|
|||
scheduleFromNow([=] { Repeat(*this, f, delta); }, delta);
|
||||
}
|
||||
|
||||
size_t CScheduler::getQueueInfo(std::chrono::system_clock::time_point &first,
|
||||
std::chrono::system_clock::time_point &last) const
|
||||
size_t CScheduler::getQueueInfo(std::chrono::system_clock::time_point& first,
|
||||
std::chrono::system_clock::time_point& last) const
|
||||
{
|
||||
LOCK(newTaskMutex);
|
||||
size_t result = taskQueue.size();
|
||||
|
@ -122,13 +122,15 @@ size_t CScheduler::getQueueInfo(std::chrono::system_clock::time_point &first,
|
|||
return result;
|
||||
}
|
||||
|
||||
bool CScheduler::AreThreadsServicingQueue() const {
|
||||
bool CScheduler::AreThreadsServicingQueue() const
|
||||
{
|
||||
LOCK(newTaskMutex);
|
||||
return nThreadsServicingQueue;
|
||||
}
|
||||
|
||||
|
||||
void SingleThreadedSchedulerClient::MaybeScheduleProcessQueue() {
|
||||
void SingleThreadedSchedulerClient::MaybeScheduleProcessQueue()
|
||||
{
|
||||
{
|
||||
LOCK(m_cs_callbacks_pending);
|
||||
// Try to avoid scheduling too many copies here, but if we
|
||||
|
@ -140,8 +142,9 @@ void SingleThreadedSchedulerClient::MaybeScheduleProcessQueue() {
|
|||
m_pscheduler->schedule(std::bind(&SingleThreadedSchedulerClient::ProcessQueue, this), std::chrono::system_clock::now());
|
||||
}
|
||||
|
||||
void SingleThreadedSchedulerClient::ProcessQueue() {
|
||||
std::function<void ()> callback;
|
||||
void SingleThreadedSchedulerClient::ProcessQueue()
|
||||
{
|
||||
std::function<void()> callback;
|
||||
{
|
||||
LOCK(m_cs_callbacks_pending);
|
||||
if (m_are_callbacks_running) return;
|
||||
|
@ -157,7 +160,8 @@ void SingleThreadedSchedulerClient::ProcessQueue() {
|
|||
struct RAIICallbacksRunning {
|
||||
SingleThreadedSchedulerClient* instance;
|
||||
explicit RAIICallbacksRunning(SingleThreadedSchedulerClient* _instance) : instance(_instance) {}
|
||||
~RAIICallbacksRunning() {
|
||||
~RAIICallbacksRunning()
|
||||
{
|
||||
{
|
||||
LOCK(instance->m_cs_callbacks_pending);
|
||||
instance->m_are_callbacks_running = false;
|
||||
|
@ -169,7 +173,8 @@ void SingleThreadedSchedulerClient::ProcessQueue() {
|
|||
callback();
|
||||
}
|
||||
|
||||
void SingleThreadedSchedulerClient::AddToProcessQueue(std::function<void ()> func) {
|
||||
void SingleThreadedSchedulerClient::AddToProcessQueue(std::function<void()> func)
|
||||
{
|
||||
assert(m_pscheduler);
|
||||
|
||||
{
|
||||
|
@ -179,7 +184,8 @@ void SingleThreadedSchedulerClient::AddToProcessQueue(std::function<void ()> fun
|
|||
MaybeScheduleProcessQueue();
|
||||
}
|
||||
|
||||
void SingleThreadedSchedulerClient::EmptyQueue() {
|
||||
void SingleThreadedSchedulerClient::EmptyQueue()
|
||||
{
|
||||
assert(!m_pscheduler->AreThreadsServicingQueue());
|
||||
bool should_continue = true;
|
||||
while (should_continue) {
|
||||
|
@ -189,7 +195,8 @@ void SingleThreadedSchedulerClient::EmptyQueue() {
|
|||
}
|
||||
}
|
||||
|
||||
size_t SingleThreadedSchedulerClient::CallbacksPending() {
|
||||
size_t SingleThreadedSchedulerClient::CallbacksPending()
|
||||
{
|
||||
LOCK(m_cs_callbacks_pending);
|
||||
return m_callbacks_pending.size();
|
||||
}
|
||||
|
|
|
@ -84,8 +84,8 @@ public:
|
|||
* Returns number of tasks waiting to be serviced,
|
||||
* and first and last task times
|
||||
*/
|
||||
size_t getQueueInfo(std::chrono::system_clock::time_point &first,
|
||||
std::chrono::system_clock::time_point &last) const;
|
||||
size_t getQueueInfo(std::chrono::system_clock::time_point& first,
|
||||
std::chrono::system_clock::time_point& last) const;
|
||||
|
||||
/** Returns true if there are threads actively running in serviceQueue() */
|
||||
bool AreThreadsServicingQueue() const;
|
||||
|
@ -110,19 +110,20 @@ private:
|
|||
* B() will be able to observe all of the effects of callback A() which executed
|
||||
* before it.
|
||||
*/
|
||||
class SingleThreadedSchedulerClient {
|
||||
class SingleThreadedSchedulerClient
|
||||
{
|
||||
private:
|
||||
CScheduler *m_pscheduler;
|
||||
CScheduler* m_pscheduler;
|
||||
|
||||
RecursiveMutex m_cs_callbacks_pending;
|
||||
std::list<std::function<void ()>> m_callbacks_pending GUARDED_BY(m_cs_callbacks_pending);
|
||||
std::list<std::function<void()>> m_callbacks_pending GUARDED_BY(m_cs_callbacks_pending);
|
||||
bool m_are_callbacks_running GUARDED_BY(m_cs_callbacks_pending) = false;
|
||||
|
||||
void MaybeScheduleProcessQueue();
|
||||
void ProcessQueue();
|
||||
|
||||
public:
|
||||
explicit SingleThreadedSchedulerClient(CScheduler *pschedulerIn) : m_pscheduler(pschedulerIn) {}
|
||||
explicit SingleThreadedSchedulerClient(CScheduler* pschedulerIn) : m_pscheduler(pschedulerIn) {}
|
||||
|
||||
/**
|
||||
* Add a callback to be executed. Callbacks are executed serially
|
||||
|
@ -130,7 +131,7 @@ public:
|
|||
* Practically, this means that callbacks can behave as if they are executed
|
||||
* in order by a single thread.
|
||||
*/
|
||||
void AddToProcessQueue(std::function<void ()> func);
|
||||
void AddToProcessQueue(std::function<void()> func);
|
||||
|
||||
/**
|
||||
* Processes all remaining queue members on the calling thread, blocking until queue is empty
|
||||
|
|
Loading…
Reference in a new issue