]> git.pond.sub.org Git - empserver/blobdiff - include/empthread.h
(empth_init_signals): Don't catch SIGINT and SIGTERM.
[empserver] / include / empthread.h
index e10df7f39b161132eef8e09b6c8e2ad5f0df3558..172e89a0d9917405b547620fd7ae693eee27b6d3 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -19,9 +19,9 @@
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
@@ -31,6 +31,7 @@
  *     Sasha Mikheev
  *     Doug Hay, 1998
  *     Steve McClure, 1998
+ *     Markus Armbruster, 2005
  */
 
 /*
  * event to happen.
  */
 
-#ifndef _EMTHREAD_H_
-#define _EMTHREAD_H_
-
-#include "misc.h"
-
-#if defined(_WIN32)
-#undef _EMPTH_LWP
-#undef _EMPTH_POSIX
-#define _EMPTH_WIN32
-#endif
-
-#ifdef _EMPTH_LWP
+#ifndef EMPTHREAD_H
+#define EMPTHREAD_H
+
+/* thread priorities */
+enum {
+    PP_MAIN     = 7,
+    PP_UPDATE   = 6,
+    PP_SHUTDOWN         = 5,
+    PP_SCHED    = 4,
+    PP_TIMESTAMP = 2,
+    PP_PLAYER   = 3,
+    PP_ACCEPT   = 3,
+    PP_KILLIDLE         = 2
+};
+
+#ifdef EMPTH_LWP
 #include "lwp.h"
 
 /* Abstract data types */
@@ -77,9 +82,9 @@ typedef struct lwpSem empth_sem_t;
 /* Request stack checking */
 #define EMPTH_STACKCHECK  LWP_STACKCHECK
 
-#endif /* _EMPTH_LWP */
+#endif /* EMPTH_LWP */
 
-#ifdef _EMPTH_POSIX
+#ifdef EMPTH_POSIX
 #include <pthread.h>
 #define EMPTH_FD_READ   0x1
 #define EMPTH_FD_WRITE  0x2
@@ -90,9 +95,9 @@ typedef struct lwpSem empth_sem_t;
 typedef struct empth_t empth_t;
 typedef struct empth_sem_t empth_sem_t;
 
-#endif /* _EMPTH_POSIX */
+#endif /* EMPTH_POSIX */
 
-#if defined(_EMPTH_WIN32)
+#ifdef EMPTH_W32
 /* The Windows NT Threads */
 #define EMPTH_FD_READ   0x1
 #define EMPTH_FD_WRITE  0x2
@@ -104,7 +109,7 @@ typedef struct loc_Thread_t empth_t;
 typedef struct loc_Sem_t empth_sem_t;
 
 void empth_request_shutdown(void);
-#endif /* _EMPTH_WIN32 */
+#endif /* EMPTH_W32 */
 
 /*
  * Initialize thread package.
@@ -126,6 +131,7 @@ int empth_init(void **ctx, int flags);
  * UD is the value to pass to ENTRY.  It is also assigned to the
  * context variable defined with empth_init() whenever the thread gets
  * scheduled.
+ * Yield the processor.
  * Return the thread, or NULL on error.
  */
 empth_t *empth_create(int prio, void (*entry)(void *),
@@ -138,6 +144,9 @@ empth_t *empth_self(void);
 
 /*
  * Terminate the current thread.
+ * The current thread should not be the thread that executed main().
+ * If it is, implementations may terminate the process rather than the
+ * thread.
  * Never returns.
  */
 void empth_exit(void);
@@ -178,6 +187,12 @@ void empth_wakeup(empth_t *thread);
  */
 void empth_sleep(time_t until);
 
+/*
+ * Wait for some implementation-defined external shutdown signal.
+ * Return a non-negative number identifying the signal.
+ */
+int empth_wait_for_shutdown(void);
+
 /*
  * Create a semaphore.
  * NAME is its name, it is used for debugging.
@@ -205,7 +220,11 @@ void empth_sem_signal(empth_sem_t *sem);
  */
 void empth_sem_wait(empth_sem_t *sem);
 
-/* Internal function, not part of the thread abstraction */
-void empth_alarm(int);
+
+/*
+ * Stuff for implementations, not for clients.
+ */
+
+void empth_init_signals(void);
 
 #endif