digiKam Developer Documentation: Digikam::DynamicThread Class Reference

| digiKam Developer Documentation Professional Photo Management with the Power of Open Source

Loading...
Searching...
No Matches
Public Types | Public Slots | Signals | Public Member Functions | Protected Member Functions | List of all members
Digikam::DynamicThread Class Referenceabstract
Inheritance diagram for Digikam::DynamicThread:

## Public Types
enum | State { Inactive , Scheduled , Running , Deactivating }

## Public Slots
void | start ()
void | stop ()
| Stop computation, sets the running flag to false.
void | wait ()
| Waits until the thread finishes.

## Signals
void | finished ()
void | starting ()
| Emitted if emitSignals is enabled.

## Public Member Functions
| DynamicThread (QObject *const parent=nullptr)
| This class extends QRunnable, so you have to reimplement virtual void run().
| ~DynamicThread () override
| The destructor calls stop() and wait(), but if you, in your destructor, delete any data that is accessed by your run() method, you must call stop() and wait() before yourself.
bool | isFinished () const
bool | isRunning () const
QThread::Priority | priority () const
virtual void | run ()=0
| Implement this pure virtual function in your subclass.
void | setEmitSignals (bool emitThem)
void | setPriority (QThread::Priority priority)
| Sets the priority for this dynamic thread.
State | state () const

## Protected Member Functions
bool | runningFlag () const volatile
| In you run() method, you shall regularly check for runningFlag() and cleanup and return if false.
virtual void | shutDown ()
| If you are deleting data in your destructor which is accessed from the thread, do one of the following from your destructor to guarantee a safe shutdown: 1) Call this method 2) Call stop() and wait(), knowing that nothing will call start() anymore after this 3) Be sure the thread will never be running at destruction.
void | start (QMutexLocker< QMutex > &locker)
| Doing the same as start(), stop() and wait above, provide it with a locked QMutexLocker on mutex().
void | stop (const QMutexLocker< QMutex > &locker)
QMutex * | threadMutex () const
| This is the non-recursive mutex used to protect state variables and waiting in this class.
void | wait (QMutexLocker< QMutex > &locker)

## Constructor & Destructor Documentation

## ◆ DynamicThread()

Digikam::DynamicThread::DynamicThread | ( | QObject *const | parent = `nullptr` | ) |
| explicit

In all aspects the class will act similar to a QThread.

## Member Function Documentation

## ◆ run()

virtual void Digikam::DynamicThread::run | ( |  | ) |
| pure virtual

Implemented in Digikam::DImgThreadedFilter, Digikam::ImageHistogram, and Digikam::LoadSaveThread.

## ◆ setPriority()

void Digikam::DynamicThread::setPriority | ( | QThread::Priority | priority | ) |

Can be set anytime. If the thread is currently not running, the priority will be set when it is run next time. When you set QThread::InheritPriority (default), the priority is not changed but inherited from the thread pool.

## ◆ shutDown()

void Digikam::DynamicThread::shutDown | ( |  | ) |
| protectedvirtual

Note
  This irrevocably stops this object.
  It is not sufficient that your parent class does this. Calling this method, or providing one of the above mentioned equivalent guarantees, must be done by every single last class in the hierarchy with an implemented destructor deleting data. (the base class destructor is always called after the derived class)

Reimplemented in Digikam::ManagedLoadSaveThread.

## ◆ start()

void Digikam::DynamicThread::start | ( | QMutexLocker< QMutex > & | locker | ) |
| protected

Note the start() will unlock and relock for scheduling once, after state change.

## ◆ threadMutex()

QMutex * Digikam::DynamicThread::threadMutex | ( |  | ) | const
| protected

You can use it if you want to protect your memory in the same scope as calling start, stop or wait, then using the QMutexLocker variants below. Note that when you have locked this mutex, you must use these variants, as the mutex is non-recursive.

## ◆ wait

void Digikam::DynamicThread::wait | ( |  | ) |
| slot

Typically, call stop() before.