]> git.pond.sub.org Git - empserver/blobdiff - src/lib/empthread/ntthread.c
Make empth_wakeup() and empth_terminate() wake up empth_sleep(), and
[empserver] / src / lib / empthread / ntthread.c
index cd51c3ba9c36d3a2faf9c4425e054776625ea61a..0073cd283a2d4a2ee7c9965e26e3261135185a49 100644 (file)
@@ -599,21 +599,25 @@ empth_wakeup(empth_t *pThread)
  *
  * Put the given thread to sleep...
  */
-void
+int
 empth_sleep(time_t until)
 {
     long lSec;
+    empth_t *pThread = TlsGetValue(dwTLSIndex);
+    int iReturn = 0;
 
-    loc_BlockThisThread();
-
-    while ((lSec = until - time(0)) > 0) {
-        loc_debug("going to sleep %ld sec", lSec);
-       Sleep(lSec * 1000L);
-    }
+    if ((lSec = until - time(0)) > 0) {
+       loc_BlockThisThread();
+       loc_debug("going to sleep %ld sec", lSec);
 
-    loc_debug("sleep done. Waiting to run.");
+       if (WaitForSingleObject(pThread->hThreadEvent, lSec * 1000L) !=
+           WAIT_TIMEOUT)
+           iReturn = -1;
 
-    loc_RunThisThread(NULL);
+       loc_debug("sleep done. Waiting to run.");
+       loc_RunThisThread(NULL);
+    }
+    return iReturn;
 }
 
 /************************