CFEL - ASG Software Suite  2.5.0
CASS
Public Types | Public Slots | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
lmf::PausableThread Class Referenceabstract

A QThread that has the ability to be paused and resumed. More...

#include <pausablethread.h>

+ Inheritance diagram for lmf::PausableThread:
+ Collaboration diagram for lmf::PausableThread:

Public Types

enum  status_t { running, paused, notstarted }
 enum describing the internal status of the thread More...
 
enum  control_t { _run, _quit, _pause }
 enum describing the control status of the thread More...
 
enum  exception_t {
  NO_EXCEPTION, INVALID_ARGUMENT_EXCEPTION, RUNTIME_ERROR_EXCEPTION, OUT_OF_RANGE_EXCEPTION,
  LOGIC_ERROR_EXCEPTION, STANDART_EXCEPTION, UNKNOWN_EXCEPTION
}
 enum describing which exception was thrown More...
 

Public Slots

virtual void end ()
 tell the thread to quit More...
 

Public Member Functions

 PausableThread (control_t control=_run, QObject *parent=0)
 constructor More...
 
virtual ~PausableThread ()
 destructor More...
 
void run ()
 run the thread More...
 
virtual void runthis ()=0
 contains the code to run in the thread More...
 
void pause (bool block=false)
 pause the thread More...
 
void waitUntilPaused ()
 waits until thread is paused More...
 
void resume ()
 resume the thread More...
 
status_t status () const
 return the current status of the thread More...
 
bool shouldQuit () const
 query whether this thread is told to quit More...
 
void rethrowException () const
 rethrow the thrown exception More...
 
exception_t exceptionThrown () const
 
- Public Member Functions inherited from QThread
 QThread (QObject *parent=0)
 
 currentThread ()
 
 HANDLE QThread::currentThreadId()
 
 exec ()
 
 exit (int returnCode=0)
 
 finished ()
 
 idealThreadCount ()
 
 isFinished ()
 
 isRunning ()
 
 msleep (unsigned long msecs)
 
 priority ()
 
 quit ()
 
 run ()
 
 setPriority (Priority priority)
 
 setStackSize (uint stackSize)
 
 setTerminationEnabled (bool enabled=true)
 
 sleep (unsigned long secs)
 
 stackSize ()
 
 start (Priority priority=InheritPriority)
 
 started ()
 
 terminate ()
 
 terminated ()
 
 usleep (unsigned long usecs)
 
 wait (unsigned long time=ULONG_MAX)
 
 yieldCurrentThread ()
 

Protected Member Functions

void pausePoint ()
 point where the thread will be paused More...
 

Protected Attributes

QMutex _pauseMutex
 mutex to wait on until thread is paused More...
 
QWaitCondition _pauseCondition
 wait condition to wait on until thread is resumed More...
 
QWaitCondition _waitUntilPausedCondition
 wait condition to wait unitl thread is paused More...
 
status_t _status
 the internal status of the thread More...
 
control_t _control
 the internal control status of the thread More...
 
size_t _pausecount
 a counter how many threads have pause this thread More...
 
exception_t _exception_thrown
 flag to show that general exception was thrown More...
 
std::invalid_argument _invarg_excep
 the invalid arguemnt exception thrown More...
 
std::runtime_error _runt_excep
 the invalid arguemnt exception thrown More...
 
std::out_of_range _outrange_excep
 the invalid arguemnt exception thrown More...
 
std::logic_error _logic_excep
 the invalid arguemnt exception thrown More...
 

Detailed Description

A QThread that has the ability to be paused and resumed.

This class inherits from QThread and enhances the QThread class to be able to be paused and resumed

Todo:
check the logic whether this is threadsafe (maybe need to add some more mutexlockers.)
Author
Lutz Foucar

Definition at line 28 of file pausablethread.h.

Member Enumeration Documentation

enum describing the control status of the thread

Enumerator
_run 
_quit 
_pause 

Definition at line 36 of file pausablethread.h.

enum describing which exception was thrown

Enumerator
NO_EXCEPTION 
INVALID_ARGUMENT_EXCEPTION 
RUNTIME_ERROR_EXCEPTION 
OUT_OF_RANGE_EXCEPTION 
LOGIC_ERROR_EXCEPTION 
STANDART_EXCEPTION 
UNKNOWN_EXCEPTION 

Definition at line 39 of file pausablethread.h.

enum describing the internal status of the thread

Enumerator
running 
paused 
notstarted 

Definition at line 33 of file pausablethread.h.

Constructor & Destructor Documentation

lmf::PausableThread::PausableThread ( control_t  control = _run,
QObject parent = 0 
)
inline

constructor

You can construct this thread to be either paused or running when you call the start() member of the created object.

Parameters
controlthe initial state of the thread
parentpointer to the parent object

Definition at line 59 of file pausablethread.h.

PausableThread::~PausableThread ( )
virtual

destructor

stops the threads execution before deleting the thread. Make sure that all waitconditions are properly shut down.

Definition at line 17 of file pausablethread.cpp.

Member Function Documentation

virtual void lmf::PausableThread::end ( )
inlinevirtualslot

tell the thread to quit

Reimplemented in cass::SharedMemoryInput.

Definition at line 141 of file pausablethread.h.

References _control, and _quit.

exception_t lmf::PausableThread::exceptionThrown ( ) const
inline
Returns
the exception thrown

Definition at line 137 of file pausablethread.h.

References _exception_thrown.

void PausableThread::pause ( bool  block = false)

pause the thread

Will tell the thread to pause. The function can be told to block until the thread is paused. It does that by waiting internaly on waitUntilPaused() to return. If one does not want this function to block, just call it with the default argument (false).

Parameters
blockif true this function call will block until the thread is paused. If false this will return immidiatly (default).

Definition at line 73 of file pausablethread.cpp.

void PausableThread::pausePoint ( )
protected

point where the thread will be paused

Call this function from within your run() at the point where you can pause the thread whithout leaving it in an undefined state. It will check whether the thread is requested to pause, if so it will pause the thread.

Definition at line 109 of file pausablethread.cpp.

Referenced by cass::SharedMemoryInput::processDgram(), cass::ZMQInput::runthis(), cass::Worker::runthis(), cass::XFELOnlineInput::runthis(), cass::TCPInput::runthis(), cass::MultiFileInput::runthis(), and cass::SACLAOnlineInput::runthis().

void PausableThread::resume ( )

resume the thread

Will tell the thread to resume by waking up the Condition

Definition at line 94 of file pausablethread.cpp.

void PausableThread::rethrowException ( ) const

rethrow the thrown exception

this should only be called when the thread has quitted

Definition at line 121 of file pausablethread.cpp.

References LOGIC_ERROR_EXCEPTION, NO_EXCEPTION, OUT_OF_RANGE_EXCEPTION, RUNTIME_ERROR_EXCEPTION, STANDART_EXCEPTION, and UNKNOWN_EXCEPTION.

void PausableThread::run ( )

run the thread

this will call the pure virtual function runthis that needs to be implemented with the code that the thread should execute. It will handle all exceptions and ensures that they are not leaving the thread. One can check after exectution of the thread which exceptions have been thrown. Supported are std::invalid_argument std::runtime_error std::out_of_range

Definition at line 26 of file pausablethread.cpp.

virtual void lmf::PausableThread::runthis ( )
pure virtual
bool lmf::PausableThread::shouldQuit ( ) const
inline
status_t lmf::PausableThread::status ( ) const
inline

return the current status of the thread

Definition at line 122 of file pausablethread.h.

References _status.

void PausableThread::waitUntilPaused ( )

waits until thread is paused

Waits until the thread is paused by using the wait condition.

Definition at line 83 of file pausablethread.cpp.

Member Data Documentation

control_t lmf::PausableThread::_control
protected

the internal control status of the thread

Definition at line 166 of file pausablethread.h.

Referenced by cass::SharedMemoryInput::end(), end(), cass::TestInput::run(), cass::Worker::runthis(), cass::MultiFileInput::runthis(), and shouldQuit().

exception_t lmf::PausableThread::_exception_thrown
protected

flag to show that general exception was thrown

Definition at line 172 of file pausablethread.h.

Referenced by exceptionThrown().

std::invalid_argument lmf::PausableThread::_invarg_excep
protected

the invalid arguemnt exception thrown

Definition at line 175 of file pausablethread.h.

std::logic_error lmf::PausableThread::_logic_excep
protected

the invalid arguemnt exception thrown

Definition at line 184 of file pausablethread.h.

std::out_of_range lmf::PausableThread::_outrange_excep
protected

the invalid arguemnt exception thrown

Definition at line 181 of file pausablethread.h.

QWaitCondition lmf::PausableThread::_pauseCondition
protected

wait condition to wait on until thread is resumed

Definition at line 157 of file pausablethread.h.

size_t lmf::PausableThread::_pausecount
protected

a counter how many threads have pause this thread

Definition at line 169 of file pausablethread.h.

QMutex lmf::PausableThread::_pauseMutex
protected

mutex to wait on until thread is paused

Definition at line 154 of file pausablethread.h.

std::runtime_error lmf::PausableThread::_runt_excep
protected

the invalid arguemnt exception thrown

Definition at line 178 of file pausablethread.h.

status_t lmf::PausableThread::_status
protected
QWaitCondition lmf::PausableThread::_waitUntilPausedCondition
protected

wait condition to wait unitl thread is paused

Definition at line 160 of file pausablethread.h.


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