[Box Backup-commit] COMMIT r2648 - box/trunk/lib/common

subversion at boxbackup.org subversion at boxbackup.org
Sun Feb 28 19:51:28 GMT 2010


Author: chris
Date: 2010-02-28 19:51:26 +0000 (Sun, 28 Feb 2010)
New Revision: 2648

Modified:
   box/trunk/lib/common/Test.cpp
Log:
Workaround for problem with nanosleep() return values on OSX causing test
to hang.


Modified: box/trunk/lib/common/Test.cpp
===================================================================
--- box/trunk/lib/common/Test.cpp	2010-02-28 16:31:27 UTC (rev 2647)
+++ box/trunk/lib/common/Test.cpp	2010-02-28 19:51:26 UTC (rev 2648)
@@ -462,10 +462,24 @@
 	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
 }




More information about the Boxbackup-commit mailing list