]> git.pond.sub.org Git - empserver/blob - include/empthread.h
Import of Empire 4.2.12
[empserver] / include / empthread.h
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2000, 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 "prototype.h"
40 #include "misc.h"
41
42 #if defined(_WIN32)
43 #undef _EMPTH_LWP
44 #undef _EMPTH_POSIX
45 #define _EMPTH_WIN32
46 #endif
47
48 #ifdef _EMPTH_LWP
49 #include "lwp.h"
50 typedef struct lwpProc empth_t;
51 typedef struct lwpSem empth_sem_t;
52 #define EMPTH_FD_READ     LWP_FD_READ
53 #define EMPTH_FD_WRITE    LWP_FD_WRITE
54 #define EMPTH_PRINT       LWP_PRINT
55 #define EMPTH_STACKCHECK  LWP_STACKCHECK
56 #endif
57
58 #ifdef _EMPTH_POSIX
59 #ifdef __linux__
60 #define _MIT_POSIX_THREADS 1
61 #endif
62 #include <pthread.h>
63 #define EMPTH_FD_READ   0x1
64 #define EMPTH_FD_WRITE  0x2
65
66 #define EMPTH_PRINT       0x1
67 #define EMPTH_STACKCHECK  0x2
68
69 typedef void (*vf_ptr)();
70 #define EMPTH_KILLED  1
71 typedef struct empth_ctx_t {
72     char *name;           /* thread name */
73     char *desc;           /* description */
74     void *ud;             /* user data */
75     int  state;           /* my state */
76     vf_ptr ep;            /* entry point */
77     pthread_t id;         /* thread id */
78 }empth_t;
79
80 typedef struct {
81     pthread_mutex_t mtx_update; /* use it to update count */
82     int count;
83     char name[80];
84     pthread_mutex_t mtx_sem;
85     pthread_cond_t cnd_sem;
86 }empth_sem_t;
87
88 #endif
89
90 /* DEC has slightly different names for whatever reason... */
91 #ifdef _DECTHREADS_
92 #define pthread_key_create  pthread_keycreate 
93 #define pthread_attr_init   pthread_attr_create
94 #define pthread_attr_destroy pthread_attr_delete
95
96 #endif
97
98
99 #if defined(_EMPTH_WIN32)
100 /* The Windows NT Threads */
101 #define EMPTH_FD_READ   0x1
102 #define EMPTH_FD_WRITE  0x2
103
104 #define EMPTH_PRINT       0x1
105 #define EMPTH_STACKCHECK  0x2
106
107 typedef void empth_t;
108
109 typedef void empth_sem_t;
110
111 #endif
112
113 int empth_init _PROTO((char **ctx, int flags));
114 empth_t *empth_create _PROTO((int, void (*)(), int,
115                         int, char *, char *, void *));
116 empth_t *empth_self();
117 void empth_exit _PROTO((void));
118 void empth_yield _PROTO((void));
119 void empth_terminate _PROTO((empth_t *));
120 void empth_select _PROTO((int fd, int flags));
121 void empth_wakeup _PROTO((empth_t *));
122 void empth_sleep  _PROTO((long until));
123 empth_sem_t *empth_sem_create _PROTO((char *name, int count));
124 void empth_sem_signal _PROTO((empth_sem_t *));
125 void empth_sem_wait _PROTO((empth_sem_t *));
126 emp_sig_t empth_alarm _PROTO((int));
127
128
129 #include "prototypes.h" /* must come at end, after defines and typedefs */
130 #endif  
131
132
133
134
135
136
137