]> git.mxchange.org Git - simgear.git/blobdiff - simgear/threads/SGThread.cxx
Merge branch 'next' of git://gitorious.org/fg/simgear into next
[simgear.git] / simgear / threads / SGThread.cxx
index f7de11f7dfb69ffc4b4def88ad3e5cb3d0bcfe45..c7a841b02bb9d8b0ddb3dadbf3621baca0812ca5 100644 (file)
@@ -1,10 +1,18 @@
 #include <simgear/compiler.h>
 
-#ifdef _MSC_VER
+#if defined(_MSC_VER) || defined(__MINGW32__)
 #  include <time.h>
 #else
+#  if defined ( sgi ) && !defined( __GNUC__ )
+     // This works around a bug triggered when using MipsPro 7.4.1
+     // and (at least) IRIX 6.5.20
+#    include <iostream>
+#  endif
 #  include <sys/time.h>
 #endif
+#if _MSC_VER >= 1300
+#  include <winsock2.h>
+#endif
 
 #include "SGThread.hxx"
 
@@ -49,8 +57,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 );