ソースを参照

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_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);