Mercury Currency Engine
Classes | Public Types | Public Member Functions | List of all members
mce::lifecycle Struct Reference

an interface for implementing lifecycle control operations More...

#include <scheduler.hpp>

Inheritance diagram for mce::lifecycle:
Inheritance graph
[legend]

Classes

struct  implementation
 virtual interface for implementors of lifecycle More...
 

Public Types

enum  state { ready , running , suspended , halted }
 an enumeration which represents the lifecycle object's current state More...
 

Public Member Functions

 lifecycle (implementation *self)
 
 lifecycle (implementation *self, implementation *root)
 
state get_state ()
 return the state of the lifecycle
 
bool suspend ()
 temporarily suspend operations More...
 
void resume ()
 resume any current or future call to run() after an suspend()
 
void halt ()
 halt and join lifecycle execution More...
 

Detailed Description

an interface for implementing lifecycle control operations

Member Enumeration Documentation

◆ state

an enumeration which represents the lifecycle object's current state

Enumerator
running 

is initial ready state

suspended 

is running

halted 

temporarily halted by a call to suspend()

permanently halted by a call to halt()

Constructor & Destructor Documentation

◆ lifecycle() [1/2]

mce::lifecycle::lifecycle ( implementation self)
inline

Any implementation of lifecycle should pass its this pointer to its lifecycle constructor.

◆ lifecycle() [2/2]

mce::lifecycle::lifecycle ( implementation self,
implementation root 
)
inline

Call public methods with the root lifecycle implementation's methods.

Lifecycle objects can be structured as a tree, where lifecycle objects own other lifecycle objects: root - child1 - child1-child1

  • child1-child2

child2 - child2-child1

  • child2-child2

etc

If each child is given the root's pointer, then root's _impl() methods will be called when the child's public methods are called. This allows synchronized lifecycle operations no matter where in the tree lifecycle public methods are called from.

In short: if suspend()/resume()/halt()/etc are called on a child object, and the child object was constructed with a root lifecycle pointer, the root's suspend_impl()/resume_impl()/halt_impl() methods will actually* be called.

All parent lifecycle _impl() methods should only call child _impl() methods when interacting with child lifecycle objects. IE, _impl() methods should not call public lifecycle methods.

Member Function Documentation

◆ halt()

void mce::lifecycle::halt ( )
inline

halt and join lifecycle execution

As a general rule, mce::lifecycle implementations are intended to run indefinitely and halt() should only be called on process shutdown. Failure to do so can cause strange program errors where code which is expected to run does not.

◆ suspend()

bool mce::lifecycle::suspend ( )
inline

temporarily suspend operations

Returns
false if lifecycle is halted, else true

The documentation for this struct was generated from the following file: