瀏覽代碼

Keep nsec within bounds.

Brucey 2 年之前
父節點
當前提交
ae3eedb95f
共有 1 個文件被更改,包括 7 次插入1 次删除
  1. 7 1
      threads.mod/threads.c

+ 7 - 1
threads.mod/threads.c

@@ -218,7 +218,13 @@ int threads_TimedWaitCond(pthread_cond_t *cond,bb_mutex_t *mutex, int millisecs)
 	}
 	}
 	
 	
 	ts.tv_sec += millisecs / 1000;
 	ts.tv_sec += millisecs / 1000;
-	ts.tv_nsec += (millisecs % 1000) * 1000000L;
+	BBInt64 nsec = ts.tv_nsec + ((millisecs % 1000) * 1000000L);
+	if (nsec <= 999999999L) {
+		ts.tv_nsec = nsec;
+	} else {
+		ts.tv_sec += 1;
+		ts.tv_nsec = nsec - 999999999L;
+	}
 
 
 	int res = pthread_cond_timedwait(cond, mutex, &ts);
 	int res = pthread_cond_timedwait(cond, mutex, &ts);