LWP: kill dead code
[openafs.git] / src / lwp / lwp.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*******************************************************************\
11 *                                                                   *
12 *       Information Technology Center                               *
13 *       Carnegie-Mellon University                                  *
14 *                                                                   *
15 *                                                                   *
16 \*******************************************************************/
17
18 #ifndef __LWP_INCLUDE_
19 #define __LWP_INCLUDE_  1
20
21 #if !defined(KERNEL) && !defined(_KMEMUSER)
22 #include <afs/param.h>
23
24 /* External function declarations. */
25 #ifdef AFS_NT40_ENV
26 #ifndef _MFC_VER                /*skip if doing Microsoft foundation class */
27 #include <winsock2.h>
28 #endif
29 #elif defined(AFS_LINUX20_ENV)
30 #include <unistd.h>
31 #include <time.h>
32 #include <sys/time.h>
33 #else
34 # include <unistd.h>            /* select() prototype */
35 # include <sys/types.h>         /* fd_set on older platforms */
36 # include <sys/time.h>          /* struct timeval, select() prototype */
37 # ifndef FD_SET
38 #  include <sys/select.h>       /* fd_set on newer platforms */
39 # endif
40 #endif
41
42 /* fasttime.c */
43 extern int FT_GetTimeOfDay(struct timeval *tv, struct timezone *tz);
44 extern int FT_Init(int printErrors, int notReally);
45 extern int FT_AGetTimeOfDay(struct timeval *tv, struct timezone *tz);
46 extern unsigned int FT_ApproxTime(void);
47
48 #if !defined(AFS_PTHREAD_ENV)
49 # if defined(USE_UCONTEXT) && defined(HAVE_UCONTEXT_H)
50 #  include <ucontext.h>
51 # else
52 #  include <setjmp.h>
53 # endif
54
55 #define LWP_SUCCESS     0
56 #define LWP_EBADPID     -1
57 #define LWP_EBLOCKED    -2
58 #define LWP_EINIT       -3
59 #define LWP_EMAXPROC    -4
60 #define LWP_ENOBLOCK    -5
61 #define LWP_ENOMEM      -6
62 #define LWP_ENOPROCESS  -7
63 #define LWP_ENOWAIT     -8
64 #define LWP_EBADCOUNT   -9
65 #define LWP_EBADEVENT   -10
66 #define LWP_EBADPRI     -11
67 #define LWP_NO_STACK    -12
68 /* These two are for the signal mechanism. */
69 #define LWP_EBADSIG     -13     /* bad signal number */
70 #define LWP_ESYSTEM     -14     /* system call failed */
71 /* These are for the rock mechanism */
72 #define LWP_ENOROCKS    -15     /* all rocks are in use */
73 #define LWP_EBADROCK    -16     /* the specified rock does not exist */
74
75 #ifndef AFS_NT40_ENV
76 #define lwp_abort() abort()
77 #endif
78 /* Maximum priority permissible (minimum is always 0) */
79 #define LWP_MAX_PRIORITY 4      /* changed from 1 */
80
81 /* Usual priority used by user LWPs */
82 #define LWP_NORMAL_PRIORITY (LWP_MAX_PRIORITY-2)
83
84 /* Initial size of eventlist in a PCB; grows dynamically  */
85 #define EVINITSIZE  5
86
87 typedef struct lwp_pcb *PROCESS;
88
89 #ifdef AFS_NT40_ENV
90 #include <windef.h>
91 typedef struct lwp_pcb {
92     char name[32];              /* name of LWP */
93     LPVOID fiber;
94     int (*funP) ();             /* function to execute on this LWP */
95     void *argP;                 /* argument for function */
96     int priority;               /* LWP priority */
97     int stacksize;              /* Just for reference. */
98     /* the following are used for scheduling */
99     int status:8;
100     int eventlistsize:8;
101     int eventcnt:8;
102     int padding:8;
103     void **eventlist;
104     int wakevent;
105     int waitcnt;
106     struct lwp_pcb *next, *prev;
107     struct IoRequest *iomgrRequest;
108     int index;                  /* new number (++) for each process created. */
109 } lwp_pcb_t;
110
111 #else
112 struct lwp_context {            /* saved context for dispatcher */
113     char *topstack;             /* ptr to top of process stack */
114 #if defined(USE_UCONTEXT) && defined(HAVE_UCONTEXT_H)
115     ucontext_t ucontext;
116     int state;
117 #else                           /* !HAVE_UCONTEXT_H */
118 # if defined(sparc) && !defined(__linux__)
119 # ifdef save_allregs
120     int globals[7 + 1 + 32 + 2 + 32 + 2];       /* g1-g7, y reg, f0-f31, fsr, fq, c0-c31, csr, cq. */
121 # else
122     int globals[8];             /* g1-g7 and y registers. */
123 # endif
124 # endif
125     jmp_buf setjmp_buffer;
126 #endif                          /* HAVE_UCONTEXT_H */
127 };
128
129 struct rock {                   /* to hide things associated with this LWP under */
130     int tag;                    /* unique identifier for this rock */
131     char *value;                /* pointer to some arbitrary data structure */
132 };
133
134 #define MAXROCKS        4       /* max no. of rocks per LWP */
135
136 struct lwp_pcb {                /* process control block */
137     char name[32];              /* ASCII name */
138     int rc;                     /* most recent return code */
139     char status;                /* status flags */
140     char blockflag;             /* if (blockflag), process blocked */
141     char eventlistsize;         /* size of eventlist array */
142     char padding;               /* force 32-bit alignment */
143     void **eventlist;           /* ptr to array of eventids */
144     int eventcnt;               /* no. of events currently in eventlist array */
145     int wakevent;               /* index of eventid causing wakeup */
146     int waitcnt;                /* min number of events awaited */
147     int priority;               /* dispatching priority */
148     struct lwp_pcb *misc;       /* for LWP internal use only */
149     char *stack;                /* ptr to process stack */
150     int stacksize;              /* size of stack */
151     int stackcheck;             /* first word of stack for overflow checking */
152     void *(*ep)(void *);        /* initial entry point */
153     char *parm;                 /* initial parm for process */
154     struct lwp_context
155       context;                  /* saved context for next dispatch */
156     int lwp_rused;              /* no of rocks presently in use */
157     struct rock lwp_rlist[MAXROCKS];    /* set of rocks to hide things under */
158     struct lwp_pcb *next, *prev;        /* ptrs to next and previous pcb */
159     int level;                  /* nesting level of critical sections */
160     struct IoRequest *iomgrRequest;     /* request we're waiting for */
161     int index;                  /* LWP index: should be small index; actually is
162                                  * incremented on each lwp_create_process */
163 };
164 #endif /* AFS_NT40_ENV */
165
166 extern int lwp_nextindex;       /* Next lwp index to assign */
167
168
169 #ifndef LWP_KERNEL
170 #define LWP_ActiveProcess       (lwp_cpptr+0)
171 #define LWP_Index() (LWP_ActiveProcess->index)
172 #define LWP_HighestIndex() (lwp_nextindex - 1)
173 #ifndef AFS_SUN5_ENV            /* Actual functions for solaris */
174 #define LWP_SignalProcess(event)        LWP_INTERNALSIGNAL(event, 1)
175 #define LWP_NoYieldSignal(event)        LWP_INTERNALSIGNAL(event, 0)
176 #endif
177
178 extern
179 #endif
180 struct lwp_pcb *lwp_cpptr;      /* pointer to current process pcb */
181
182 struct lwp_ctl {                /* LWP control structure */
183     int processcnt;             /* number of lightweight processes */
184     char *outersp;              /* outermost stack pointer */
185     struct lwp_pcb *outerpid;   /* process carved by Initialize */
186     struct lwp_pcb *first, last;        /* ptrs to first and last pcbs */
187 #ifdef __hp9000s800
188     double dsptchstack[200];    /* stack for dispatcher use only */
189     /* force 8 byte alignment        */
190 #else
191     char dsptchstack[800];      /* stack for dispatcher use only */
192 #endif
193 };
194
195 #ifndef LWP_KERNEL
196 extern
197 #endif
198 char lwp_debug;                 /* ON = show LWP debugging trace */
199
200 /*
201  * Under hpux, any stack size smaller than 16K seems prone to
202  * overflow problems.
203  *
204  * On Solaris 2.5, gethostbyname() can use up to 21920 bytes of stack
205  * space.  Note: when measuring this, it is important to check the
206  * amount of stack space it uses for hosts that are known as well as
207  * for hosts that are unknown; the stack usage can differ between these
208  * cases, and also between machines apparently running the same OS
209  * version.
210  */
211 /*
212  * On ia64 where the ucontext is used, it can be an extra 48K
213  * Need to account for this.  There might be two of these on the
214  * stack too. This needs to be checked.
215  */
216 #if defined(USE_UCONTEXT) && defined(HAVE_UCONTEXT_H)
217 #define AFS_LWP_MINSTACKSIZE  (288 * 1024)
218 #elif defined(AFS_LINUX22_ENV)
219 #define AFS_LWP_MINSTACKSIZE    (192 * 1024)
220 #else
221 #define AFS_LWP_MINSTACKSIZE    (48 * 1024)
222 #endif
223
224 /* Action to take on stack overflow. */
225 #define LWP_SOQUIET     1       /* do nothing */
226 #define LWP_SOABORT     2       /* abort the program */
227 #define LWP_SOMESSAGE   3       /* print a message and be quiet */
228 extern int lwp_overflowAction;
229
230 /* Tells if stack size counting is enabled. */
231 extern int lwp_stackUseEnabled;
232 extern int lwp_MaxStackSeen;
233
234 #ifndef AFS_AIX32_ENV
235 #define LWP_CreateProcess2(a, b, c, d, e, f)    \
236         LWP_CreateProcess((a), (b), (c), (d), (e), (f))
237 #endif
238
239 /* iomgr.c */
240 extern fd_set *IOMGR_AllocFDSet(void);
241 extern int IOMGR_Select(int nfds, fd_set * rfds, fd_set * wfds, fd_set * efds,
242                         struct timeval *tvp);
243 extern int IOMGR_Poll(void);
244 extern void IOMGR_Sleep(int seconds);
245 extern int IOMGR_Cancel(PROCESS pid);
246 extern int IOMGR_Initialize(void);
247 extern void IOMGR_FreeFDSet(fd_set * fds);
248 extern int IOMGR_SoftSig(void *(*aproc) (void *), void *arock);
249
250 #ifdef AFS_NT40_ENV
251 /* lwp.c */
252 extern int LWP_InitializeProcessSupport(int priority, PROCESS * pid);
253 extern int LWP_CreateProcess(int (*funP) (), int stacksize, int priority,
254                              void *argP, char *name, PROCESS * pid);
255 extern int LWP_DestroyProcess(PROCESS pid);
256 extern int LWP_DispatchProcess(void);
257 extern int LWP_WaitProcess(void *event);
258 extern int LWP_INTERNALSIGNAL(void *event, int yield);
259 extern int LWP_QWait(void);
260 extern int LWP_QSignal(PROCESS pid);
261 #else
262 extern int LWP_CurrentProcess(PROCESS * pid);
263 extern int LWP_INTERNALSIGNAL(void *event, int yield);
264 extern int LWP_InitializeProcessSupport(int priority, PROCESS * pid);
265 extern int LWP_CreateProcess(void *(*ep)(void *), int stacksize, int priority,
266                              void *parm, char *name, PROCESS * pid);
267 extern int LWP_DestroyProcess(PROCESS pid);
268 extern int LWP_DispatchProcess(void);
269 extern int LWP_WaitProcess(void *event);
270 extern PROCESS LWP_ThreadId(void);
271 extern int LWP_QWait(void);
272 extern int LWP_QSignal(PROCESS pid);
273 #endif
274
275 extern afs_int32 savecontext(void (*ep)(void),
276                              struct lwp_context *savearea, char *sp);
277 extern void returnto(struct lwp_context *savearea);
278
279 #ifdef AFS_LINUX24_ENV
280 /* max time we are allowed to spend in a select call on Linux to avoid
281  lost signal issues */
282 #define IOMGR_MAXWAITTIME        60     /* seconds */
283 #else
284 /* max time we are allowed to spend in a select call on NT */
285 #define IOMGR_MAXWAITTIME        5      /* seconds */
286 #endif
287
288 /* max time we spend on a select in a Win95 DOS box */
289 #define IOMGR_WIN95WAITTIME 5000        /* microseconds */
290
291 #endif /* !AFS_PTHREAD_ENV */
292
293 extern int LWP_WaitForKeystroke(int seconds);   /* -1 => forever */
294 extern int LWP_GetResponseKey(int seconds, char *key);
295 extern int LWP_GetLine(char *linebuf, int len);
296
297 #endif /* !KERNEL && !_KMEMUSER */
298 #endif /* __LWP_INCLUDE_ */