5 #ifndef __LOGOG_THREAD_HPP__
6 #define __LOGOG_THREAD_HPP__
10 #if defined(LOGOG_FLAVOR_WINDOWS)
14 typedef unsigned int (WINAPI * __logog_pThreadFn)(
void *);
24 #define LOGOG_THREAD HANDLE
26 #define LOGOG_THREAD_CREATE(handle, attr, pStartFn, arg) \
27 (int)((*handle=(HANDLE) _beginthreadex (NULL, \
29 (__logog_pThreadFn)pStartFn, \
34 #define LOGOG_THREAD_JOIN( thread ) \
35 ( (WaitForSingleObject(( thread ),INFINITE)!=WAIT_OBJECT_0) \
36 || !CloseHandle(thread) \
38 #define LOGOG_THREAD_SELF (LOGOG_THREAD)((size_t)GetCurrentThreadId())
40 #endif // defined(LOGOG_FLAVOR_WINDOWS)
42 #if defined(LOGOG_FLAVOR_POSIX)
44 #define LOGOG_THREAD \
47 #define LOGOG_THREAD_CREATE(handle, attr, pStartFn, arg) \
48 pthread_create(handle, attr, pStartFn, arg)
50 #define LOGOG_THREAD_JOIN(thread) \
51 pthread_join(thread, NULL)
53 #define LOGOG_THREAD_SELF \
58 #endif // LOGOG_THREAD
61 #error You need to define mutex macros for your platform; please see mutex.hpp
75 typedef void* (*ThreadStartLocationType)(
void *);
80 m_pFnThreadStart = fnThreadStart;
81 m_pvThreadParams = pvParams;
87 return LOGOG_THREAD_CREATE(&m_Thread, NULL, m_pFnThreadStart, m_pvThreadParams);
95 return LOGOG_THREAD_JOIN(thread.m_Thread);
98 #ifdef LOGOG_THREAD_JOIN_SUPPORT
99 static void Join(
const std::vector<Thread*>& threads)
101 for(
size_t i=0; i<threads.size(); i++)
105 static void Delete(std::vector<Thread*>& threads)
107 for(
size_t i=0; i<threads.size(); i++)
108 delete threads.at(i);
111 #endif // LOGOG_THREAD_JOIN_SUPPORT
116 return (LOGOG_THREAD) LOGOG_THREAD_SELF ;
121 LOGOG_THREAD m_Thread;
125 void* m_pvThreadParams;
129 #endif // __LOGOG_THREAD_HPP_
[Thread]
Definition: api.hpp:8
Definition: thread.hpp:70
static LOGOG_THREAD GetCurrent()
Definition: thread.hpp:114
void *(* ThreadStartLocationType)(void *)
Definition: thread.hpp:75
int Start()
Definition: thread.hpp:85
Thread(ThreadStartLocationType fnThreadStart, void *pvParams)
Definition: thread.hpp:78
static int WaitFor(const Thread &thread)
Definition: thread.hpp:93