]> git.pond.sub.org Git - empserver/blob - include/empthread.h
(service_stoppped,stop_service,loc_Ctrl_C_Handler,
[empserver] / include / empthread.h
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23  *  related information and legal notices. It is expected that any future
24  *  projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  empthread.h: Definitions for Empire threading
29  * 
30  *  Known contributors to this file:
31  *     Sasha Mikheev
32  *     Doug Hay, 1998
33  *     Steve McClure, 1998
34  */
35
36 #ifndef _EMTHREAD_H_
37 #define _EMTHREAD_H_
38
39 #include "misc.h"
40
41 #if defined(_WIN32)
42 #undef _EMPTH_LWP
43 #undef _EMPTH_POSIX
44 #define _EMPTH_WIN32
45 #endif
46
47 #ifdef _EMPTH_LWP
48 #include "lwp.h"
49 typedef struct lwpProc empth_t;
50 typedef struct lwpSem empth_sem_t;
51 #define EMPTH_FD_READ     LWP_FD_READ
52 #define EMPTH_FD_WRITE    LWP_FD_WRITE
53 #define EMPTH_PRINT       LWP_PRINT
54 #define EMPTH_STACKCHECK  LWP_STACKCHECK
55 #endif
56
57 #ifdef _EMPTH_POSIX
58 #ifdef __linux__
59 #define _MIT_POSIX_THREADS 1
60 #endif
61 #include <pthread.h>
62 #define EMPTH_FD_READ   0x1
63 #define EMPTH_FD_WRITE  0x2
64
65 #define EMPTH_PRINT       0x1
66 #define EMPTH_STACKCHECK  0x2
67
68 #define EMPTH_KILLED  1
69 typedef struct {
70     char *name;                 /* thread name */
71     char *desc;                 /* description */
72     void *ud;                   /* user data */
73     int state;                  /* my state */
74     void (*ep)(void *);         /* entry point */
75     pthread_t id;               /* thread id */
76 } empth_t;
77
78 typedef struct {
79     pthread_mutex_t mtx_update; /* use it to update count */
80     int count;
81     char name[80];
82     pthread_mutex_t mtx_sem;
83     pthread_cond_t cnd_sem;
84 } empth_sem_t;
85
86 #endif
87
88 /* DEC has slightly different names for whatever reason... */
89 #ifdef _DECTHREADS_
90 #define pthread_key_create  pthread_keycreate
91 #define pthread_attr_init   pthread_attr_create
92 #define pthread_attr_destroy pthread_attr_delete
93
94 #endif
95
96
97 #if defined(_EMPTH_WIN32)
98 /* The Windows NT Threads */
99 #define EMPTH_FD_READ   0x1
100 #define EMPTH_FD_WRITE  0x2
101
102 #define EMPTH_PRINT       0x1
103 #define EMPTH_STACKCHECK  0x2
104
105 typedef struct loc_Thread_t empth_t;
106 typedef struct loc_Sem_t empth_sem_t;
107
108 void empth_request_shutdown(void);
109 #endif
110
111 int empth_init(char **ctx, int flags);
112 empth_t *empth_create(int, void (*)(void *), int, int, char *, char *, void *);
113 empth_t *empth_self(void);
114 void empth_exit(void);
115 void empth_yield(void);
116 void empth_terminate(empth_t *);
117 void empth_select(int fd, int flags);
118 void empth_wakeup(empth_t *);
119 void empth_sleep(long until);
120 empth_sem_t *empth_sem_create(char *name, int count);
121 void empth_sem_signal(empth_sem_t *);
122 void empth_sem_wait(empth_sem_t *);
123 void empth_alarm(int);
124
125 #endif