]> git.mxchange.org Git - simgear.git/blobdiff - simgear/threads/SGThread.cxx
cygwin and mingw fixes
[simgear.git] / simgear / threads / SGThread.cxx
index b3bb8ab2eb79d8e98a2c28695936337f788d4c59..c6d016a0fece9ddac942a585459459c50fe01376 100644 (file)
@@ -1,9 +1,10 @@
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
 #include <simgear/compiler.h>
-#include <sys/time.h>
+
+#if defined(_MSC_VER) || defined(__MINGW32__)
+#  include <time.h>
+#else
+#  include <sys/time.h>
+#endif
 
 #include "SGThread.hxx"
 
@@ -48,8 +49,33 @@ SGMutex::trylock()
     return true;
 }
 
+#if defined(_MSC_VER) || defined(__MINGW32__)
+int gettimeofday(struct timeval* tp, void* tzp) {
+    LARGE_INTEGER t;
+
+    if(QueryPerformanceCounter(&t)) {
+        /* hardware supports a performance counter */
+        LARGE_INTEGER f;
+        QueryPerformanceFrequency(&f);
+        tp->tv_sec = t.QuadPart/f.QuadPart;
+        tp->tv_usec = ((float)t.QuadPart/f.QuadPart*1000*1000)
+            - (tp->tv_sec*1000*1000);
+    } else {
+        /* hardware doesn't support a performance counter, so get the
+           time in a more traditional way. */
+        DWORD t;
+        t = timeGetTime();
+        tp->tv_sec = t / 1000;
+        tp->tv_usec = t % 1000;
+    }
+
+    /* 0 indicates that the call succeeded. */
+    return 0;
+}
+#endif
+
 bool
-SGCondition::wait( SGMutex& mutex, unsigned long ms )
+SGPthreadCond::wait( SGMutex& mutex, unsigned long ms )
 {
     struct timeval now;
     ::gettimeofday( &now, 0 );