]> git.pond.sub.org Git - empserver/blob - src/lib/lwp/lwpint.h
2db453b478427df1237511ed70a4dd4e1095ad28
[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 #ifdef UCONTEXT
28 #include <ucontext.h>
29 #else  /* !UCONTEXT */
30 #include <setjmp.h>
31 #endif /* !UCONTEXT */
32
33 /* `liveness' counter: check signals every `n' visits to the scheduler */
34 /* note: the lower this value, the more responsive the system but the */
35 /* more inefficient the context switch time */
36 #define LCOUNT  -1
37
38 /* process control block.  do *not* change the position of context */
39 struct lwpProc {
40 #ifdef UCONTEXT
41     ucontext_t context;         /* context structure */
42 #else  /* !UCONTEXT */
43     jmp_buf context;            /* processor context area */
44 #endif /* !UCONTEXT */
45     void *sbtm;                 /* stack buffer attached to it */
46     int size;                   /* size of stack buffer */
47     char *ustack;               /* lowest usable stack address */
48     int usize;                  /* size of usable stack */
49     void (*entry)(void *);      /* entry point */
50     int dead;                   /* whether the process can be rescheduled */
51     int pri;                    /* which scheduling queue we're on */
52     long runtime;               /* time at which process is restarted */
53     int fd;                     /* fd we're blocking on */
54     int argc;                   /* initial arguments */
55     char **argv;
56     void *ud;                   /* user data */
57     char *name;                 /* process name and description */
58     char *desc;
59     int flags;
60     struct lwpProc *next;
61 };
62
63 /* queue */
64 struct lwpQueue {
65     struct lwpProc *head;
66     struct lwpProc *tail;
67 };
68
69 /* semaphore */
70 struct lwpSem {
71     int count;
72     struct lwpQueue q;
73     char *name;
74 };
75
76 #define LWP_REDZONE     1024    /* make this a multiple of 1024 */
77
78 /* XXX Note that this assumes sizeof(long) == 4 */
79 #define LWP_CHECKMARK   0x5a5a5a5aL
80
81 extern int LwpStackGrowsDown;
82
83 int lwpNewContext(struct lwpProc *, int);
84 void lwpSwitchContext(struct lwpProc *, struct lwpProc *);
85 void lwpAddTail(struct lwpQueue *, struct lwpProc *);
86 struct lwpProc *lwpGetFirst(struct lwpQueue *);
87 void lwpReady(struct lwpProc *);
88 void lwpReschedule(void);
89 void lwpEntryPoint(void);
90 void lwpInitSelect(struct lwpProc * self);
91 void lwpDestroy(struct lwpProc * proc);
92
93 #endif