Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef THREAD_H
00029 #define THREAD_H
00030
00031
00032 #include "Trace.h"
00033 #include "TraceBug.h"
00034 #include "TraceLog.h"
00035 #include "QGpCoreToolsDLLExport.h"
00036
00037 namespace QGpCoreTools {
00038
00039 class QGPCORETOOLS_EXPORT Thread : public QThread
00040 {
00041 Q_OBJECT
00042 public:
00043 Thread(QObject * parent=0);
00044 ~Thread();
00045
00046 static QStringList threadNames();
00047 static void lockThreads() {_threadsMutex.lock();}
00048 static void unlockThreads() {_threadsMutex.unlock();}
00049
00050 static Thread * currentThread() {return static_cast<Thread *>(QThread::currentThread());}
00051 void start(QThread::Priority priority=QThread::InheritPriority);
00052 void startNoThread();
00053 static void sleep(unsigned long secs);
00054 static void msleep(unsigned long msecs);
00055 static void usleep(unsigned long usecs);
00056 void setSleeping(bool s) {_sleeping.fetchAndStoreOrdered(s);}
00057 bool sleeping() {return _sleeping.testAndSetOrdered(true, true);}
00058 static int idealThreadCount();
00059
00060 static QList< QStack<TraceBug *> * > bugStacks();
00061 QStack<TraceBug *> * bugStack() {return &_bugStack;}
00062 static QList< QVector<TraceLog *> * > logVectors();
00063 QVector<TraceLog *> * logVector() {return &_logVector;}
00064 #ifdef TRACE_ENABLED
00065 static QList< QStack<const TraceStamp *> * > stacks();
00066 QStack<const TraceStamp *> * stack() {return &_stack;}
00067 #endif
00068 private:
00069 static QMutex _threadsMutex;
00070 static QList<Thread *> _threads;
00071 static QSet<Thread *> _runningThreads;
00072 QAtomicInt _sleeping;
00073
00074 QStack<TraceBug *> _bugStack;
00075 QVector<TraceLog *> _logVector;
00076 #ifdef TRACE_ENABLED
00077 QStack<const TraceStamp *> _stack;
00078 #endif
00079 };
00080
00081 }
00082
00083 #endif // THREAD_H