41 #ifndef _btsthread_cpp
42 #define _btsthread_cpp
77 #if defined(_MEZZ_THREAD_POSIX_)
95 #if defined(_MEZZ_THREAD_POSIX_)
101 static ThreadId _pthread_t_to_ID(
const pthread_t &aHandle)
103 static Mutex idMapLock;
104 static std::map<pthread_t, unsigned long int> idMap;
105 static unsigned long int idCount(1);
107 lock_guard<Mutex> guard(idMapLock);
108 if(idMap.find(aHandle) == idMap.end())
109 idMap[aHandle] = idCount ++;
110 return ThreadId(idMap[aHandle]);
112 #endif // _MEZZ_POSIX_
127 #if defined(_MEZZ_THREAD_WIN32_)
128 unsigned WINAPI Thread::wrapper_function(
void * aArg)
129 #elif defined(_MEZZ_THREAD_POSIX_)
130 void * Thread::wrapper_function(
void * aArg)
149 lock_guard<Mutex> guard(ti->
mThread->mDataMutex);
150 ti->
mThread->mNotAThread =
true;
175 #if defined(_MEZZ_THREAD_WIN32_)
176 mHandle = (HANDLE) _beginthreadex(0, 0, wrapper_function, (
void *) ti, 0, &mWin32ThreadID);
177 #elif defined(_MEZZ_THREAD_POSIX_)
178 if(pthread_create(&mHandle, NULL, wrapper_function, (
void *) ti) != 0)
206 #if defined(_MEZZ_THREAD_WIN32_)
207 mHandle = (HANDLE) _beginthreadex(0, 0, wrapper_function, (
void *) ti, 0, &mWin32ThreadID);
208 #elif defined(_MEZZ_THREAD_POSIX_)
209 if(pthread_create(&mHandle, NULL, wrapper_function, (
void *) ti) != 0)
231 #if defined(_MEZZ_THREAD_WIN32_)
232 WaitForSingleObject(mHandle, INFINITE);
233 CloseHandle(mHandle);
234 #elif defined(_MEZZ_THREAD_POSIX_)
235 pthread_join(mHandle, NULL);
243 bool result = !mNotAThread;
253 #if defined(_MEZZ_THREAD_WIN32_)
254 CloseHandle(mHandle);
255 #elif defined(_TTHREAD_POSIX_)
256 pthread_detach(mHandle);
267 #if defined(_MEZZ_THREAD_WIN32_)
268 return ThreadId((
unsigned long int) mWin32ThreadID);
269 #elif defined(_MEZZ_THREAD_POSIX_)
270 return _pthread_t_to_ID(mHandle);
276 #if defined(_MEZZ_THREAD_WIN32_)
279 return (
int) si.dwNumberOfProcessors;
280 #elif defined(_SC_NPROCESSORS_ONLN)
281 return (
int) sysconf(_SC_NPROCESSORS_ONLN);
282 #elif defined(_SC_NPROC_ONLN)
283 return (
int) sysconf(_SC_NPROC_ONLN);
298 #if defined(_MEZZ_THREAD_WIN32_)
299 return ThreadId((
unsigned long int) GetCurrentThreadId());
300 #elif defined(_MEZZ_THREAD_POSIX_)
301 return _pthread_t_to_ID(pthread_self());
307 #if defined(_MEZZ_THREAD_WIN32_)
316 #if defined(_MEZZ_THREAD_WIN32_)
317 Sleep(MicroSeconds/1000);
319 usleep(MicroSeconds);