kwave
18.07.70
|
#include <WorkerThread.h>
Public Member Functions | |
WorkerThread (Kwave::Runnable *runnable, QVariant params) | |
virtual | ~WorkerThread () Q_DECL_OVERRIDE |
virtual void | start () |
virtual int | stop (unsigned int timeout=10000) |
virtual void | run () Q_DECL_OVERRIDE |
virtual void | cancel () |
bool | shouldStop () |
Private Attributes | |
Kwave::Runnable * | m_runnable |
QVariant | m_params |
QMutex | m_lock |
QMutex | m_lock_sighup |
QAtomicInt | m_should_stop |
pthread_t | m_tid |
pthread_t | m_owner_tid |
Definition at line 35 of file WorkerThread.h.
|
explicit |
Constructor
Definition at line 51 of file WorkerThread.cpp.
References _dummy_SIGHUP_handler(), and g_signal_handler_is_in_place.
|
virtual |
Destructor, calls stop() if the thread is still running.
Definition at line 77 of file WorkerThread.cpp.
References stop().
|
virtual |
Sets an internal flag that signals the worker thread to cancel, so that the next call to "shouldStop()" returns true.
Definition at line 176 of file WorkerThread.cpp.
References m_should_stop.
Referenced by Kwave::PlayBackPulseAudio::disconnectFromServer(), Kwave::RecordPulseAudio::disconnectFromServer(), Kwave::PlaybackController::run_wrapper(), and Kwave::PlaybackController::stopDevicePlayBack().
|
virtual |
A wrapper for the run() function, calls the run_wrapper(...) of m_runnable with the parameters passed in the constructor.
Reimplemented in Kwave::RecordThread.
Definition at line 154 of file WorkerThread.cpp.
References m_lock_sighup, m_owner_tid, m_params, m_runnable, m_tid, and Kwave::Runnable::run_wrapper().
bool Kwave::WorkerThread::shouldStop | ( | ) |
Returns true if the thread should stop. Should be polled by the thread's run() function to wait for a termination signal.
Definition at line 182 of file WorkerThread.cpp.
References m_should_stop.
Referenced by Kwave::RecordThread::run(), and Kwave::PlaybackController::run_wrapper().
|
virtual |
Starts the thread's execution.
Definition at line 89 of file WorkerThread.cpp.
References m_lock, and m_should_stop.
Referenced by Kwave::PlayBackPulseAudio::connectToServer(), Kwave::RecordPulseAudio::connectToServer(), Kwave::Plugin::execute(), Kwave::RecordPlugin::leaveInhibit(), and Kwave::PlaybackController::startDevicePlayBack().
|
virtual |
Stops the thread execution. Please note that you MUST call this function at the end if you derived a class from this one.
timeout | the timeout in milliseconds, default = 10s |
Definition at line 100 of file WorkerThread.cpp.
References m_lock, m_lock_sighup, m_owner_tid, m_should_stop, m_tid, and MAX_ATTEMPTS_TO_STOP.
Referenced by Kwave::PlayBackPulseAudio::disconnectFromServer(), Kwave::RecordPulseAudio::disconnectFromServer(), Kwave::RecordPlugin::enterInhibit(), Kwave::RecordPlugin::setup(), Kwave::RecordPlugin::setupRecordThread(), Kwave::Plugin::stop(), Kwave::Plugin::~Plugin(), Kwave::RecordThread::~RecordThread(), and ~WorkerThread().
|
private |
Mutex to control access to the thread itself
Definition at line 86 of file WorkerThread.h.
|
private |
Mutex for protecting SIGHUP <-> thread exit
Definition at line 89 of file WorkerThread.h.
|
private |
POSIX compatible thread ID of the owner thread.
Definition at line 102 of file WorkerThread.h.
|
private |
parameter pointer passed to the run() function
Definition at line 83 of file WorkerThread.h.
Referenced by run().
|
private |
pointer to the object that has a run() function
Definition at line 80 of file WorkerThread.h.
Referenced by run().
|
private |
set to 1 to signal the thread that it should stop
Definition at line 92 of file WorkerThread.h.
Referenced by cancel(), shouldStop(), start(), and stop().
|
private |
POSIX compatible thread ID of the worker thread. only needed and only valid while the thread is running. (needs a POSIX 1003.1-2001 system libc)
Definition at line 99 of file WorkerThread.h.