Update Mapgen VoxelManipulator on buffer invalidation
[oweals/minetest.git] / src / jthread / jmutex.h
index 39bd95f02281318aaad2b557d1feabb67da74fd6..e57cd8a435f14217b53d4b371bde40a8890cb3d6 100644 (file)
 #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
        #include <winsock2.h>
        #include <windows.h>
-       
+       // CriticalSection is way faster than the alternative
        #define JMUTEX_CRITICALSECTION
 #else // using pthread
        #include <pthread.h>
@@ -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,8 +65,15 @@ private:
 #endif // JMUTEX_CRITICALSECTION
 #else // pthread mutex
        pthread_mutex_t mutex;
+
+       bool IsLocked() {
+               if (pthread_mutex_trylock(&mutex)) {
+                       pthread_mutex_unlock(&mutex);
+                       return true;
+               }
+               return false;
+       }
 #endif // WIN32
-       bool initialized;
 };
 
 #endif // JMUTEX_H