clean up headers, obsd socket.h needs types.h
[arla.git] / lwp / plwp.h
blob6bcbfe2b4a2db9429ea473b644e7e8b7c2fac16e
1 /*
2 * $Id$
3 */
5 #ifndef LWP_INCLUDED
6 #define LWP_INCLUDED
8 #ifdef HAVE_CONFIG_H
9 #include <config.h>
10 #endif
12 #ifdef HAVE_SYS_TYPES_H
13 #include <sys/types.h>
14 #endif
15 #ifdef HAVE_SYS_SELECT_H
16 #include <sys/select.h>
17 #endif
18 #ifdef HAVE_UNISTD_H
19 #include <unistd.h>
20 #endif
21 #ifdef HAVE_POSIX_SIGNALS
22 #define AFS_POSIX_SIGNALS 1
23 #endif
24 #define AFS_LWP_MINSTACKSIZE (100 * 1024)
25 #include <sys/time.h>
26 #include <signal.h>
28 #ifdef PTHREADS_LWP
29 #include <pthread.h>
30 #endif
32 #include <roken.h>
34 #ifdef WINDOWS_THREADS_LWP
35 #include <windows.h>
36 #endif
38 #ifndef LWP_KERNEL
39 extern
40 #endif
41 int lwp_debug; /* ON = show LWP debugging trace */
43 extern int lwp_stackUseEnabled;
44 extern int lwp_MaxStackSeen;
45 #define LWP_ActiveProcess (lwp_cpptr+0)
47 #define LWP_VERSION 210888001
49 #define LWP_SUCCESS 0
50 #define LWP_EBADPID -1
51 #define LWP_EBLOCKED -2
52 #define LWP_EINIT -3
53 #define LWP_EMAXPROC -4
54 #define LWP_ENOBLOCK -5
55 #define LWP_ENOMEM -6
56 #define LWP_ENOPROCESS -7
57 #define LWP_ENOWAIT -8
58 #define LWP_EBADCOUNT -9
59 #define LWP_EBADEVENT -10
60 #define LWP_EBADPRI -11
61 #define LWP_NO_STACK -12
62 /* These two are for the signal mechanism. */
63 #define LWP_EBADSIG -13 /* bad signal number */
64 #define LWP_ESYSTEM -14 /* system call failed */
65 /* These are for the rock mechanism */
66 #define LWP_ENOROCKS -15 /* all rocks are in use */
67 #define LWP_EBADROCK -16 /* the specified rock does not exist */
70 /* Maximum priority permissible (minimum is always 0) */
71 #define LWP_MAX_PRIORITY 4
73 /* Usual priority used by user LWPs */
74 #define LWP_NORMAL_PRIORITY (LWP_MAX_PRIORITY-1)
76 #define LWP_SignalProcess(event) LWP_INTERNALSIGNAL(event, 1)
77 #define LWP_NoYieldSignal(event) LWP_INTERNALSIGNAL(event, 0)
79 /* Users aren't really supposed to know what a pcb is, but .....*/
80 typedef struct lwp_pcb *PROCESS;
82 /* Action to take on stack overflow. */
83 #define LWP_SOQUIET 1 /* do nothing */
84 #define LWP_SOABORT 2 /* abort the program */
85 #define LWP_SOMESSAGE 3 /* print a message and be quiet */
86 extern int lwp_overflowAction;
88 /* Invalid LWP Index */
89 #define LWP_INVALIDTHREADID (-1)
91 /* Tells if stack size counting is enabled. */
92 extern int lwp_stackUseEnabled;
94 int LWP_QWait(void);
95 int LWP_QSignal(PROCESS);
96 int LWP_Init(int, int, PROCESS *);
97 int LWP_InitializeProcessSupport(int, PROCESS *);
98 int LWP_TerminateProcessSupport(void);
99 int LWP_CreateProcess(void (*)(), int, int, char *, char *, PROCESS *);
100 int LWP_CurrentProcess(PROCESS *);
101 int LWP_DestroyProcess(PROCESS);
102 int LWP_DispatchProcess(void);
103 int LWP_GetProcessPriority(PROCESS, int *);
104 int LWP_INTERNALSIGNAL(void *, int);
105 int LWP_WaitProcess(void *);
106 int LWP_MwaitProcess(int, char **);
107 int LWP_StackUsed(PROCESS, int *, int *);
108 int LWP_NewRock(int, char *);
109 int LWP_GetRock(int, char **);
110 char *LWP_Name(void);
111 int LWP_Index(void);
112 int LWP_HighestIndex(void);
114 int IOMGR_SoftSig(void (*)(), char *);
115 int IOMGR_Initialize(void);
116 int IOMGR_Finalize(void);
117 long IOMGR_Poll(void);
118 int IOMGR_Select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
119 int IOMGR_Cancel(PROCESS);
120 int IOMGR_Signal(int, char *);
121 int IOMGR_CancelSignal(int);
122 void IOMGR_Sleep(unsigned int);
124 int FT_Init(int, int);
125 #if __GNUC__ >= 2
126 struct timezone;
127 #endif
128 int FT_GetTimeOfDay(struct timeval *, struct timezone *);
129 int TM_GetTimeOfDay(struct timeval *, struct timezone *);
130 int FT_AGetTimeOfDay(struct timeval *, struct timezone *);
131 unsigned int FT_ApproxTime(void);
133 /* Initial size of eventlist in a PCB; grows dynamically */
134 #define EVINITSIZE 5
136 struct rock
137 {/* to hide things associated with this LWP under */
138 int tag; /* unique identifier for this rock */
139 /* pointer to some arbitrary data structure */
140 #if defined(PTHREADS_LWP)
141 pthread_key_t val;
142 #elif defined(WINDOWS_THREADS_LWP)
143 LPVOID val;
144 #endif
147 #define MAXROCKS 4 /* max no. of rocks per LWP */
149 struct lwp_pcb { /* process control block */
150 char name[32];
151 int rc;
152 char status;
153 char **eventlist;
154 char eventlistsize;
155 int eventcnt;
156 int wakevent;
157 int waitcnt;
158 char blockflag;
159 int priority;
160 PROCESS misc;
161 char *stack;
162 int stacksize;
163 long stackcheck;
164 void (*ep)(char *);
165 char *parm;
166 int rused;
167 struct rock rlist[MAXROCKS];
168 PROCESS next, prev;
169 int level;
170 struct IoRequest *iomgrRequest;
171 int index;
172 struct timeval lastReady;
173 #if defined(PTHREADS_LWP)
174 pthread_mutex_t m;
175 pthread_cond_t c;
176 pthread_attr_t a;
177 #elif defined(WINDOWS_THREADS_LWP)
178 HANDLE m;
179 HANDLE c;
180 HANDLE t;
181 #endif
184 extern int lwp_nextindex; /* Next lwp index to assign */
186 extern PROCESS lwp_cpptr; /* pointer to current process pcb */
187 struct lwp_ctl { /* LWP control structure */
188 int processcnt; /* number of lightweight processes */
189 char *outersp; /* outermost stack pointer */
190 PROCESS outerpid; /* process carved by Initialize */
191 PROCESS first, last; /* ptrs to first and last pcbs */
192 char dsptchstack[800]; /* stack for dispatcher use only */
195 /* Debugging macro */
196 #ifdef LWPDEBUG
197 #define lwpdebug(level, msg)\
198 if (lwp_debug > level) {\
199 printf("***LWP (0x%x): ", lwp_cpptr);\
200 printf msg;\
201 putchar('\n');\
202 fflush(stdout);\
204 #else /* LWPDEBUG */
205 #define lwpdebug(level, msg)
206 #endif /* LWPDEBUG */
208 #define MAXTHREADS 100
210 #endif /* LWP_INCLUDED */