Browse Source

fix problem with pthread_cond_timedwait

David Rose 16 years ago
parent
commit
31f2ce467d

+ 4 - 3
direct/src/plugin/p3dConditionVar.cxx

@@ -138,14 +138,15 @@ wait(double timeout) {
   int seconds = (int)floor(timeout);
   ts.tv_sec += seconds;
   ts.tv_nsec += (int)((timeout - seconds) * 1000000.0);
+  if (ts.tv_nsec > 1000000) {
+    ts.tv_nsec -= 1000000;
+    ++ts.tv_sec;
+  }
 
   int result = pthread_cond_timedwait(&_cvar, &_lock, &ts);
   if (result != 0 && result != ETIMEDOUT) {
     errno = result;
     perror("pthread_cond_timedwait");
-    // TODO: investigate why we sometimes get an "Invalid Value" or
-    // some such here.
-    //    assert(false);
   }
 
 #endif  // _WIN32

+ 4 - 0
panda/src/pipeline/conditionVarPosixImpl.cxx

@@ -39,6 +39,10 @@ wait(double timeout) {
   int seconds = (int)floor(timeout);
   ts.tv_sec += seconds;
   ts.tv_nsec += (int)((timeout - seconds) * 1000000.0);
+  if (ts.tv_nsec > 1000000) {
+    ts.tv_nsec -= 1000000;
+    ++ts.tv_sec;
+  }
 
   int result = pthread_cond_timedwait(&_cvar, &_mutex._lock, &ts);
 #ifndef NDEBUG