From: James Turner Date: Sun, 23 Dec 2012 23:30:40 +0000 (+0000) Subject: OS-X specific sleep helper, more stable. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a131f442477a11894169933755591674bb7ad5e9;p=simgear.git OS-X specific sleep helper, more stable. --- diff --git a/simgear/timing/timestamp.cxx b/simgear/timing/timestamp.cxx index 2189d643..297f665a 100644 --- a/simgear/timing/timestamp.cxx +++ b/simgear/timing/timestamp.cxx @@ -255,6 +255,24 @@ bool SGTimeStamp::sleepFor(const SGTimeStamp& reltime) // Don't know, but may be win32 has something better today?? Sleep(static_cast(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();