Autowiring  1.0.3
A C++ Inversion of Control Framework
CoreRunnable Class Reference

Provides the interface for threads that should receive start and stop notifications in a context More...

#include <CoreRunnable.h>

Inheritance diagram for CoreRunnable:
AutoPacketFactory AutoPacketGraph BasicThread CoreThread

Public Member Functions

virtual bool IsRunning (void) const
 Reports whether this runnable is currently running.
 
bool ShouldStop (void) volatile const
 Reports whether this runnable should stop.
 
virtual bool Start (std::shared_ptr< CoreObject > outstanding)
 Causes this runnable to begin processing. More...
 
void Stop (bool graceful=true)
 Stops this runnable. More...
 
bool ThreadSleep (std::chrono::nanoseconds timeout)
 Sleeps this thread for the specified duration. More...
 
void Wait (void)
 Waits indefinitely. Returns when this runnable stops. More...
 
bool WaitFor (std::chrono::nanoseconds timeout)
 Waits for the specified amount of time. More...
 
template<typename TimeType >
bool WaitUntil (TimeType timepoint)
 Waits until the specified time. More...
 
bool WasStarted (void) volatile const
 Reports whether this runnable was ever started.
 

Protected Member Functions

virtual bool DoAdditionalWait (std::chrono::nanoseconds timeout)
 Invoked just before control is returned to the user. More...
 
virtual void DoAdditionalWait (void)
 Untimed variant of DoAdditionalWait More...
 
const std::shared_ptr< CoreObject > & GetOutstanding (void) const
 
virtual bool OnStart (void)
 Invoked by the Start() method. Override this method to perform any needed setup More...
 
virtual void OnStop (bool graceful)
 Invoked by the base class Stop() method. Override this method to perform any needed cleanup. More...
 

Detailed Description

Provides the interface for threads that should receive start and stop notifications in a context

Users of Autowiring will typically use BasicThread or CoreThread instead of extending this class.

Member Function Documentation

virtual bool CoreRunnable::DoAdditionalWait ( std::chrono::nanoseconds  timeout)
inlineprotectedvirtual

Invoked just before control is returned to the user.

Parameters
timeoutThe maximum amount of time to wait
Returns
True if the wait succeeded, false if a timeout occurred

This virtual method provides implementors with a way to add further constraints to the wait operation beyond the condition variable held internally by this CoreRunnable.

This method must return true if the timeout is indefinite.

Reimplemented in BasicThread, and AutoPacketFactory.

virtual void CoreRunnable::DoAdditionalWait ( void  )
inlineprotectedvirtual

Untimed variant of DoAdditionalWait

Reimplemented in BasicThread, and AutoPacketFactory.

const std::shared_ptr<CoreObject>& CoreRunnable::GetOutstanding ( void  ) const
protected
Returns
A reference to the current outstanding counter
virtual bool CoreRunnable::OnStart ( void  )
inlineprotectedvirtual

Invoked by the Start() method. Override this method to perform any needed setup

Returns
True if processing has started, false otherwise. When overriding, returning false will shut down the runnable immediately.

This method will be called at most once. Returning false from this method will result in an immediate invocation of OnStop(false).

Reimplemented in BasicThread, AutoPacketGraph, and AutoPacketFactory.

virtual void CoreRunnable::OnStop ( bool  graceful)
inlineprotectedvirtual

Invoked by the base class Stop() method. Override this method to perform any needed cleanup.

Parameters
gracefulSpecifies whether the runnable should stop normally or whether it should exit as quickly as possible.

This method will be called at most once from a passive level.

Reimplemented in BasicThread, CoreThread, and AutoPacketFactory.

virtual bool CoreRunnable::Start ( std::shared_ptr< CoreObject >  outstanding)
virtual

Causes this runnable to begin processing.

Returns
This method always returns true.

It is an error to call this routine more than once. The passed outstanding shared pointer is used to keep tracking of number of simultaneous runnables outstanding. This routine may be called even after Stop has been called; the caller MUST return false in this case.

Callers should strongly prefer not to override Start if possible. Instead, override OnStart and obtain an instance of the outstanding pointer via GetOutstanding

void CoreRunnable::Stop ( bool  graceful = true)

Stops this runnable.

Calls OnStop(), forwarding the graceful parameter.

On return of this method, regardless of the return value, a subsequent call to Wait is guaranteed to either return immediately, or once the thread implementation completes.

bool CoreRunnable::ThreadSleep ( std::chrono::nanoseconds  timeout)

Sleeps this thread for the specified duration.

Returns
False if the thread was terminated before the timeout elapsed.
void CoreRunnable::Wait ( void  )

Waits indefinitely. Returns when this runnable stops.

bool CoreRunnable::WaitFor ( std::chrono::nanoseconds  timeout)

Waits for the specified amount of time.

template<typename TimeType >
bool CoreRunnable::WaitUntil ( TimeType  timepoint)

Waits until the specified time.

Parameters
timepointA std::chrono type representing a duration or future point in time.

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