Bitcoin Core  27.99.0
P2P Digital Currency
Public Member Functions | Private Member Functions | Private Attributes | List of all members
SerialTaskRunner Class Reference

Class used by CScheduler clients which may schedule multiple jobs which are required to be run serially. More...

#include <scheduler.h>

Inheritance diagram for SerialTaskRunner:
[legend]
Collaboration diagram for SerialTaskRunner:
[legend]

Public Member Functions

 SerialTaskRunner (CScheduler &scheduler LIFETIMEBOUND)
 
void insert (std::function< void()> func) override EXCLUSIVE_LOCKS_REQUIRED(!m_callbacks_mutex)
 Add a callback to be executed. More...
 
void flush () 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! More...
 
size_t size () override EXCLUSIVE_LOCKS_REQUIRED(!m_callbacks_mutex)
 Returns the number of currently pending events. More...
 
- Public Member Functions inherited from util::TaskRunnerInterface
virtual ~TaskRunnerInterface ()
 

Private Member Functions

std::list< std::function< void()> > m_callbacks_pending GUARDED_BY (m_callbacks_mutex)
 
bool m_are_callbacks_running GUARDED_BY (m_callbacks_mutex)
 
void MaybeScheduleProcessQueue () EXCLUSIVE_LOCKS_REQUIRED(!m_callbacks_mutex)
 
void ProcessQueue () EXCLUSIVE_LOCKS_REQUIRED(!m_callbacks_mutex)
 

Private Attributes

CSchedulerm_scheduler
 
Mutex m_callbacks_mutex
 

Detailed Description

Class used by CScheduler clients which may schedule multiple jobs which are required to be run serially.

Jobs may not be run on the same thread, but no two jobs will be executed at the same time and memory will be release-acquire consistent (the scheduler will internally do an acquire before invoking a callback as well as a release at the end). In practice this means that a callback B() will be able to observe all of the effects of callback A() which executed before it.

Definition at line 124 of file scheduler.h.

Constructor & Destructor Documentation

◆ SerialTaskRunner()

SerialTaskRunner::SerialTaskRunner ( CScheduler &scheduler  LIFETIMEBOUND)
inlineexplicit

Definition at line 141 of file scheduler.h.

Member Function Documentation

◆ flush()

void SerialTaskRunner::flush ( )
overridevirtual

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!

Implements util::TaskRunnerInterface.

Definition at line 185 of file scheduler.cpp.

Here is the call graph for this function:

◆ GUARDED_BY() [1/2]

std::list<std::function<void()> > m_callbacks_pending SerialTaskRunner::GUARDED_BY ( m_callbacks_mutex  )
private

◆ GUARDED_BY() [2/2]

bool m_are_callbacks_running SerialTaskRunner::GUARDED_BY ( m_callbacks_mutex  )
private

◆ insert()

void SerialTaskRunner::insert ( std::function< void()>  func)
overridevirtual

Add a callback to be executed.

Callbacks are executed serially and memory is release-acquire consistent between callback executions. Practically, this means that callbacks can behave as if they are executed in order by a single thread.

Implements util::TaskRunnerInterface.

Definition at line 176 of file scheduler.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MaybeScheduleProcessQueue()

void SerialTaskRunner::MaybeScheduleProcessQueue ( )
private

Definition at line 132 of file scheduler.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ProcessQueue()

void SerialTaskRunner::ProcessQueue ( )
private

Definition at line 145 of file scheduler.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ size()

size_t SerialTaskRunner::size ( )
overridevirtual

Returns the number of currently pending events.

Implements util::TaskRunnerInterface.

Definition at line 196 of file scheduler.cpp.

Member Data Documentation

◆ m_callbacks_mutex

Mutex SerialTaskRunner::m_callbacks_mutex
private

Definition at line 129 of file scheduler.h.

◆ m_scheduler

CScheduler& SerialTaskRunner::m_scheduler
private

Definition at line 127 of file scheduler.h.


The documentation for this class was generated from the following files: