QGpCoreTools/Thread.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of QGpCoreTools.
00004 **
00005 **  This library is free software; you can redistribute it and/or
00006 **  modify it under the terms of the GNU Lesser General Public
00007 **  License as published by the Free Software Foundation; either
00008 **  version 2.1 of the License, or (at your option) any later version.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00013 **  License for more details.
00014 **
00015 **  You should have received a copy of the GNU Lesser General Public
00016 **  License along with this library; if not, write to the Free Software
00017 **  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 **
00019 **  See http://www.geopsy.org for more information.
00020 **
00021 **  Created : 2007-12-26
00022 **  Authors :
00023 **    Marc Wathelet
00024 **    Marc Wathelet (LGIT, Grenoble, France)
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 } // namespace QGpCoreTools
00082 
00083 #endif // THREAD_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines