rippled
Public Member Functions | Private Attributes | List of all members
ripple::JobQueue::Coro Class Reference

Coroutines must run to completion. More...

Inheritance diagram for ripple::JobQueue::Coro:
Inheritance graph
[legend]
Collaboration diagram for ripple::JobQueue::Coro:
Collaboration graph
[legend]

Public Member Functions

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

Private Attributes

detail::LocalValues lvs_
 
JobQueuejq_
 
JobType type_
 
std::string name_
 
bool running_
 
std::mutex mutex_
 
std::mutex mutex_run_
 
std::condition_variable cv_
 
boost::coroutines::asymmetric_coroutine< void >::pull_type coro_
 
boost::coroutines::asymmetric_coroutine< void >::push_type * yield_
 
bool finished_ = false
 

Detailed Description

Coroutines must run to completion.

Definition at line 59 of file JobQueue.h.

Constructor & Destructor Documentation

◆ Coro() [1/2]

template<class F >
ripple::JobQueue::Coro::Coro ( Coro_create_t  ,
JobQueue ,
JobType  ,
std::string const &  ,
F &&   
)

◆ Coro() [2/2]

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

◆ ~Coro()

ripple::JobQueue::Coro::~Coro ( )

Member Function Documentation

◆ operator=()

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

◆ yield()

void ripple::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 ripple::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 ripple::JobQueue::Coro::resume ( )

Resume coroutine execution.

Effects: The coroutine continues execution from where it last left off using this same thread. Undefined behavior if called after the coroutine has completed with a return (as opposed to a yield()). Undefined behavior if resume() or post() called consecutively without a corresponding yield.

◆ runnable()

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

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

◆ expectEarlyExit()

void ripple::JobQueue::Coro::expectEarlyExit ( )

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

◆ join()

void ripple::JobQueue::Coro::join ( )

Waits until coroutine returns from the user function.

Member Data Documentation

◆ lvs_

detail::LocalValues ripple::JobQueue::Coro::lvs_
private

Definition at line 62 of file JobQueue.h.

◆ jq_

JobQueue& ripple::JobQueue::Coro::jq_
private

Definition at line 63 of file JobQueue.h.

◆ type_

JobType ripple::JobQueue::Coro::type_
private

Definition at line 64 of file JobQueue.h.

◆ name_

std::string ripple::JobQueue::Coro::name_
private

Definition at line 65 of file JobQueue.h.

◆ running_

bool ripple::JobQueue::Coro::running_
private

Definition at line 66 of file JobQueue.h.

◆ mutex_

std::mutex ripple::JobQueue::Coro::mutex_
private

Definition at line 67 of file JobQueue.h.

◆ mutex_run_

std::mutex ripple::JobQueue::Coro::mutex_run_
private

Definition at line 68 of file JobQueue.h.

◆ cv_

std::condition_variable ripple::JobQueue::Coro::cv_
private

Definition at line 69 of file JobQueue.h.

◆ coro_

boost::coroutines::asymmetric_coroutine<void>::pull_type ripple::JobQueue::Coro::coro_
private

Definition at line 70 of file JobQueue.h.

◆ yield_

boost::coroutines::asymmetric_coroutine<void>::push_type* ripple::JobQueue::Coro::yield_
private

Definition at line 71 of file JobQueue.h.

◆ finished_

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

Definition at line 73 of file JobQueue.h.