]> git.pond.sub.org Git - empserver/blob - src/lib/lwp/lwpint.h
(stkalign_t, STKALIGN): Replace.
[empserver] / src / lib / lwp / lwpint.h
1 /*
2  * lwpint.h -- lwp internal structures
3  *
4  * Copyright (C) 1991-3 Stephen Crane.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  * 
11  * This library 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 GNU
14  * Library General Public License for more details.
15  * 
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  * author: Stephen Crane, (jsc@doc.ic.ac.uk), Department of Computing,
21  * Imperial College of Science, Technology and Medicine, 180 Queen's
22  * Gate, London SW7 2BZ, England.
23  */
24 #ifndef _LWPINT_H
25 #define _LWPINT_H
26
27 /* `liveness' counter: check signals every `n' visits to the scheduler */
28 /* note: the lower this value, the more responsive the system but the */
29 /* more inefficient the context switch time */
30 #define LCOUNT  -1
31
32 /* process control block.  do *not* change the position of context */
33 struct lwpProc {
34 #ifdef UCONTEXT
35     ucontext_t context;         /* context structure */
36 #else  /* !UCONTEXT */
37     jmp_buf context;            /* processor context area */
38 #endif /* !UCONTEXT */
39     void *sbtm;                 /* bottom of stack attached to it */
40     int size;                   /* size of stack */
41     void (*entry)(void *);      /* entry point */
42     int dead;                   /* whether the process can be rescheduled */
43     int pri;                    /* which scheduling queue we're on */
44     long runtime;               /* time at which process is restarted */
45     int fd;                     /* fd we're blocking on */
46     int argc;                   /* initial arguments */
47     char **argv;
48     void *ud;                   /* user data */
49     void *lowmark;              /* start of low buffer around stack */
50     void *himark;               /* start of upper buffer around stack */
51     char *name;                 /* process name and description */
52     char *desc;
53     int flags;
54     struct lwpProc *next;
55 };
56
57 /* queue */
58 struct lwpQueue {
59     struct lwpProc *head;
60     struct lwpProc *tail;
61 };
62
63 /* semaphore */
64 struct lwpSem {
65     int count;
66     struct lwpQueue q;
67     char *name;
68 };
69
70 #ifdef UCONTEXT
71 void lwpInitContext(struct lwpProc *, stack_t *);
72 #define lwpSave(x)    getcontext(&(x))
73 #define lwpRestore(x) setcontext(&(x))
74 #else  /* !UCONTEXT */
75 #if defined(hpux) && !defined(hpc)
76 void lwpInitContext(volatile struct lwpProc * volatile, void *);
77 #else
78 void lwpInitContext(struct lwpProc *, void *);
79 #endif
80 #if defined(hpc)
81 int lwpSave(jmp_buf);
82 #define lwpRestore(x)   longjmp(x, 1)
83 #elif defined(hpux) || defined(AIX32) || defined(ALPHA)
84 int lwpSave(jmp_buf);
85 void lwpRestore(jmp_buf);
86 #elif defined(SUN4)
87 #define lwpSave(x)      _setjmp(x)
88 #define lwpRestore(x)   _longjmp(x, 1)
89 #else
90 #define lwpSave(x)      setjmp(x)
91 #define lwpRestore(x)   longjmp(x, 1)
92 #endif
93 #endif /* !UCONTEXT */
94
95 #ifdef AIX32
96 /* AIX needs 12 extra bytes above the stack; we add it here */
97 #define LWP_EXTRASTACK  3*sizeof(long)
98 #else
99 #define LWP_EXTRASTACK  0
100 #endif
101
102 #define LWP_REDZONE     1024    /* make this a multiple of 1024 */
103
104 /* XXX Note that this assumes sizeof(long) == 4 */
105 #define LWP_CHECKMARK   0x5a5a5a5aL
106
107 #ifdef hpux
108 #define STKALIGN 64
109 #else
110 #define STKALIGN sizeof(double)
111 #endif
112
113 /* internal routines */
114 void lwpAddTail(struct lwpQueue *, struct lwpProc *);
115 struct lwpProc *lwpGetFirst(struct lwpQueue *);
116 void lwpReady(struct lwpProc *);
117 void lwpReschedule(void);
118 void lwpEntryPoint(void);
119 void lwpInitSelect(struct lwpProc * self);
120 void lwpDestroy(struct lwpProc * proc);
121
122 #endif /* _LWP_H */