]> git.pond.sub.org Git - empserver/commitdiff
Ensure the empth_sleep() always yields for WIN32
authorRon Koenderink <rkoenderink@yahoo.ca>
Fri, 12 Sep 2008 01:06:10 +0000 (19:06 -0600)
committerRon Koenderink <rkoenderink@yahoo.ca>
Fri, 12 Sep 2008 13:22:28 +0000 (07:22 -0600)
The WIN32 version did not block when the sleep was
already reached by the time empth_sleep() did the
time remaining calculation.  The other versions
of empth_sleep() do always yield.

src/lib/empthread/ntthread.c

index 4799b0311644b33254ac0c33fb666e80ce573c08..9b05f7d97730d456389b4119316aeb669e4469df 100644 (file)
@@ -613,11 +613,11 @@ empth_wakeup(empth_t *pThread)
 int
 empth_sleep(time_t until)
 {
-    long lSec;
+    long lSec = until - time(0) > 0 ? until - time(0) : 0;
     empth_t *pThread = TlsGetValue(dwTLSIndex);
     int iReturn = 0;
 
-    while (!iReturn && ((lSec = until - time(0)) > 0)) {
+    do {
        loc_BlockThisThread();
        loc_debug("going to sleep %ld sec", lSec);
 
@@ -627,7 +627,8 @@ empth_sleep(time_t until)
 
        loc_debug("sleep done. Waiting to run.");
        loc_RunThisThread(NULL);
-    }
+    } while (!iReturn && ((lSec = until - time(0)) > 0));
+
     return iReturn;
 }