Just Intonation  Version 1.3.0 (18)
Explore scale-independent dynamically adapting tuning in just intonation
ThreadWorker Class Reference

Helper class for ThreadBase. More...

#include <threadworker.h>

Inheritance diagram for ThreadWorker:
Inheritance graph
Collaboration diagram for ThreadWorker:
Collaboration graph

Signals

void startTimer ()
 Helper signal for starting the temporarily existing timer. More...
 
void stopTimer ()
 Helper signal for stopping the temporarily existing timer. More...
 

Public Member Functions

 ThreadWorker (ThreadBase *threadbase)
 Constructor. More...
 
void setPriority (const QThread::Priority p)
 Specify the priority of the thread. More...
 
void setTimerInterval (const int msec, const int firstMsec)
 Set timer interval in milliseconds. More...
 
void setThreadName (const QString name)
 Set thread name. More...
 
QString getThreadName () const
 Helper function for debugging: Get the current thread id and time. More...
 
bool start ()
 Start thread and move base class to the new thread. More...
 
bool stop ()
 Send a request to the thread for termination. More...
 
void setVerbosity (int verbosity)
 Set the verbosity level of the class-specific messages. More...
 
int getVerbosity ()
 Get the actual verbosity level. More...
 

Private Member Functions

virtual void run () override final
 Private thread worker function, starting execution loop. More...
 
void setCurrentThreadName (QString threadname)
 Helper function for debugging: set the current thread name. More...
 

Private Attributes

ThreadBasepThreadBase
 Pointer back to the instance of the ThreadBase. More...
 
QString mThreadName
 Assigned thread name. More...
 
QThread::Priority mPriority
 Assigned priority of the thread. More...
 
int mInterval
 
int mFirstInterval
 Assigned periodic waiting time in milliseconds. More...
 

Detailed Description

Helper class for ThreadBase.

ThreadWorker is a helper class for ThreadBase. It is needed because the new thread needs to be started in an instance different from the calling instance so that the slots of the calling instance can be moved later to the thread of the new instance. This trick ensures that all slots of the calling instance (ThreadBase) are running in the newly created thread. (This is the main purpose of the whole construction)

See also
ThreadBase

Definition at line 44 of file threadworker.h.

Constructor & Destructor Documentation

ThreadWorker::ThreadWorker ( ThreadBase threadbase)

Constructor.

In the constructor the parameters are reset to default values, namely, an empty thread name, normal execution priority, and a timer interval of one second.

Parameters
threadbase: Pointer back to the ThreadBase instance

Definition at line 42 of file threadworker.cpp.

Member Function Documentation

QString ThreadWorker::getThreadName ( ) const

Helper function for debugging: Get the current thread id and time.

Returns
Name of the thread in a readable format. This name is the actual name of the thread. It may differ from the name that was assigned via setThreadName(),
Note
This feature works only on Linux systems, it is inactive on other platforms

Definition at line 244 of file threadworker.cpp.

int Log::getVerbosity ( )
inherited

Get the actual verbosity level.

Returns
: Verbosity level (1...4)

Definition at line 118 of file log.cpp.

void ThreadWorker::run ( )
finaloverrideprivatevirtual

Private thread worker function, starting execution loop.

After creation the new thread executes this function. First the timer is created. If the thread is in the suspended mode it simply waits. Otherwise the timer and the execution loop are started.

Definition at line 176 of file threadworker.cpp.

Here is the call graph for this function:

void ThreadWorker::setCurrentThreadName ( QString  threadname)
private

Helper function for debugging: set the current thread name.

Parameters
threadname: QString holding the name of the thread
Note
This function works only on Linux systems, it is inactive on other platforms

Definition at line 220 of file threadworker.cpp.

Here is the call graph for this function:

void ThreadWorker::setPriority ( const QThread::Priority  priority)

Specify the priority of the thread.

Can be used at any time, no matter whether the thread is running.

Parameters
priority: Qt priority level
See also
http://doc.qt.io/qt-5.7/qthread.html#Priority-enum

Definition at line 63 of file threadworker.cpp.

void ThreadWorker::setThreadName ( const QString  name)

Set thread name.

Parameters
name: Name to be assigned to the thread
Note
: Threads can only be named under Linux

Definition at line 101 of file threadworker.cpp.

Here is the call graph for this function:

void ThreadWorker::setTimerInterval ( const int  msec,
const int  firstMsec 
)

Set timer interval in milliseconds.

Set the timer interval at which the PeriodicallyCalledWorkerFunctiion() will be called. Has to be called before the thread starts.

Parameters
msec: Periodic waiting time in milliseconds
firstMsec: First waiting time in milliseconds

Definition at line 82 of file threadworker.cpp.

void Log::setVerbosity ( int  verbosity)
inherited

Set the verbosity level of the class-specific messages.

Parameters
verbosity: Verbosity level (1...4)

Definition at line 107 of file log.cpp.

bool ThreadWorker::start ( )

Start thread and move base class to the new thread.

After starting the thread the instance of the base class of type ThreadBase is moved to the thread of ThreadWorker. This ensures that all slots of the base class and its derived classes are executed in the new thread.

Returns
True on success

Definition at line 121 of file threadworker.cpp.

Here is the call graph for this function:

void ThreadWorker::startTimer ( )
signal

Helper signal for starting the temporarily existing timer.

Since we want the timer to be executed in the new thread its instance is created temporarily from the new thread. Therefore, the slots of the timer are not always existing. This signal is simply forwarded to the timer slot.

bool ThreadWorker::stop ( )

Send a request to the thread for termination.

This function requests the thread to terminate. The user has to make sure that the implementation stops as soon as isInterruptionRequested() becomes true. The calling thread waits up to two seconds for the thread to terminate. If the thread terminates before the function returns true, otherwise it returns false.

Returns
True if thread stopped regularly, False if thread is still running after a timeout of two seconds.

Definition at line 158 of file threadworker.cpp.

void ThreadWorker::stopTimer ( )
signal

Helper signal for stopping the temporarily existing timer.

Since we want the timer to be executed in the new thread its instance is created temporarily from the new thread. Therefore, the slots of the timer are not always existing. This signal is simply forwarded to the timer slot.

Member Data Documentation

int ThreadWorker::mFirstInterval
private

Assigned periodic waiting time in milliseconds.

Definition at line 80 of file threadworker.h.

int ThreadWorker::mInterval
private

Definition at line 80 of file threadworker.h.

QThread::Priority ThreadWorker::mPriority
private

Assigned priority of the thread.

Definition at line 79 of file threadworker.h.

QString ThreadWorker::mThreadName
private

Assigned thread name.

Definition at line 78 of file threadworker.h.

ThreadBase* ThreadWorker::pThreadBase
private

Pointer back to the instance of the ThreadBase.

Definition at line 77 of file threadworker.h.


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