GemaCoreLib
The GeMA Core library
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
GmThread Class Reference

Our thread wrapper, specialized for running tasks from the thread manager queue. More...

#include <gmThreadManager.h>

Collaboration diagram for GmThread:
Collaboration graph
[legend]

Public Member Functions

 GmThread (GmThreadManager *manager, int tid)
 Thread wrapper constructor for a worker thread. Creates the equivalent QThread object without starting it. More...
 
 GmThread (GmThreadManager *manager)
 Thread wrapper constructor for the main thread. Should be created FROM the main thread.
 
 ~GmThread ()
 Destructor. If the wrapper is not over the main thread, destroys it. Expects that the caller has already made sure that the wrapped thread is no longer running.
 
int id () const
 Returns the thread id (a value between 1 and the maximum number of threads)
 
GmThreadManagerthreadManager () const
 Returns a pointer to the thread manager.
 
QThreadthread () const
 Returns the pointer to the associated Qt thread.
 
bool cancelPending () const
 Do we have a pending request to cancel this thread work or any other thread has aborted?
 
LuaEnvluaEnv () const
 Returns the Lua environment associated with this thread.
 

Private Member Functions

void start ()
 Wrapper over QThread::start(). Should NOT be called over the main thead.
 
bool wait (unsigned long time=ULONG_MAX)
 Wrapper over QThread::wait(). Should NOT be called over the main thead.
 
void run ()
 Thread execution routine.
 

Private Attributes

int _tid
 Our thread id.
 
QThread_thread
 The thread.
 
GmThreadManager_tm
 The thread manager.
 
QWaitCondition _idleCond
 The condition variable used to wake up a thread waiting for jobs.
 

Friends

class GmThreadManager
 
class GmInternalThread
 

Detailed Description

Our thread wrapper, specialized for running tasks from the thread manager queue.

This class does not inherits directly from QThread in order to allow for wrapping the main application thread inside a GmThread. This in turn allows us to handle the single thread execution case, without threads, in an uniform way.

Constructor & Destructor Documentation

◆ GmThread()

GmThread::GmThread ( GmThreadManager manager,
int  tid 
)

Thread wrapper constructor for a worker thread. Creates the equivalent QThread object without starting it.

The given thread id must be unique and between 1 and the maximum number of threads.


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