BUG#: 8682
authorvenkat.puvvada <venkat.puvvada>
Thu, 7 Jan 2010 05:21:45 +0000 (05:21 +0000)
committervenkat.puvvada <venkat.puvvada>
Thu, 7 Jan 2010 05:21:45 +0000 (05:21 +0000)
TITLE: time_wait() implementation is incorrect for pthread semaphores
DESCRIPTION: Converted the milliseconds to seconds first and then to nanooseconds.

src/Pegasus/Common/Semaphore.cpp

index e7e0ff509cd5900399f315633919679f4b03e088..1877aa4396ac8855f90383f3ea72960874e18b6c 100644 (file)
@@ -181,7 +181,9 @@ Boolean Semaphore::time_wait(Uint32 milliseconds)
     struct timeval now = { 0, 0 };
     struct timespec waittime = { 0, 0 };
     gettimeofday(&now, NULL);
-    waittime.tv_sec = now.tv_sec;
+
+    waittime.tv_sec = now.tv_sec + (milliseconds / 1000);
+    milliseconds = milliseconds % 1000;
     waittime.tv_nsec = now.tv_usec + (milliseconds * 1000);     // microseconds
     waittime.tv_sec += (waittime.tv_nsec / 1000000);    // roll overflow into
     waittime.tv_nsec = (waittime.tv_nsec % 1000000);    // the "seconds" part