21 #ifndef UCRITICAL_SECTION_H
22 #define UCRITICAL_SECTION_H
25 #ifndef WIN32_LEAN_AND_MEAN
26 #define WIN32_LEAN_AND_MEAN
31 #include <semaphore.h>
36 namespace OpenSkyNet {
42 inline LockableCS()
throw() { InitializeCriticalSection(&_cS); }
43 inline ~LockableCS()
throw() { DeleteCriticalSection(&_cS); }
45 inline void lock()
throw() { EnterCriticalSection(&_cS); }
46 inline void unlock()
throw() { LeaveCriticalSection(&_cS); }
50 pthread_mutexattr_t mutexAttr;
51 pthread_mutexattr_settype(&mutexAttr,PTHREAD_MUTEX_RECURSIVE_NP);
52 pthread_mutex_init(&_cS,&mutexAttr);
53 pthread_mutexattr_destroy(&mutexAttr);
57 inline void lock() throw() { pthread_mutex_lock(&_cS); }
58 inline void unlock() throw() { pthread_mutex_unlock(&_cS); }
71 inline SyncEvent()
throw() { _event = CreateEvent(NULL,FALSE,FALSE,NULL); }
72 inline ~SyncEvent()
throw() { CloseHandle(_event); }
74 inline void set()
throw() { SetEvent(_event); }
75 inline void wait()
throw() { WaitForSingleObject(_event,INFINITE); }
79 int error = sem_init(&_event,0,0);
83 int error = sem_destroy(&_event);
87 inline void set() throw() {
89 int error = sem_getvalue(&_event,&val);
94 error = sem_post(&_event);
98 inline void wait() throw() {
99 int error = sem_wait(&_event);
116 void create(LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter) {
118 _hThread = CreateThread(
129 WaitForSingleObject(_hThread, INFINITE);
134 if (CloseHandle(_hThread))
140 void create(
void* (*start_address)(
void*),
void* arg) {
142 pthread_attr_init(&_threadAttr);
144 pthread_attr_setstacksize(&_threadAttr, 1048576);
146 pthread_create(&_thread, &_threadAttr, start_address, arg);
151 pthread_join(_thread, NULL);
156 if (!pthread_attr_destroy(&_threadAttr))
165 pthread_attr_t _threadAttr;
171 #endif //UCRITICAL_SECTION_H
void set()
Definition: UThread.h:87
void unlock()
Definition: UThread.h:58
LockableCS()
Definition: UThread.h:49
SyncEvent()
Definition: UThread.h:78
void wait()
Definition: UThread.h:98
Definition: UThread.h:111
Thread()
Definition: UThread.h:138
void wait()
Definition: UThread.h:149
void lock()
Definition: UThread.h:57
void create(void *(*start_address)(void *), void *arg)
Definition: UThread.h:140
~LockableCS()
Definition: UThread.h:55
void close()
Definition: UThread.h:154
~SyncEvent()
Definition: UThread.h:82