Blame


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