ecto
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
ecto::scheduler Class Reference

#include <scheduler.hpp>

Collaboration diagram for ecto::scheduler:
Collaboration graph
[legend]

Public Types

enum  State {
  INIT = 0, RUNNING, EXECUTING, STOPPING,
  FINI = -1, ERROR = -2
}
 

Public Member Functions

 scheduler (plasm_ptr p)
 
 ~scheduler ()
 
bool execute (unsigned num_iters=0)
 
bool prepare_jobs (unsigned num_iters=0)
 
bool run_job ()
 
bool run (unsigned timeout_usec)
 
bool run ()
 
bool running () const
 
bool executing () const
 
void stop ()
 
std::string stats () const
 
State state () const
 

Private Member Functions

State state (State)
 
void execute_init (unsigned num_iteRelWithDebInfors)
 
void execute_iter (unsigned cur_iter, unsigned num_iters, std::size_t stack_idx)
 
void execute_fini ()
 
void interrupt ()
 
void compute_stack ()
 

Private Attributes

plasm_ptr plasm_
 
ecto::graph::graph_tgraph_
 
std::vector< ecto::graph::graph_t::vertex_descriptor > stack_
 
profile::graph_stats_type graphstats_
 
boost::asio::io_service io_svc_
 
boost::mutex mtx_
 
State state_
 Current state of the scheduler. More...
 
std::size_t runners_
 Current number of "runners" (threads calling a run method). More...
 
boost::signals2::connection interrupt_connection
 
bool interrupted
 

Detailed Description

TODO: Doc this class. TODO: Need to share io_svc_ instances with other entities (schedulers+)?

Member Enumeration Documentation

Scheduler states. Values greater than 0 indicate a "running" state.

Enumerator
INIT 

None of the execute*() methods have been called yet.

RUNNING 

One of the execute*() methods was called and successfully completed the specified number of iterations.

EXECUTING 

execute() is running, or jobs have been prepared and the specified number of iterations have not been completed.

STOPPING 

stop() was called, but the scheduler has not stopped yet.

FINI 

stop() completed, or one of the cell::process() calls returned ecto::QUIT and the scheduler is no longer running.

ERROR 

One of the cell::process() calls returned an error or threw, and the scheduler is no longer running.

Constructor & Destructor Documentation

ecto::scheduler::scheduler ( plasm_ptr  p)
explicit
ecto::scheduler::~scheduler ( )

Member Function Documentation

void ecto::scheduler::compute_stack ( )
private

Check plasm for correctness, configure it, activate it, then sort it topologically to populate stack_. This method is idempotent.

bool ecto::scheduler::execute ( unsigned  num_iters = 0)

Synchronously execute plasm for num_iters iterations.

Parameters
[in]num_itersThe number of iterations to execute the plasm. 0 indicates that the plasm should be executed until some cell::process() call returns ecto::QUIT.
Attention
This call will block indefinately if num_iters is 0.
void ecto::scheduler::execute_fini ( )
private
void ecto::scheduler::execute_init ( unsigned  num_iteRelWithDebInfors)
private
void ecto::scheduler::execute_iter ( unsigned  cur_iter,
unsigned  num_iters,
std::size_t  stack_idx 
)
private
bool ecto::scheduler::executing ( ) const
inline
Returns
true indicates that the plasm is currently in an executing state ( state_ == EXECUTING).
void ecto::scheduler::interrupt ( )
private
bool ecto::scheduler::prepare_jobs ( unsigned  num_iters = 0)

Prepare jobs for execution of a plasm over num_iters iterations. No actual work will be done without calling the run*() methods. This just fills up the io service queues with the jobs required for initialisation and execution of the plasm over the specified number of iterations.

Parameters
[in]num_itersThe number of iterations to execute the plasm. 0 indicates that the plasm should be executed until some cell::process() call returns ecto::QUIT.
Attention
A call to run() will block indefinately if num_iters is 0.
bool ecto::scheduler::run ( unsigned  timeout_usec)

Run jobs in the calling thread for the specified number of microseconds, or until the io_service is depleted.

Parameters
[in]timeout_usecThe number of microsecs to run io_service jobs.
Attention
Assuming the io_service does not run out of work, this is the minimum amount of time that will be spent running jobs.
Returns
true indicates that the scheduler is still "running."
bool ecto::scheduler::run ( )

Run jobs in the calling thread until the io_service is depleted.

Returns
true indicates that the scheduler is still "running."
bool ecto::scheduler::run_job ( )

Run one job in the calling thread of execution.

Note
A job is not necessarily (but is usually) a cell::process() call.
Attention
If using python cells, this method must be called from the main python thread.
Returns
true indicates that the scheduler is still "running."
bool ecto::scheduler::running ( ) const
inline
Returns
true indicates that the plasm is currently in a running state (state_ > 0, i.e. RUNNING, EXECUTING, or STOPPING).
scheduler::State ecto::scheduler::state ( ) const
inline
Returns
The current scheduler state.
scheduler::State ecto::scheduler::state ( State  state)
inlineprivate
std::string ecto::scheduler::stats ( ) const
inline
Returns
The current graph execution stats.
void ecto::scheduler::stop ( )

Stop the scheduler, and flush any jobs in the io_service.

Note
The scheduler will no longer be in the running state.
Attention
The plasm may be in the middle of the stack when it is stopped, but successive calls to execute*() start from the beginning.

Member Data Documentation

ecto::graph::graph_t& ecto::scheduler::graph_
private
profile::graph_stats_type ecto::scheduler::graphstats_
private
boost::signals2::connection ecto::scheduler::interrupt_connection
private
bool ecto::scheduler::interrupted
private
boost::asio::io_service ecto::scheduler::io_svc_
private
boost::mutex ecto::scheduler::mtx_
mutableprivate
plasm_ptr ecto::scheduler::plasm_
private
std::size_t ecto::scheduler::runners_
private

Current number of "runners" (threads calling a run method).

std::vector<ecto::graph::graph_t::vertex_descriptor> ecto::scheduler::stack_
private
State ecto::scheduler::state_
private

Current state of the scheduler.


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