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 #ifndef PTHREAD_H
00028 #define PTHREAD_H
00029
00030 #include <map>
00031 #include <list>
00032 #include <vector>
00033
00034 #include "Trace.h"
00035 #include "TraceBug.h"
00036 #include "EventLoop.h"
00037 #include "GpCoreToolsDLLExport.h"
00038
00039 namespace GpCoreTools {
00040
00041 class EventLoop;
00042
00043 class GPCORETOOLS_EXPORT PThread
00044 {
00045 public:
00046 PThread();
00047 virtual ~PThread() {}
00048
00049 void start();
00050 void stop();
00051 void wait();
00052 pthread_t id() const {return _id;}
00053
00054 void setEventLoop(EventLoop * l);
00055 EventLoop * eventLoop() const {return _eventLoop;}
00056
00057 static PThread * currentThread();
00058 static void init();
00059 static void lockThreads() {pthread_mutex_lock(&_threadsMutex);}
00060 static void unlockThreads() {pthread_mutex_unlock(&_threadsMutex);}
00061
00062 static std::list< std::vector<TraceBug *> * > bugStacks();
00063 std::vector<TraceBug *> * bugStack() {return &_bugStack;}
00064 #ifdef TRACE_ENABLED
00065 static std::list< std::vector<const TraceStamp *> * > stacks();
00066 std::vector<const TraceStamp *> * stack() {return &_stack;}
00067 #endif
00068 protected:
00069 virtual void run()=0;
00070 private:
00071 static void * run(void * arg);
00072
00073 pthread_t _id;
00074 static pthread_mutex_t _threadsMutex;
00075 static std::map<pthread_t, PThread *> _threads;
00076
00077 #ifdef TRACE_ENABLED
00078 std::vector<const TraceStamp *> _stack;
00079 #endif
00080 std::vector<TraceBug *> _bugStack;
00081 EventLoop * _eventLoop;
00082 };
00083
00084 }
00085
00086 #endif // PTHREAD_H