Tcl Source Code

Artifact [05f55e0927]
Login

Artifact 05f55e09274512d54b45be731787ac6c34b15cf8:

Attachment "tim.patch" to ticket [3328635fff] added by ferrieux 2011-06-25 03:41:02.
Index: unix/tclUnixThrd.c
===================================================================
--- unix/tclUnixThrd.c
+++ unix/tclUnixThrd.c
@@ -538,12 +538,16 @@
 	 * Double check inside mutex to avoid race, then initialize condition
 	 * variable if necessary.
 	 */
 
 	if (*condPtr == NULL) {
+	    pthread_condattr_t attr;
+	    pthread_condattr_init(&attr);
+	    pthread_condattr_setclock(&attr,CLOCK_MONOTONIC);
 	    pcondPtr = ckalloc(sizeof(pthread_cond_t));
-	    pthread_cond_init(pcondPtr, NULL);
+	    pthread_cond_init(pcondPtr, &attr);
+	    pthread_condattr_destroy(&attr);
 	    *condPtr = (Tcl_Condition) pcondPtr;
 	    TclRememberCondition(condPtr);
 	}
 	MASTER_UNLOCK;
     }
@@ -550,21 +554,21 @@
     pmutexPtr = *((pthread_mutex_t **)mutexPtr);
     pcondPtr = *((pthread_cond_t **)condPtr);
     if (timePtr == NULL) {
 	pthread_cond_wait(pcondPtr, pmutexPtr);
     } else {
-	Tcl_Time now;
+	struct timespec pnow;
 
 	/*
 	 * Make sure to take into account the microsecond component of the
 	 * current time, including possible overflow situations. [Bug #411603]
 	 */
 
-	Tcl_GetTime(&now);
-	ptime.tv_sec = timePtr->sec + now.sec +
-	    (timePtr->usec + now.usec) / 1000000;
-	ptime.tv_nsec = 1000 * ((timePtr->usec + now.usec) % 1000000);
+	clock_gettime(CLOCK_MONOTONIC, &pnow);
+	ptime.tv_sec = timePtr->sec + pnow.tv_sec +
+	    (timePtr->usec + pnow.tv_nsec/1000) / 1000000;
+	ptime.tv_nsec = 1000 * ((timePtr->usec + pnow.tv_nsec/1000) % 1000000);
 	pthread_cond_timedwait(pcondPtr, pmutexPtr, &ptime);
     }
 }
 
 /*