Browse Source

deps-libff: Fix bug where rel time was used instead of abs

The bug was undetected because it accidentally fell into an error case that slept the correct amount of time.  pthread_cond_timedwait takes an absolute time in the future to wait until.  The value we were passing was always in the past so it was immediately failing with a TIMEDOUT error code.
John Bradley 10 years ago
parent
commit
de574e99e3
1 changed files with 7 additions and 9 deletions
  1. 7 9
      deps/libff/libff/ff-timer.c

+ 7 - 9
deps/libff/libff/ff-timer.c

@@ -36,20 +36,18 @@ static void *timer_thread(void *opaque)
 
 		uint64_t current_time = av_gettime();
 		if (current_time < timer->next_wake) {
-			int64_t sleep_time_us = timer->next_wake - current_time;
-
-			struct timespec sleep_time;
-			sleep_time.tv_sec =
-					(long)sleep_time_us / AV_TIME_BASE;
-			sleep_time.tv_nsec =
-					(long)(sleep_time_us % AV_TIME_BASE)
-							* 1000;
+			struct timespec sleep_time = {
+				.tv_sec = timer->next_wake / AV_TIME_BASE,
+				.tv_nsec = (timer->next_wake % AV_TIME_BASE)
+						* 1000
+			};
 
 			ret = pthread_cond_timedwait(&timer->cond,
 					&timer->mutex, &sleep_time);
 			if (ret != 0) {
 				// failed to wait, just sleep
-				av_usleep((unsigned)sleep_time_us);
+				av_usleep((unsigned)(timer->next_wake
+						- current_time));
 			}
 
 			// we can be woken up merely to set a sooner wake time