]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/jthread/jmutex.h
Fix building under MSVC
[dragonfireclient.git] / src / jthread / jmutex.h
index 6675162a56b6070efdc22e3b021f5c20aa6d3f94..e57cd8a435f14217b53d4b371bde40a8890cb3d6 100644 (file)
@@ -30,6 +30,9 @@
 #define JMUTEX_H
 
 #if (defined(WIN32) || defined(_WIN32_WCE))
+       #ifndef _WIN32_WINNT
+               #define _WIN32_WINNT 0x0501
+       #endif
        #ifndef _WIN32_WCE
                #include <process.h>
        #endif // _WIN32_WCE
@@ -50,10 +53,9 @@ class JMutex
 public:
        JMutex();
        ~JMutex();
-       int Init();
        int Lock();
        int Unlock();
-       bool IsInitialized()                                            { return initialized; }
+
 private:
 #if (defined(WIN32) || defined(_WIN32_WCE))
 #ifdef JMUTEX_CRITICALSECTION
@@ -63,58 +65,15 @@ class JMutex
 #endif // JMUTEX_CRITICALSECTION
 #else // pthread mutex
        pthread_mutex_t mutex;
-#endif // WIN32
-       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);
+       bool IsLocked() {
+               if (pthread_mutex_trylock(&mutex)) {
+                       pthread_mutex_unlock(&mutex);
+                       return true;
+               }
+               return false;
        }
+#endif // WIN32
 };
 
-#endif
-
 #endif // JMUTEX_H