]> git.mxchange.org Git - simgear.git/commitdiff
OS-X specific sleep helper, more stable.
authorJames Turner <jmt@Bishop.local>
Sun, 23 Dec 2012 23:30:40 +0000 (23:30 +0000)
committerJames Turner <jmt@Bishop.local>
Sun, 23 Dec 2012 23:30:40 +0000 (23:30 +0000)
simgear/timing/timestamp.cxx

index 2189d643a8ec65c5313d2903ea6cbabd417982ce..297f665aebcbd055003e59e42952263fb978d9ae 100644 (file)
@@ -255,6 +255,24 @@ bool SGTimeStamp::sleepFor(const SGTimeStamp& reltime)
     // Don't know, but may be win32 has something better today??
     Sleep(static_cast<DWORD>(reltime.toMSecs()));
     return true;
+#elif defined __APPLE__
+    // the generic version below behaves badly on Mac; use nanosleep directly,
+    // similar to the POSIX timers version
+    struct timespec ts;
+    ts.tv_sec = reltime._sec;
+    ts.tv_nsec = reltime._nsec;
+    
+    for (;;) {
+        struct timespec rem;
+        int ret = nanosleep(&ts, &rem);
+        if (-1 == ret && errno != EINTR)
+            return false;
+        if (ret == 0)
+            break;
+        // Use the remainder for the next cycle.
+        ts = rem;
+    }
+    return true;
 #else
     SGTimeStamp abstime;
     abstime.stamp();