24 #ifndef _GEMA_THREAD_MANAGER_H_ 25 #define _GEMA_THREAD_MANAGER_H_ 32 #include <QWaitCondition> 42 template <
class T,
bool Align>
class GmTLS;
51 #define GmThreadLocal __declspec(thread) 53 #define GmThreadLocal __thread 102 LuaEnv* threadLuaEnv(
int tid)
const;
106 void execTasks(
int nthreads);
121 int numTasks()
const;
156 static int maxProcThreads() { assert(_maxProcThreads > 0);
return _maxProcThreads; }
159 static int numProcCores() { assert(_numProcCores > 0);
return _numProcCores; }
174 int clearTaskQueues();
175 int numTasksInQueues()
const;
226 int id()
const {
return _tid; }
245 bool wait(
unsigned long time = ULONG_MAX);
Our thread wrapper, specialized for running tasks from the thread manager queue.
Definition: gmThreadManager.h:217
bool _abortRequested
Flag for aborting tasks due to another task failure.
Definition: gmThreadManager.h:198
bool cancelRequested() const
Do we have a pending request to cancel the simulation?
Definition: gmThreadManager.h:124
virtual ~GmThreadTask()
Virtual destructor.
Definition: gmThreadManager.h:75
#define GmThreadLocal
Macro used to declare that a global / static variable has a per thread value (Thread Local Storage)
Definition: gmThreadManager.h:53
GmTLS< LuaEnv *, false > * _luaEnv
The per thread Lua environment. Must be a pointer to avoid include order problems with GmTLS.
Definition: gmThreadManager.h:205
GmTLS< GmTaskQueue, false > * _taskQueues
The task queues. Queue 0 is a global queue shared by all threads, while other queues can be used to m...
Definition: gmThreadManager.h:190
const GmLogCategory & logger()
Returns the thread manager logger.
Definition: gmThreadManager.h:147
LuaEnv * luaEnv() const
Returns the Lua environment associated with this thread.
Definition: gmThreadManager.h:238
Declaration of usefull configuration definitions for the Core library.
static int _numProcCores
The number of processor cores (physical processors - no hyper threading)
Definition: gmThreadManager.h:186
GmThreadTaskResult
Possible results for running a task.
Definition: gmThreadManager.h:60
The thread finished its execution without errors.
Definition: gmThreadManager.h:62
static int numProcCores()
Returns the number of processor cores (physical processors - no hyper threading)
Definition: gmThreadManager.h:159
int _active
Flag for controlling if runTasks is active, and how many threads should be used (prevents a thread to...
Definition: gmThreadManager.h:196
int _numTasks
The number of task added to the queues before runTasks()
Definition: gmThreadManager.h:191
A class that works together with GmThreadManager to provide thread local storage.
Definition: gmThreadLocalStorage.h:131
bool cancelPending() const
Do we have a pending request to cancel this thread work or any other thread has aborted?
Definition: gmThreadManager.h:235
void start(QThread::Priority priority)
Auxiliar class used to store the complete set of simulation data.
Definition: gmSimulationData.h:51
GmThreadManager * threadManager() const
Returns a pointer to the thread manager.
Definition: gmThreadManager.h:229
GmLogCategory _logger
Basic logger object for thread manager messages.
Definition: gmThreadManager.h:203
int _maxAffinityId
The biggest tid requested in a call to addTask()
Definition: gmThreadManager.h:194
bool _cancelRequested
Flag for thread cancelation due to an external request / thread manager deletion.
Definition: gmThreadManager.h:197
QVector< int > _taskAffinity
The vector storing the id of the thread used to execute each task.
Definition: gmThreadManager.h:193
QThread * thread() const
Returns the pointer to the associated Qt thread.
Definition: gmThreadManager.h:232
int _npendingTasks
The number of still pending tasks.
Definition: gmThreadManager.h:192
The thread aborted.
Definition: gmThreadManager.h:64
QMutex _taskMutex
The mutex controlling access to thread tasks.
Definition: gmThreadManager.h:200
static int currentId()
Returns the id of the current thread, which MUST be either the main thread or a thread created by the...
Definition: gmThreadManager.h:166
QWaitCondition _idleCond
The condition variable used to wake up a thread waiting for jobs.
Definition: gmThreadManager.h:251
Interface for a task executed by a thread manager thread.
Definition: gmThreadManager.h:68
bool cancelPending() const
Do we have a pending request to cancel the simulation or any other thread has aborted?
Definition: gmThreadManager.h:127
GmThreadLocal int GmThreadManagerThreadId
Local storage for thread ids. More efficient than using QThread::currentThread() for then accessing t...
Definition: gmThreadManager.cpp:50
QQueue< GmThreadTask * > GmTaskQueue
Type for a task queue.
Definition: gmThreadManager.h:182
void setTaskIndex(int index)
Updates the task index inside the task manager for this task.
Definition: gmThreadManager.h:86
GmThread * _mainThread
A pointer to a GmThread wrapper for the main thread.
Definition: gmThreadManager.h:188
#define GMC_API_EXPORT
Macro for controling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_LI...
Definition: gmCoreConfig.h:35
QThread * _thread
The thread.
Definition: gmThreadManager.h:249
GmLogLevel
Available log levels list.
Definition: gmLog.h:36
bool wait(unsigned long time)
Class representing a category with multiple logging levels.
Definition: gmLog.h:58
static bool inMainThread()
Is the current thread the main thread? Equivalent to comparing the currentId() with 0.
Definition: gmThreadManager.h:169
int id() const
Returns the thread id (a value between 1 and the maximum number of threads)
Definition: gmThreadManager.h:226
int _tid
Our thread id.
Definition: gmThreadManager.h:248
int taskIndex() const
Returns the task index (the order in which the task was added to the thread manager)
Definition: gmThreadManager.h:83
Thread manager used for handling parallel executions.
Definition: gmThreadManager.h:94
GmThreadTask()
Default constructor. Task index MUST be set by a call to setTaskIndex()
Definition: gmThreadManager.h:72
void setCancelFlag(bool mode=true)
Informs the thread manager that the user wants to cancel the simulation. Can be called from the serve...
Definition: gmThreadManager.h:144
GmThreadManager * _tm
The thread manager.
Definition: gmThreadManager.h:250
static int maxProcThreads()
Returns the maximum number of concurrent threads supported by the processor.
Definition: gmThreadManager.h:156
The internal thread class, inheriting from QThread, used for calling the GmThread::run() method.
Definition: gmThreadManager.cpp:53
const QVector< int > & taskAffinity() const
Returns a vector with size equal to the number of tasks executed in the last call to runTasks() stori...
Definition: gmThreadManager.h:119
static int _maxNumThreads
The maximum number of threads that can be used.
Definition: gmThreadManager.h:184
QWaitCondition _managerCond
The condition variable used to block the manager until tasks are finished.
Definition: gmThreadManager.h:201
QList< GmThread * > _threadList
A list with all the allocated threads.
Definition: gmThreadManager.h:189
The thread was externally canceled.
Definition: gmThreadManager.h:63
static int maxWorkerThreads()
Returns the maximum number of allowed working threads.
Definition: gmThreadManager.h:153
static int _maxProcThreads
The maximum number of supported concurrent threads (logical processors)
Definition: gmThreadManager.h:185
Declaration of support functions and macros for information logging.