Go to the documentation of this file.
53 #ifndef _SAG_CONNECTIVITY_THREADS_HPP_
54 #define _SAG_CONNECTIVITY_THREADS_HPP_
56 #if defined(_WIN32) || defined(__WIN32) || defined(WIN32)
67 #define SAG_MUTEX_LOCK(m) EnterCriticalSection(&m)
68 #define SAG_MUTEX_UNLOCK(m) LeaveCriticalSection(&m)
70 #define SAG_MUTEX_INIT(m) InitializeCriticalSection(&m)
72 #define SAG_MUTEX_DESTROY(m) DeleteCriticalSection(&m)
74 #define SAG_MUTEX_T CRITICAL_SECTION
78 #define SAG_SEMA_WAIT(s) WaitForSingleObject(s, INFINITE)
79 #define SAG_SEMA_POST(s) ReleaseSemaphore(s, 1, NULL)
81 #define SAG_SEMA_INIT(s) s = CreateSemaphore(NULL, 0, 0x7FFFFFFF, NULL)
83 #define SAG_SEMA_DESTROY(s) CloseHandle(s)
85 #define SAG_SEMA_T HANDLE
89 #define SAG_THREAD_CREATE(id, func, params) (!(id = (HANDLE)_beginthreadex(NULL, 0, func, params, 0, NULL)))
90 #define SAG_THREAD_JOIN(id) WaitForSingleObject(id, INFINITE)
92 #define SAG_THREAD_RETURN return 0;
94 #define SAG_THREAD_T HANDLE
96 #define SAG_THREAD_RET_T unsigned int __stdcall
104 #include <semaphore.h>
110 #define SAG_MUTEX_LOCK(m) pthread_mutex_lock(&m)
111 #define SAG_MUTEX_UNLOCK(m) pthread_mutex_unlock(&m)
113 #define SAG_MUTEX_INIT(m) pthread_mutex_init(&m, NULL)
115 #define SAG_MUTEX_DESTROY(m) pthread_mutex_destroy(&m)
117 #define SAG_MUTEX_T pthread_mutex_t
121 #define SAG_SEMA_WAIT(s) {while (sem_wait(&s));}
122 #define SAG_SEMA_POST(s) sem_post(&s)
124 #define SAG_SEMA_INIT(s) sem_init(&s, 0, 0)
126 #define SAG_SEMA_DESTROY(s) sem_destroy(&s)
128 #define SAG_SEMA_T sem_t
132 #define SAG_THREAD_CREATE(id, func, params) pthread_create(& id, NULL, func, params)
133 #define SAG_THREAD_JOIN(id) pthread_join(id, NULL)
135 #define SAG_THREAD_RETURN return NULL;
137 #define SAG_THREAD_T pthread_t
139 #define SAG_THREAD_RET_T void*
146 #endif // _SAG_CONNECTIVITY_THREADS_HPP_