CFEL - ASG Software Suite
2.5.0
CASS
|
A QThread that has the ability to be paused and resumed. More...
#include <pausablethread.h>
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 |
![]() | |
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... | |
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
Definition at line 28 of file pausablethread.h.
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
You can construct this thread to be either paused or running when you call the start() member of the created object.
control | the initial state of the thread |
parent | pointer to the parent object |
Definition at line 59 of file pausablethread.h.
|
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.
|
inlinevirtualslot |
tell the thread to quit
Reimplemented in cass::SharedMemoryInput.
Definition at line 141 of file pausablethread.h.
|
inline |
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).
block | if 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.
|
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.
|
pure virtual |
contains the code to run in the thread
needs to be implemented by the derived threads
Implemented in cass::HDF5FileInput, cass::SACLAOnlineInput, cass::XFELHDF5FileInput, cass::MultiFileInput, cass::TCPInput, cass::SACLAOfflineInput, cass::XFELOnlineInput, cass::TagListProcessor, cass::Worker, cass::FileProcessor, cass::FileInput, cass::SharedMemoryInput, cass::ZMQInput, cass::ACQIRIS::LMAParser, cass::XtcParser, cass::InputBase, and cass::TxtParser.
|
inline |
query whether this thread is told to quit
Definition at line 128 of file pausablethread.h.
References _control, and _quit.
Referenced by cass::TCPInput::connectToServer(), cass::TCPInput::dataAvailable(), cass::SharedMemoryInput::processDgram(), cass::MultiFileInput::readEventData(), cass::ZMQInput::runthis(), cass::FileInput::runthis(), cass::XFELOnlineInput::runthis(), cass::SACLAOfflineInput::runthis(), cass::TCPInput::runthis(), cass::MultiFileInput::runthis(), cass::XFELHDF5FileInput::runthis(), cass::SACLAOnlineInput::runthis(), and cass::HDF5FileInput::runthis().
|
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.
|
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().
|
protected |
flag to show that general exception was thrown
Definition at line 172 of file pausablethread.h.
Referenced by exceptionThrown().
|
protected |
the invalid arguemnt exception thrown
Definition at line 175 of file pausablethread.h.
|
protected |
the invalid arguemnt exception thrown
Definition at line 184 of file pausablethread.h.
|
protected |
the invalid arguemnt exception thrown
Definition at line 181 of file pausablethread.h.
|
protected |
wait condition to wait on until thread is resumed
Definition at line 157 of file pausablethread.h.
|
protected |
a counter how many threads have pause this thread
Definition at line 169 of file pausablethread.h.
|
protected |
mutex to wait on until thread is paused
Definition at line 154 of file pausablethread.h.
|
protected |
the invalid arguemnt exception thrown
Definition at line 178 of file pausablethread.h.
|
protected |
the internal status of the thread
Definition at line 163 of file pausablethread.h.
Referenced by cass::TestInput::run(), cass::ZMQInput::runthis(), cass::FileInput::runthis(), cass::SharedMemoryInput::runthis(), cass::Worker::runthis(), cass::SACLAOfflineInput::runthis(), cass::XFELOnlineInput::runthis(), cass::TCPInput::runthis(), cass::MultiFileInput::runthis(), cass::XFELHDF5FileInput::runthis(), cass::HDF5FileInput::runthis(), and status().
|
protected |
wait condition to wait unitl thread is paused
Definition at line 160 of file pausablethread.h.