]> git.pond.sub.org Git - empserver/blobdiff - src/lib/empthread/ntthread.c
Update copyright notice.
[empserver] / src / lib / empthread / ntthread.c
index 0fb8c4cc684ffc8e27ab3459e484ca8d16f06916..c734a0cd36cadea8d2c43a041ab154f3f30c46f4 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  * WIN32 has a full pre-emptive threading environment.  But Empire can
  * not handle pre-emptive threading.  Thus, we will use the threads,
  * but limit the preemption using a Mutex semaphore.
- *
  */
 
 #include <config.h>
 
+#include <errno.h>
+#include <signal.h>
 #include <stdio.h>
 #include <sys/types.h>
-#include <signal.h>
-#include <errno.h>
 #include <time.h>
-#include "misc.h"
-#include "empthread.h"
-#include "prototypes.h"
-
 #define WIN32
 #include <winsock2.h>
 #undef NS_ALL
 #include <windows.h>
 #include <process.h>
+#include "misc.h"
+#include "empthread.h"
+#include "prototypes.h"
 
 #define loc_MIN_THREAD_STACK  16384
 
@@ -184,7 +182,6 @@ loc_debug(const char *pszFmt, ...)
 
 /************************
  * loc_FreeThreadInfo
- *
  */
 static void
 loc_FreeThreadInfo(empth_t *pThread)
@@ -265,8 +262,7 @@ loc_BlockThisThread(void)
 static BOOL
 loc_Exit_Handler(DWORD fdwCtrlType)
 {
-    switch (fdwCtrlType) 
-    { 
+    switch (fdwCtrlType) { 
         case CTRL_C_EVENT:
         case CTRL_CLOSE_EVENT:
         case CTRL_BREAK_EVENT: 
@@ -279,31 +275,6 @@ loc_Exit_Handler(DWORD fdwCtrlType)
     }
 }
 
-/************************
- * empth_request_shutdown
- *
- * This wakes up the main thread so shutdown can proceed.
- * This is done by signalling hShutdownEvent.
- */
-void
-empth_request_shutdown(void)
-{
-    SetEvent(hShutdownEvent);
-}
-
-/************************
- * loc_BlockMainThread
- *
- * This blocks up the main thread.  loc_WakeupMainThread() is used
- * wakeup the main so shutdown can proceed.
- */
-static void
-loc_BlockMainThread(void)
-{
-    /* Get the MUTEX semaphore, wait the number of MS */
-    WaitForSingleObject(hShutdownEvent, INFINITE);
-}
-
 /************************
  * empth_threadMain
  *
@@ -493,19 +464,12 @@ empth_exit(void)
 {
     empth_t *pThread = TlsGetValue(dwTLSIndex);
 
-    loc_BlockThisThread();
-
     loc_debug("empth_exit");
+    loc_BlockThisThread();
 
-    if (pThread->bMainThread) {
-       loc_BlockMainThread();
-       loc_RunThisThread();
-       shutdwn(0);
-    } else {
-       TlsSetValue(dwTLSIndex, NULL);
-       loc_FreeThreadInfo(pThread);
-       _endthread();
-    }
+    TlsSetValue(dwTLSIndex, NULL);
+    loc_FreeThreadInfo(pThread);
+    _endthread();
 }
 
 /************************
@@ -609,6 +573,29 @@ empth_sleep(time_t until)
     loc_RunThisThread();
 }
 
+/************************
+ * empth_request_shutdown
+ *
+ * This wakes up empth_wait_for_signal() so shutdown can proceed.
+ * This is done by signalling hShutdownEvent.
+ */
+void
+empth_request_shutdown(void)
+{
+    SetEvent(hShutdownEvent);
+}
+
+int
+empth_wait_for_signal(void)
+{
+    loc_BlockThisThread();
+
+    /* Get the MUTEX semaphore, wait the number of MS */
+    WaitForSingleObject(hShutdownEvent, INFINITE);
+
+    loc_RunThisThread();
+    return 0;
+}
 
 /************************
  * empth_sem_create