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
00029
00030
00031
00032
00033
00039 #ifndef BLOCXX_THREADIMPL_HPP_INCLUDE_GUARD_
00040 #define BLOCXX_THREADIMPL_HPP_INCLUDE_GUARD_
00041 #include "blocxx/BLOCXX_config.h"
00042 #include "blocxx/Types.hpp"
00043 #include "blocxx/ThreadTypes.hpp"
00044 #include "blocxx/Timeout.hpp"
00045
00046 #ifdef BLOCXX_NCR
00047 #ifndef PTHREAD_ONCE_INIT
00048 #define PTHREAD_ONCE_INIT pthread_once_init
00049 #endif
00050 #endif
00051
00052
00053
00054
00055
00056 namespace BLOCXX_NAMESPACE
00057 {
00058
00059
00060
00061
00062 #define BLOCXX_THREAD_FLG_JOINABLE 0x000000001
00063 typedef Int32 (*ThreadFunction)(void*);
00070 namespace ThreadImpl
00071 {
00083 BLOCXX_COMMON_API int createThread(Thread_t& handle, ThreadFunction func,
00084 void* funcParm, UInt32 threadFlags);
00090 BLOCXX_COMMON_API void destroyThread(Thread_t& handle);
00097 inline bool sameThreads(const volatile Thread_t& handle1,
00098 const volatile Thread_t& handle2)
00099 {
00100 #if defined(BLOCXX_WIN32)
00101 return handle1 == handle2;
00102 #elif BLOCXX_USE_PTHREAD
00103 return pthread_equal(handle1, handle2);
00104 #endif
00105 }
00113 BLOCXX_COMMON_API void exitThread(Thread_t& handle, Int32 rval);
00117 inline Thread_t currentThread()
00118 {
00119 #if defined(BLOCXX_WIN32)
00120 return GetCurrentThreadId();
00121 #else
00122 return pthread_self();
00123 #endif
00124 }
00125
00126
00135 BLOCXX_COMMON_API UInt64 thread_t_ToUInt64(Thread_t thr);
00136
00145 BLOCXX_COMMON_API int setThreadDetached(Thread_t& handle);
00154 BLOCXX_COMMON_API int joinThread(Thread_t& handle, Int32& rval);
00159 BLOCXX_COMMON_API void yield();
00165 BLOCXX_COMMON_API void sleep(UInt32 milliSeconds);
00171 BLOCXX_COMMON_API void sleep(const Timeout& timeout);
00199 BLOCXX_COMMON_API void testCancel();
00200 BLOCXX_COMMON_API void saveThreadInTLS(void* pTheThread);
00201 BLOCXX_COMMON_API void sendSignalToThread(Thread_t threadID, int signo);
00202 BLOCXX_COMMON_API void cancel(Thread_t threadID);
00203 };
00204
00205 }
00206
00207 #endif