TPIE

11a2c2d
tpie::pipelining::parallel_bits::state_base Class Reference

Common state in parallel pipelining library. More...

#include <tpie/pipelining/parallel/base.h>

Public Types

typedef std::mutex mutex_t
 
typedef std::condition_variable cond_t
 
typedef std::unique_lock< std::mutex > lock_t
 

Public Member Functions

void set_input_ptr (size_t idx, node *v)
 Must not be used concurrently. More...
 
void set_output_ptr (size_t idx, after_base *v)
 Must not be used concurrently. More...
 
nodeinput (size_t idx)
 Get the specified before instance. More...
 
after_baseoutput (size_t idx)
 Get the specified after instance. More...
 
worker_state get_state (size_t idx)
 Shared state, must have mutex to use. More...
 
void transition_state (size_t idx, worker_state from, worker_state to)
 Shared state, must have mutex to use. More...
 

Public Attributes

const options opts
 
mutex_t mutex
 Single mutex. More...
 
cond_t producerCond
 Condition variable. More...
 
cond_t * workerCond
 Condition variable, one per worker. More...
 
size_t runningWorkers
 Shared state, must have mutex to write. More...
 
std::exception_ptr eptr
 Exception thrown in worker thread to be rethrown in main thread. More...
 

Protected Member Functions

 state_base (const options opts)
 

Protected Attributes

std::vector< node * > m_inputs
 
std::vector< after_base * > m_outputs
 
std::vector< worker_state > m_states
 

Detailed Description

Common state in parallel pipelining library.

This class is instantiated once and kept in a std::shared_ptr, and it is not copy constructible.

Unless noted otherwise, a thread must own the state mutex to access other parts of this instance.

Definition at line 207 of file base.h.

Member Function Documentation

◆ get_state()

worker_state tpie::pipelining::parallel_bits::state_base::get_state ( size_t  idx)
inline

Shared state, must have mutex to use.

Definition at line 275 of file base.h.

275  {
276  return m_states[idx];
277  }

◆ input()

node& tpie::pipelining::parallel_bits::state_base::input ( size_t  idx)
inline

Get the specified before instance.

Enables easy construction of the pipeline graph at runtime.

Shared state, must have mutex to use.

Definition at line 260 of file base.h.

260 { return *m_inputs[idx]; }

◆ output()

after_base& tpie::pipelining::parallel_bits::state_base::output ( size_t  idx)
inline

Get the specified after instance.

Serves two purposes: First, it enables easy construction of the pipeline graph at runtime. Second, it is used by before to send batch signals to after.

Shared state, must have mutex to use.

Definition at line 272 of file base.h.

272 { return *m_outputs[idx]; }

◆ set_input_ptr()

void tpie::pipelining::parallel_bits::state_base::set_input_ptr ( size_t  idx,
node v 
)
inline

Must not be used concurrently.

Definition at line 244 of file base.h.

244  {
245  m_inputs[idx] = v;
246  }

◆ set_output_ptr()

void tpie::pipelining::parallel_bits::state_base::set_output_ptr ( size_t  idx,
after_base v 
)
inline

Must not be used concurrently.

Definition at line 249 of file base.h.

249  {
250  m_outputs[idx] = v;
251  }

◆ transition_state()

void tpie::pipelining::parallel_bits::state_base::transition_state ( size_t  idx,
worker_state  from,
worker_state  to 
)
inline

Shared state, must have mutex to use.

Definition at line 280 of file base.h.

280  {
281  if (m_states[idx] != from) {
282  std::stringstream ss;
283  ss << idx << " Invalid state transition " << from << " -> " << to << "; current state is " << m_states[idx];
284  log_error() << ss.str() << std::endl;
285  throw exception(ss.str());
286  }
287  m_states[idx] = to;
288  }

References tpie::log_error().

Member Data Documentation

◆ eptr

std::exception_ptr tpie::pipelining::parallel_bits::state_base::eptr

Exception thrown in worker thread to be rethrown in main thread.

Definition at line 241 of file base.h.

◆ mutex

mutex_t tpie::pipelining::parallel_bits::state_base::mutex

Single mutex.

Definition at line 216 of file base.h.

◆ producerCond

cond_t tpie::pipelining::parallel_bits::state_base::producerCond

Condition variable.

Who waits: The producer, with the single mutex (waits until at least one worker has state = IDLE or state = OUTPUTTING).

Who signals: The par_after, when a worker is OUTPUTTING.

Definition at line 224 of file base.h.

◆ runningWorkers

size_t tpie::pipelining::parallel_bits::state_base::runningWorkers

Shared state, must have mutex to write.

Definition at line 238 of file base.h.

◆ workerCond

cond_t* tpie::pipelining::parallel_bits::state_base::workerCond

Condition variable, one per worker.

Who waits: The worker's par_before when waiting for input (wait for state = PROCESSING), the worker's par_after when waiting for output to be read (wait for state = IDLE). Waits with the single mutex.

Who signals: par_producer, when input has been written (sets state to PROCESSING). par_consumer, when output has been read (sets state to IDLE).

Definition at line 235 of file base.h.


The documentation for this class was generated from the following file:
tpie::log_error
logstream & log_error()
Return logstream for writing error log messages.
Definition: tpie_log.h:148