1 #pragma src "/sys/src/libthread"
2 #pragma lib "libthread.a"
4 #pragma varargck argpos chanprint 2
6 typedef struct Alt Alt;
7 typedef struct Channel Channel;
8 typedef struct Ref Ref;
11 * Channel structure. S is the size of the buffer. For unbuffered channels
12 * s is zero. v is an array of s values. If s is zero, v is unused.
13 * f and n represent the state of the queue pointed to by v.
18 Nqshift = 5, /* logâ‚‚ # of bits in long */
20 Nqbits = (1 << Nqshift) * 2,
24 int s; /* Size of the channel (may be zero) */
25 uint f; /* Extraction point (insertion pt: (f+n) % s) */
26 uint n; /* Number of values in the channel */
27 int e; /* Element size */
28 int freed; /* Set when channel is being deleted */
29 volatile Alt **qentry; /* Receivers/senders waiting (malloc) */
30 volatile int nentry; /* # of entries malloc-ed */
31 volatile int closed; /* channel is closed */
32 uchar v[1]; /* Array of s values in the channel */
36 /* Channel operations for alt: */
46 Channel *c; /* channel */
47 void *v; /* pointer to value */
48 ChanOp op; /* operation */
49 char *err; /* did the op fail? */
51 * the next variables are used internally to alt
52 * they need not be initialized
54 Channel **tag; /* pointer to rendez-vous tag */
55 int entryno; /* entry number */
63 int chanclose(Channel*);
64 int chanclosing(Channel *c);
65 Channel*chancreate(int elemsize, int bufsize);
66 void chanfree(Channel *c);
67 int chanprint(Channel *, char *, ...);
68 long decref(Ref *r); /* returns 0 iff value is now zero */
70 int nbrecv(Channel *c, void *v);
71 void* nbrecvp(Channel *c);
72 ulong nbrecvul(Channel *c);
73 int nbsend(Channel *c, void *v);
74 int nbsendp(Channel *c, void *v);
75 int nbsendul(Channel *c, ulong v);
77 int proccreate(void (*f)(void *arg), void *arg, uint stacksize);
78 int procrfork(void (*f)(void *arg), void *arg, uint stacksize, int flag);
79 void** procdata(void);
80 void procexec(Channel *, char *, char *[]);
81 void procexecl(Channel *, char *, ...);
82 int recv(Channel *c, void *v);
83 void* recvp(Channel *c);
84 ulong recvul(Channel *c);
85 int send(Channel *c, void *v);
86 int sendp(Channel *c, void *v);
87 int sendul(Channel *c, ulong v);
88 int threadcreate(void (*f)(void *arg), void *arg, uint stacksize);
89 void** threaddata(void);
90 void threadexits(char *);
91 void threadexitsall(char *);
92 int threadgetgrp(void); /* return thread group of current thread */
93 char* threadgetname(void);
94 void threadint(int); /* interrupt thread */
95 void threadintgrp(int); /* interrupt threads in grp */
96 void threadkill(int); /* kill thread */
97 void threadkillgrp(int); /* kill threads in group */
98 void threadmain(int argc, char *argv[]);
99 void threadnonotes(void);
100 int threadnotify(int (*f)(void*, char*), int in);
103 int threadsetgrp(int); /* set thread group, return old */
104 void threadsetname(char *fmt, ...);
105 Channel*threadwaitchan(void);
108 #pragma varargck argpos threadsetname 1
110 extern int mainstacksize;
112 /* slave I/O processes */
113 typedef struct Ioproc Ioproc;
115 #pragma incomplete Ioproc
118 Ioproc* ioproc(void);
119 void closeioproc(Ioproc*);
120 void iointerrupt(Ioproc*);
122 int ioclose(Ioproc*, int);
123 int iodial(Ioproc*, char*, char*, char*, int*);
124 int ioopen(Ioproc*, char*, int);
125 long ioread(Ioproc*, int, void*, long);
126 long ioreadn(Ioproc*, int, void*, long);
127 long iowrite(Ioproc*, int, void*, long);
128 int iosleep(Ioproc*, long);
129 int ioflush(Ioproc*);
131 long iocall(Ioproc*, long (*)(va_list*), ...);