From 03a71287fa2f4ef79b59ecbdbb1fd47d51240c66 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 28 Feb 2010 19:51:26 +0000 Subject: Workaround for problem with nanosleep() return values on OSX causing test to hang. --- lib/common/Test.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/common/Test.cpp b/lib/common/Test.cpp index 787cf0a2..b1cbb5a9 100644 --- a/lib/common/Test.cpp +++ b/lib/common/Test.cpp @@ -462,10 +462,24 @@ void safe_sleep(int seconds) ts.tv_nsec = 0; while (nanosleep(&ts, &ts) == -1 && errno == EINTR) { - BOX_TRACE("safe_sleep interrupted with " << - ts.tv_sec << "." << ts.tv_nsec << - " secs remaining, sleeping again"); - /* sleep again */ + // FIME evil hack for OSX, where ts.tv_sec contains + // a negative number interpreted as unsigned 32-bit + // when nanosleep() returns later than expected. + + int32_t secs = (int32_t) ts.tv_sec; + int64_t remain_ns = (secs * 1000000000) + ts.tv_nsec; + + if (remain_ns < 0) + { + BOX_WARNING("nanosleep interrupted " << + ((float)(0 - remain_ns) / 1000000000) << + " secs late"); + return; + } + + BOX_TRACE("nanosleep interrupted with " << + (remain_ns / 1000000000) << " secs remaining, " + "sleeping again"); } #endif } -- cgit v1.2.3