diff options
Diffstat (limited to 'src/jthread/jmutex.h')
-rw-r--r-- | src/jthread/jmutex.h | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/jthread/jmutex.h b/src/jthread/jmutex.h index 9ce013096..e528aeb4a 100644 --- a/src/jthread/jmutex.h +++ b/src/jthread/jmutex.h @@ -30,6 +30,9 @@ #define JMUTEX_H #if (defined(WIN32) || defined(_WIN32_WCE)) + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0500 + #endif #ifndef _WIN32_WCE #include <process.h> #endif // _WIN32_WCE @@ -67,4 +70,54 @@ private: bool initialized; }; +#ifdef _WIN32 + +class Event { + HANDLE hEvent; + +public: + Event() { + hEvent = CreateEvent(NULL, 0, 0, NULL); + } + + ~Event() { + CloseHandle(hEvent); + } + + void wait() { + WaitForSingleObject(hEvent, INFINITE); + } + + void signal() { + SetEvent(hEvent); + } +}; + +#else + +#include <semaphore.h> + +class Event { + sem_t sem; + +public: + Event() { + sem_init(&sem, 0, 0); + } + + ~Event() { + sem_destroy(&sem); + } + + void wait() { + sem_wait(&sem); + } + + void signal() { + sem_post(&sem); + } +}; + +#endif + #endif // JMUTEX_H |