WSF
WsfThread Class Referenceabstract

#include <WsfThread.hpp>

Inheritance diagram for WsfThread:

Public Types

enum  FunctionType {
  STOPPED = 0 , AVAILABLE = 1 , ASSIGNED = 2 , PAUSED = 3 ,
  CRITICAL = 4
}

Public Member Functions

 WsfThread ()=default
 ~WsfThread () override=default
void Run () override
FunctionType GetFunction () const
bool CriticalWork () const
 Thread Run() function status methods.
bool ReadyForWork () const
bool Stopped () const
bool AssignWork ()
 Thread internal Run() control methods.
bool StopWork ()
bool ForceStopWork ()
bool PauseWork ()
void EndThread ()
void WaitUntilWorkDone ()
bool TryWaitUntilWorkDone (double aTimeoutSecs)
virtual void Available ()
 Methods called by the thread's Run() method.
virtual FunctionType DoWork ()=0
virtual FunctionType Pause ()=0

Protected Member Functions

bool BeginCriticalWork ()
bool EndCriticalWork ()
bool SetFunction (FunctionType aOldFunction, FunctionType aNewFunction)

Protected Attributes

FunctionType mSavedState = STOPPED
std::condition_variable mWorkDoneCond
std::mutex mFunctionWriteMutex

Member Enumeration Documentation

◆ FunctionType

Enumerator
STOPPED 
AVAILABLE 
ASSIGNED 
PAUSED 
CRITICAL 

Constructor & Destructor Documentation

◆ WsfThread()

◆ ~WsfThread()

WsfThread::~WsfThread ( )
overridedefault

References Run().

Member Function Documentation

◆ AssignWork()

bool WsfThread::AssignWork ( )
inline

◆ Available()

void WsfThread::Available ( )
virtual

Methods called by the thread's Run() method.

Define what happens when the thread is in the AVAILABLE state. The default is to do nothing.

Note
This method does not return the next state of the thread, as this easily leads to a race condition. Instead, use the WsfThread::AssignWork and WsfThread::StopWork methods to transition to other states.

References AVAILABLE, and mFunctionWriteMutex.

Referenced by Run().

◆ BeginCriticalWork()

bool WsfThread::BeginCriticalWork ( )
protected

References CRITICAL, mSavedState, and SetFunction().

Referenced by Pause().

◆ CriticalWork()

bool WsfThread::CriticalWork ( ) const
inline

Thread Run() function status methods.

References CRITICAL.

◆ DoWork()

virtual FunctionType WsfThread::DoWork ( )
pure virtual

The user defines the processing to be performed during the ASSIGNED state by implementing this method.

Returns
The FunctionType defining the state the thread will be in after completion of the work. If the work is complete, return either AVAILABLE or PAUSED; otherwise return ASSIGNED.

Implemented in WsfDisIO_Thread, and WsfMultiThreadManager::SimulationUpdateThread.

Referenced by Run().

◆ EndCriticalWork()

bool WsfThread::EndCriticalWork ( )
protected

References CRITICAL, mSavedState, and SetFunction().

Referenced by Pause().

◆ EndThread()

void WsfThread::EndThread ( )

Sets the flag to break the thread Run() function out of its loop. This will cause the thread function to return ending / terminating the thread. This method should be called as part of a destructor or clean up

References mFunctionWriteMutex.

Referenced by WsfDisIO_Thread::SimulationComplete().

◆ ForceStopWork()

bool WsfThread::ForceStopWork ( )

References SetFunction(), and STOPPED.

◆ GetFunction()

◆ Pause()

virtual FunctionType WsfThread::Pause ( )
pure virtual

The user defines the processing to be performed during the PAUSED state by implementing this method.

Returns
The FunctionType defining the state the thread will be in after completion of the work. If the pause is complete, return either AVAILABLE or ASSIGNED; otherwise return PAUSED.

Implemented in WsfDisIO_Thread, and WsfMultiThreadManager::SimulationUpdateThread.

References BeginCriticalWork(), and EndCriticalWork().

Referenced by Run().

◆ PauseWork()

bool WsfThread::PauseWork ( )

References CRITICAL, PAUSED, and SetFunction().

◆ ReadyForWork()

bool WsfThread::ReadyForWork ( ) const
inline

◆ Run()

void WsfThread::Run ( )
override

This method is the main thread function. It calls all other methods that are part of this thread. The while loop will execute until the 'end thread' flag is set externally to this method or the thread function is set to stopped internally by this method. Either one will then cause this function return, ending the thread.

References ASSIGNED, AVAILABLE, Available(), DoWork(), mFunctionWriteMutex, mWorkDoneCond, Pause(), PAUSED, SetFunction(), and STOPPED.

Referenced by ~WsfThread().

◆ SetFunction()

bool WsfThread::SetFunction ( FunctionType aOldFunction,
FunctionType aNewFunction )
protected

◆ Stopped()

bool WsfThread::Stopped ( ) const
inline

References STOPPED.

◆ StopWork()

bool WsfThread::StopWork ( )
inline

◆ TryWaitUntilWorkDone()

bool WsfThread::TryWaitUntilWorkDone ( double aTimeoutSecs)

◆ WaitUntilWorkDone()

void WsfThread::WaitUntilWorkDone ( )

Member Data Documentation

◆ mFunctionWriteMutex

std::mutex WsfThread::mFunctionWriteMutex
protected

◆ mSavedState

FunctionType WsfThread::mSavedState = STOPPED
protected

◆ mWorkDoneCond

std::condition_variable WsfThread::mWorkDoneCond
protected

The documentation for this class was generated from the following files:
Copyrights Multiple, All Rights Reserved