From a8176e9b8e9a21ba42f9d4e1937e035a5e4bfe26 Mon Sep 17 00:00:00 2001 From: hobbs Date: Thu, 29 Mar 2001 19:29:22 +0000 Subject: * unix/tclUnixThrd.c (Tcl_ConditionWait): fixed handling of timeout for threads (corrects excessive CPU usage issue for Tk on Unix in threaded Tcl environment). (ruppert) [Bug #411603] --- unix/tclUnixThrd.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/unix/tclUnixThrd.c b/unix/tclUnixThrd.c index bbbb3f2..faf08ed 100644 --- a/unix/tclUnixThrd.c +++ b/unix/tclUnixThrd.c @@ -681,8 +681,17 @@ Tcl_ConditionWait(condPtr, mutexPtr, timePtr) if (timePtr == NULL) { pthread_cond_wait(pcondPtr, pmutexPtr); } else { - ptime.tv_sec = timePtr->sec + TclpGetSeconds(); - ptime.tv_nsec = 1000 * timePtr->usec; + Tcl_Time now; + + /* + * Make sure to take into account the microsecond component of the + * current time, including possible overflow situations. [Bug #411603] + */ + + TclpGetTime(&now); + ptime.tv_sec = timePtr->sec + now.sec + + (timePtr->usec + now.usec) / 1000000; + ptime.tv_nsec = 1000 * ((timePtr->usec + now.usec) % 1000000); pthread_cond_timedwait(pcondPtr, pmutexPtr, &ptime); } } -- cgit v0.12