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 _threadready(_Thread*);
17 void _threadswitch(void);
18 void _threadsetsysproc(void);
19 void _threadsleep(Rendez*);
20 _Thread *_threadwakeup(Rendez*);
22 /*
23 * per proc and thread data
24 */
25 void **procdata(void);
27 /*
28 * supplied by user instead of main.
29 * mainstacksize is size of stack allocated to run threadmain
30 */
31 void threadmain(int argc, char *argv[]);
32 extern int mainstacksize;
34 /*
35 * channel communication
36 */
37 typedef struct Alt Alt;
38 typedef struct _Altarray _Altarray;
39 typedef struct Channel Channel;
41 enum
42 {
43 CHANEND,
44 CHANSND,
45 CHANRCV,
46 CHANNOP,
47 CHANNOBLK,
48 };
50 struct Alt
51 {
52 void *v;
53 Channel *c;
54 uint op;
55 _Thread *thread;
56 Alt *xalt;
57 };
59 struct _Altarray
60 {
61 Alt **a;
62 uint n;
63 uint m;
64 };
66 struct Channel
67 {
68 uint bufsize;
69 uint elemsize;
70 uchar *buf;
71 uint nbuf;
72 uint off;
73 _Altarray asend;
74 _Altarray arecv;
75 char *name;
76 };
78 /* [Edit .+1,./^$/ |cfn -h $PLAN9/src/libthread/channel.c] */
79 int chanalt(Alt *alts);
80 Channel* chancreate(int elemsize, int elemcnt);
81 void chanfree(Channel *c);
82 int chaninit(Channel *c, int elemsize, int elemcnt);
83 int channbrecv(Channel *c, void *v);
84 void* channbrecvp(Channel *c);
85 ulong channbrecvul(Channel *c);
86 int channbsend(Channel *c, void *v);
87 int channbsendp(Channel *c, void *v);
88 int channbsendul(Channel *c, ulong v);
89 int chanrecv(Channel *c, void *v);
90 void* chanrecvp(Channel *c);
91 ulong chanrecvul(Channel *c);
92 int chansend(Channel *c, void *v);
93 int chansendp(Channel *c, void *v);
94 int chansendul(Channel *c, ulong v);
96 #define alt chanalt
97 #define nbrecv channbrecv
98 #define nbrecvp channbrecvp
99 #define nvrecvul channbrecvul
100 #define nbsend channbsend
101 #define nbsendp channbsendp
102 #define nbsendul channbsendul
103 #define recv chanrecv
104 #define recvp chanrecvp
105 #define recvul chanrecvul
106 #define send chansend
107 #define sendp chansendp
108 #define sendul chansendul
110 /*
111 * reference counts
112 */
113 typedef struct Ref Ref;
115 struct Ref {
116 Lock lock;
117 long ref;
118 };
120 long decref(Ref *r);
121 long incref(Ref *r);
123 /*
124 * slave i/o processes
125 */
126 typedef struct Ioproc Ioproc;
128 /* [Edit .+1,/^$/ |cfn -h $PLAN9/src/libthread/io*.c] */
129 void closeioproc(Ioproc *io);
130 long iocall(Ioproc *io, long (*op)(va_list*), ...);
131 int ioclose(Ioproc *io, int fd);
132 int iodial(Ioproc *io, char *addr, char *local, char *dir, int *cdfp);
133 void iointerrupt(Ioproc *io);
134 int ioopen(Ioproc *io, char *path, int mode);
135 Ioproc* ioproc(void);
136 long ioread(Ioproc *io, int fd, void *a, long n);
137 int ioread9pmsg(Ioproc*, int, void*, int);
138 long ioreadn(Ioproc *io, int fd, void *a, long n);
139 int iorecvfd(Ioproc *, int);
140 int iosendfd(Ioproc*, int, int);
141 int iosleep(Ioproc *io, long n);
142 long iowrite(Ioproc *io, int fd, void *a, long n);
144 /*
145 * exec external programs
146 */
147 void threadexec(Channel*, int[3], char*, char *[]);
148 void threadexecl(Channel*, int[3], char*, ...);
149 int threadspawn(int[3], char*, char*[]);
150 Channel* threadwaitchan(void);
152 #if defined(__cplusplus)
154 #endif
155 #endif /* _THREADH_ */