Blob


1 #ifndef _THREAD_H_
2 #define _THREAD_H_ 1
3 #if defined(__cplusplus)
4 extern "C" {
5 #endif
7 /*
8 * basic procs and threads
9 */
10 int proccreate(void (*f)(void *arg), void *arg, unsigned int stacksize);
11 int threadcreate(void (*f)(void *arg), void *arg, unsigned int stacksize);
12 void threadexits(char *);
13 void threadexitsall(char *);
14 void threadsetname(char*, ...);
15 void threadsetstate(char*, ...);
16 void threadyield(void);
17 void _threadready(_Thread*);
18 void _threadswitch(void);
19 void _threadsetsysproc(void);
20 void _threadsleep(Rendez*);
21 _Thread *_threadwakeup(Rendez*);
22 #define yield threadyield
24 /*
25 * per proc and thread data
26 */
27 void **procdata(void);
29 /*
30 * supplied by user instead of main.
31 * mainstacksize is size of stack allocated to run threadmain
32 */
33 void threadmain(int argc, char *argv[]);
34 extern int mainstacksize;
36 /*
37 * channel communication
38 */
39 typedef struct Alt Alt;
40 typedef struct _Altarray _Altarray;
41 typedef struct Channel Channel;
43 enum
44 {
45 CHANEND,
46 CHANSND,
47 CHANRCV,
48 CHANNOP,
49 CHANNOBLK,
50 };
52 struct Alt
53 {
54 void *v;
55 Channel *c;
56 uint op;
57 _Thread *thread;
58 Alt *xalt;
59 };
61 struct _Altarray
62 {
63 Alt **a;
64 uint n;
65 uint m;
66 };
68 struct Channel
69 {
70 uint bufsize;
71 uint elemsize;
72 uchar *buf;
73 uint nbuf;
74 uint off;
75 _Altarray asend;
76 _Altarray arecv;
77 char *name;
78 };
80 /* [Edit .+1,./^$/ |cfn -h $PLAN9/src/libthread/channel.c] */
81 int chanalt(Alt *alts);
82 Channel* chancreate(int elemsize, int elemcnt);
83 void chanfree(Channel *c);
84 int chaninit(Channel *c, int elemsize, int elemcnt);
85 int channbrecv(Channel *c, void *v);
86 void* channbrecvp(Channel *c);
87 ulong channbrecvul(Channel *c);
88 int channbsend(Channel *c, void *v);
89 int channbsendp(Channel *c, void *v);
90 int channbsendul(Channel *c, ulong v);
91 int chanrecv(Channel *c, void *v);
92 void* chanrecvp(Channel *c);
93 ulong chanrecvul(Channel *c);
94 int chansend(Channel *c, void *v);
95 int chansendp(Channel *c, void *v);
96 int chansendul(Channel *c, ulong v);
98 #define alt chanalt
99 #define nbrecv channbrecv
100 #define nbrecvp channbrecvp
101 #define nvrecvul channbrecvul
102 #define nbsend channbsend
103 #define nbsendp channbsendp
104 #define nbsendul channbsendul
105 #define recv chanrecv
106 #define recvp chanrecvp
107 #define recvul chanrecvul
108 #define send chansend
109 #define sendp chansendp
110 #define sendul chansendul
112 /*
113 * reference counts
114 */
115 typedef struct Ref Ref;
117 struct Ref {
118 Lock lock;
119 long ref;
120 };
122 long decref(Ref *r);
123 long incref(Ref *r);
125 /*
126 * slave i/o processes
127 */
128 typedef struct Ioproc Ioproc;
130 /* [Edit .+1,/^$/ |cfn -h $PLAN9/src/libthread/io*.c] */
131 void closeioproc(Ioproc *io);
132 long iocall(Ioproc *io, long (*op)(va_list*), ...);
133 int ioclose(Ioproc *io, int fd);
134 int iodial(Ioproc *io, char *addr, char *local, char *dir, int *cdfp);
135 void iointerrupt(Ioproc *io);
136 int ioopen(Ioproc *io, char *path, int mode);
137 Ioproc* ioproc(void);
138 long ioread(Ioproc *io, int fd, void *a, long n);
139 int ioread9pmsg(Ioproc*, int, void*, int);
140 long ioreadn(Ioproc *io, int fd, void *a, long n);
141 int iorecvfd(Ioproc *, int);
142 int iosendfd(Ioproc*, int, int);
143 int iosleep(Ioproc *io, long n);
144 long iowrite(Ioproc *io, int fd, void *a, long n);
146 /*
147 * exec external programs
148 */
149 void threadexec(Channel*, int[3], char*, char *[]);
150 void threadexecl(Channel*, int[3], char*, ...);
151 int threadspawn(int[3], char*, char*[]);
152 Channel* threadwaitchan(void);
154 #if defined(__cplusplus)
156 #endif
157 #endif /* _THREADH_ */