summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2010-02-28 19:51:26 +0000
committerChris Wilson <chris+github@qwirx.com>2010-02-28 19:51:26 +0000
commit03a71287fa2f4ef79b59ecbdbb1fd47d51240c66 (patch)
tree834189e4d17d9e9aed1573219a55e30d192c52df
parent6189699f3ddec1409b1dbf3a045a595cf6ca629c (diff)
Workaround for problem with nanosleep() return values on OSX causing test
to hang.
-rw-r--r--lib/common/Test.cpp22
1 files 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
}