xrpld
Loading...
Searching...
No Matches
xrpl::JobQueue::Coro Class Reference

Coroutines must run to completion. More...

#include <JobQueue.h>

Inheritance diagram for xrpl::JobQueue::Coro:
Collaboration diagram for xrpl::JobQueue::Coro:

Public Member Functions

template<class F>
 Coro (CoroCreateT, JobQueue &, JobType, std::string, F &&)
 Coro (Coro const &)=delete
Corooperator= (Coro const &)=delete
 ~Coro ()
void yield () const
 Suspend coroutine execution.
bool post ()
 Schedule coroutine execution.
void resume ()
 Resume coroutine execution.
bool runnable () const
 Returns true if the Coro is still runnable (has not returned).
void expectEarlyExit ()
 Once called, the Coro allows early exit without an assert.
void join ()
 Waits until coroutine returns from the user function.
shared_from_this (T... args)
weak_from_this (T... args)

Private Attributes

detail::LocalValues lvs_
JobQueuejq_
JobType type_
std::string name_
bool running_ {false}
std::mutex mutex_
std::mutex mutexRun_
std::condition_variable cv_
boost::coroutines2::coroutine< void >::push_type * yield_ {}
boost::coroutines2::coroutine< void >::pull_type coro_
bool finished_ = false

Detailed Description

Coroutines must run to completion.

Definition at line 46 of file JobQueue.h.

Constructor & Destructor Documentation

◆ Coro() [1/2]

template<class F>
xrpl::JobQueue::Coro::Coro ( CoroCreateT ,
JobQueue & ,
JobType ,
std::string ,
F &&  )

◆ Coro() [2/2]

xrpl::JobQueue::Coro::Coro ( Coro const & )
delete

◆ ~Coro()

xrpl::JobQueue::Coro::~Coro ( )

Member Function Documentation

◆ operator=()

Coro & xrpl::JobQueue::Coro::operator= ( Coro const & )
delete

◆ yield()

void xrpl::JobQueue::Coro::yield ( ) const

Suspend coroutine execution.

Effects: The coroutine's stack is saved. The associated Job thread is released. Note: The associated Job function returns. Undefined behavior if called consecutively without a corresponding post.

◆ post()

bool xrpl::JobQueue::Coro::post ( )

Schedule coroutine execution.

Effects: Returns immediately. A new job is scheduled to resume the execution of the coroutine. When the job runs, the coroutine's stack is restored and execution continues at the beginning of coroutine function or the statement after the previous call to yield. Undefined behavior if called after the coroutine has completed with a return (as opposed to a yield()). Undefined behavior if post() or resume() called consecutively without a corresponding yield.

Returns
true if the Coro's job is added to the JobQueue.

◆ resume()

void xrpl::JobQueue::Coro::resume ( )

Resume coroutine execution.

Effects: The coroutine continues execution from where it last left off using this same thread. If the coroutine has already completed, returns immediately (handles the documented post-before-yield race condition). Undefined behavior if resume() or post() called consecutively without a corresponding yield.

◆ runnable()

bool xrpl::JobQueue::Coro::runnable ( ) const

Returns true if the Coro is still runnable (has not returned).

◆ expectEarlyExit()

void xrpl::JobQueue::Coro::expectEarlyExit ( )

Once called, the Coro allows early exit without an assert.

◆ join()

void xrpl::JobQueue::Coro::join ( )

Waits until coroutine returns from the user function.

Member Data Documentation

◆ lvs_

detail::LocalValues xrpl::JobQueue::Coro::lvs_
private

Definition at line 49 of file JobQueue.h.

◆ jq_

JobQueue& xrpl::JobQueue::Coro::jq_
private

Definition at line 50 of file JobQueue.h.

◆ type_

JobType xrpl::JobQueue::Coro::type_
private

Definition at line 51 of file JobQueue.h.

◆ name_

std::string xrpl::JobQueue::Coro::name_
private

Definition at line 52 of file JobQueue.h.

◆ running_

bool xrpl::JobQueue::Coro::running_ {false}
private

Definition at line 53 of file JobQueue.h.

◆ mutex_

std::mutex xrpl::JobQueue::Coro::mutex_
private

Definition at line 54 of file JobQueue.h.

◆ mutexRun_

std::mutex xrpl::JobQueue::Coro::mutexRun_
private

Definition at line 55 of file JobQueue.h.

◆ cv_

std::condition_variable xrpl::JobQueue::Coro::cv_
private

Definition at line 56 of file JobQueue.h.

◆ yield_

boost::coroutines2::coroutine<void>::push_type* xrpl::JobQueue::Coro::yield_ {}
private

Definition at line 57 of file JobQueue.h.

◆ coro_

boost::coroutines2::coroutine<void>::pull_type xrpl::JobQueue::Coro::coro_
private

Definition at line 58 of file JobQueue.h.

◆ finished_

bool xrpl::JobQueue::Coro::finished_ = false
private

Definition at line 60 of file JobQueue.h.