00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef PHX_THREAD_H
00013 #define PHX_THREAD_H
00014
00015 #include <Phx/PhxConfig.h>
00016 #include <Phx/PhxTypes.h>
00017
00018 namespace Phx {
00019 class Thread :public LockedPtrInterface<Thread> {
00020 class IdentifierClass;
00021 public:
00023 Thread(String name, void* (*callback)(void *),void* arg);
00025 ~Thread();
00026
00028 const String& name(void);
00029
00031 void kill(void);
00032
00036 void* join(long timeout);
00037
00038 typedef ValueType<IdentifierClass,uint64_t> Identifier;
00039
00040 static Identifier current() {
00041 #if defined( PHX_PLATFORM_WIN32 )
00042 return Identifier((uint64_t)pthread_self().p);
00043 #else
00044 return Identifier((uint64_t)pthread_self());
00045 #endif
00046 }
00047
00048 Identifier identifier() const {
00049 #if defined( PHX_PLATFORM_WIN32 )
00050 return( Identifier( (uint64_t)mThread.p ) );
00051 #else
00052 return Identifier((uint64_t)mThread);
00053 #endif
00054 }
00055
00056 private:
00057 static void* exec(void *threadPtr);
00058 void* exec(void);
00059
00060 String mName;
00061 pthread_t mThread;
00062 pthread_cond_t mCond;
00063 pthread_mutex_t mMutex;
00064 bool mRunning;
00065
00066 void *(*pCallback)(void *);
00067 void *pArg;
00068 void *mRet;
00069 };
00070 }
00071 ;
00072 #endif