Blame


1 b2cfc4e2 2003-09-30 devnull #ifndef _THREADH_
2 b2cfc4e2 2003-09-30 devnull #define _THREADH_ 1
3 b2cfc4e2 2003-09-30 devnull
4 b2cfc4e2 2003-09-30 devnull /* avoid conflicts with socket library */
5 b2cfc4e2 2003-09-30 devnull #undef send
6 b2cfc4e2 2003-09-30 devnull #define send _threadsend
7 b2cfc4e2 2003-09-30 devnull #undef recv
8 b2cfc4e2 2003-09-30 devnull #define recv _threadrecv
9 b2cfc4e2 2003-09-30 devnull
10 b2cfc4e2 2003-09-30 devnull typedef struct Alt Alt;
11 b2cfc4e2 2003-09-30 devnull typedef struct Channel Channel;
12 b2cfc4e2 2003-09-30 devnull typedef struct Ref Ref;
13 b2cfc4e2 2003-09-30 devnull
14 b2cfc4e2 2003-09-30 devnull /* Channel structure. S is the size of the buffer. For unbuffered channels
15 b2cfc4e2 2003-09-30 devnull * s is zero. v is an array of s values. If s is zero, v is unused.
16 b2cfc4e2 2003-09-30 devnull * f and n represent the state of the queue pointed to by v.
17 b2cfc4e2 2003-09-30 devnull */
18 b2cfc4e2 2003-09-30 devnull
19 b2cfc4e2 2003-09-30 devnull enum {
20 b2cfc4e2 2003-09-30 devnull Nqwds = 2,
21 b2cfc4e2 2003-09-30 devnull Nqshift = 5, // 2log #of bits in long
22 b2cfc4e2 2003-09-30 devnull Nqmask = - 1,
23 b2cfc4e2 2003-09-30 devnull Nqbits = (1 << Nqshift) * 2,
24 b2cfc4e2 2003-09-30 devnull };
25 b2cfc4e2 2003-09-30 devnull
26 b2cfc4e2 2003-09-30 devnull struct Channel {
27 b2cfc4e2 2003-09-30 devnull int s; // Size of the channel (may be zero)
28 b2cfc4e2 2003-09-30 devnull unsigned int f; // Extraction point (insertion pt: (f + n) % s)
29 b2cfc4e2 2003-09-30 devnull unsigned int n; // Number of values in the channel
30 b2cfc4e2 2003-09-30 devnull int e; // Element size
31 b2cfc4e2 2003-09-30 devnull int freed; // Set when channel is being deleted
32 b2cfc4e2 2003-09-30 devnull volatile Alt **qentry; // Receivers/senders waiting (malloc)
33 b2cfc4e2 2003-09-30 devnull volatile int nentry; // # of entries malloc-ed
34 b2cfc4e2 2003-09-30 devnull unsigned char v[1]; // Array of s values in the channel
35 b2cfc4e2 2003-09-30 devnull };
36 b2cfc4e2 2003-09-30 devnull
37 b2cfc4e2 2003-09-30 devnull
38 b2cfc4e2 2003-09-30 devnull /* Channel operations for alt: */
39 b2cfc4e2 2003-09-30 devnull typedef enum {
40 b2cfc4e2 2003-09-30 devnull CHANEND,
41 b2cfc4e2 2003-09-30 devnull CHANSND,
42 b2cfc4e2 2003-09-30 devnull CHANRCV,
43 b2cfc4e2 2003-09-30 devnull CHANNOP,
44 b2cfc4e2 2003-09-30 devnull CHANNOBLK,
45 b2cfc4e2 2003-09-30 devnull } ChanOp;
46 b2cfc4e2 2003-09-30 devnull
47 b2cfc4e2 2003-09-30 devnull struct Alt {
48 b2cfc4e2 2003-09-30 devnull Channel *c; /* channel */
49 b2cfc4e2 2003-09-30 devnull void *v; /* pointer to value */
50 b2cfc4e2 2003-09-30 devnull ChanOp op; /* operation */
51 b2cfc4e2 2003-09-30 devnull
52 b2cfc4e2 2003-09-30 devnull /* the next variables are used internally to alt
53 b2cfc4e2 2003-09-30 devnull * they need not be initialized
54 b2cfc4e2 2003-09-30 devnull */
55 b2cfc4e2 2003-09-30 devnull Channel **tag; /* pointer to rendez-vous tag */
56 b2cfc4e2 2003-09-30 devnull int entryno; /* entry number */
57 b2cfc4e2 2003-09-30 devnull };
58 b2cfc4e2 2003-09-30 devnull
59 b2cfc4e2 2003-09-30 devnull struct Ref {
60 b2cfc4e2 2003-09-30 devnull long ref;
61 b2cfc4e2 2003-09-30 devnull };
62 b2cfc4e2 2003-09-30 devnull
63 b2cfc4e2 2003-09-30 devnull int alt(Alt alts[]);
64 b2cfc4e2 2003-09-30 devnull Channel* chancreate(int elemsize, int bufsize);
65 b2cfc4e2 2003-09-30 devnull int chaninit(Channel *c, int elemsize, int elemcnt);
66 b2cfc4e2 2003-09-30 devnull void chanfree(Channel *c);
67 b2cfc4e2 2003-09-30 devnull int chanprint(Channel *, char *, ...);
68 b2cfc4e2 2003-09-30 devnull long decref(Ref *r); /* returns 0 iff value is now zero */
69 b2cfc4e2 2003-09-30 devnull void incref(Ref *r);
70 b2cfc4e2 2003-09-30 devnull int nbrecv(Channel *c, void *v);
71 b2cfc4e2 2003-09-30 devnull void* nbrecvp(Channel *c);
72 b2cfc4e2 2003-09-30 devnull unsigned long nbrecvul(Channel *c);
73 b2cfc4e2 2003-09-30 devnull int nbsend(Channel *c, void *v);
74 b2cfc4e2 2003-09-30 devnull int nbsendp(Channel *c, void *v);
75 b2cfc4e2 2003-09-30 devnull int nbsendul(Channel *c, unsigned long v);
76 b2cfc4e2 2003-09-30 devnull int proccreate(void (*f)(void *arg), void *arg, unsigned int stacksize);
77 b2cfc4e2 2003-09-30 devnull int procrfork(void (*f)(void *arg), void *arg, unsigned int stacksize, int flag);
78 b2cfc4e2 2003-09-30 devnull void** procdata(void);
79 b2cfc4e2 2003-09-30 devnull void procexec(Channel *, char *, char *[]);
80 b2cfc4e2 2003-09-30 devnull void procexecl(Channel *, char *, ...);
81 b2cfc4e2 2003-09-30 devnull int recv(Channel *c, void *v);
82 b2cfc4e2 2003-09-30 devnull void* recvp(Channel *c);
83 b2cfc4e2 2003-09-30 devnull unsigned long recvul(Channel *c);
84 b2cfc4e2 2003-09-30 devnull int send(Channel *c, void *v);
85 b2cfc4e2 2003-09-30 devnull int sendp(Channel *c, void *v);
86 b2cfc4e2 2003-09-30 devnull int sendul(Channel *c, unsigned long v);
87 b2cfc4e2 2003-09-30 devnull int threadcreate(void (*f)(void *arg), void *arg, unsigned int stacksize);
88 b2cfc4e2 2003-09-30 devnull void** threaddata(void);
89 b2cfc4e2 2003-09-30 devnull void threadexits(char *);
90 b2cfc4e2 2003-09-30 devnull void threadexitsall(char *);
91 b2cfc4e2 2003-09-30 devnull int threadgetgrp(void); /* return thread group of current thread */
92 b2cfc4e2 2003-09-30 devnull char* threadgetname(void);
93 b2cfc4e2 2003-09-30 devnull void threadint(int); /* interrupt thread */
94 b2cfc4e2 2003-09-30 devnull void threadintgrp(int); /* interrupt threads in grp */
95 b2cfc4e2 2003-09-30 devnull void threadkill(int); /* kill thread */
96 b2cfc4e2 2003-09-30 devnull void threadkillgrp(int); /* kill threads in group */
97 b2cfc4e2 2003-09-30 devnull void threadmain(int argc, char *argv[]);
98 b2cfc4e2 2003-09-30 devnull void threadnonotes(void);
99 b2cfc4e2 2003-09-30 devnull int threadnotify(int (*f)(void*, char*), int in);
100 b2cfc4e2 2003-09-30 devnull int threadid(void);
101 b2cfc4e2 2003-09-30 devnull int threadpid(int);
102 b2cfc4e2 2003-09-30 devnull int threadsetgrp(int); /* set thread group, return old */
103 b2cfc4e2 2003-09-30 devnull void threadsetname(char *name);
104 b2cfc4e2 2003-09-30 devnull Channel* threadwaitchan(void);
105 b2cfc4e2 2003-09-30 devnull int tprivalloc(void);
106 b2cfc4e2 2003-09-30 devnull void tprivfree(int);
107 b2cfc4e2 2003-09-30 devnull void **tprivaddr(int);
108 b2cfc4e2 2003-09-30 devnull void yield(void);
109 b2cfc4e2 2003-09-30 devnull
110 b2cfc4e2 2003-09-30 devnull long threadstack(void);
111 b2cfc4e2 2003-09-30 devnull
112 b2cfc4e2 2003-09-30 devnull extern int mainstacksize;
113 b2cfc4e2 2003-09-30 devnull
114 b2cfc4e2 2003-09-30 devnull /* slave I/O processes */
115 b2cfc4e2 2003-09-30 devnull typedef struct Ioproc Ioproc;
116 b2cfc4e2 2003-09-30 devnull
117 b2cfc4e2 2003-09-30 devnull Ioproc* ioproc(void);
118 b2cfc4e2 2003-09-30 devnull void closeioproc(Ioproc*);
119 b2cfc4e2 2003-09-30 devnull void iointerrupt(Ioproc*);
120 b2cfc4e2 2003-09-30 devnull
121 b2cfc4e2 2003-09-30 devnull int ioclose(Ioproc*, int);
122 b2cfc4e2 2003-09-30 devnull int iodial(Ioproc*, char*, char*, char*, int*);
123 b2cfc4e2 2003-09-30 devnull int ioopen(Ioproc*, char*, int);
124 b2cfc4e2 2003-09-30 devnull long ioread(Ioproc*, int, void*, long);
125 b2cfc4e2 2003-09-30 devnull long ioreadn(Ioproc*, int, void*, long);
126 b2cfc4e2 2003-09-30 devnull long iowrite(Ioproc*, int, void*, long);
127 b2cfc4e2 2003-09-30 devnull int iosleep(Ioproc*, long);
128 b2cfc4e2 2003-09-30 devnull
129 b2cfc4e2 2003-09-30 devnull long iocall(Ioproc*, long (*)(va_list*), ...);
130 b2cfc4e2 2003-09-30 devnull void ioret(Ioproc*, int);
131 b2cfc4e2 2003-09-30 devnull
132 b2cfc4e2 2003-09-30 devnull #endif /* _THREADH_ */