]> git.lizzy.rs Git - plan9front.git/blob - sys/include/thread.h
turn ptrdiff_t into a 64 bit type
[plan9front.git] / sys / include / thread.h
1 #pragma src "/sys/src/libthread"
2 #pragma lib "libthread.a"
3
4 #pragma varargck        argpos  chanprint       2
5
6 typedef struct Alt      Alt;
7 typedef struct Channel  Channel;
8 typedef struct Ref      Ref;
9
10 /*
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.
14  */
15
16 enum {
17         Nqwds = 2,
18         Nqshift = 5,            /* logâ‚‚ # of bits in long */
19         Nqmask =  -1,
20         Nqbits = (1 << Nqshift) * 2,
21 };
22
23 struct Channel {
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 */
33 };
34
35
36 /* Channel operations for alt: */
37 typedef enum {
38         CHANEND,
39         CHANSND,
40         CHANRCV,
41         CHANNOP,
42         CHANNOBLK,
43 } ChanOp;
44
45 struct Alt {
46         Channel *c;             /* channel */
47         void    *v;             /* pointer to value */
48         ChanOp  op;             /* operation */
49         char    *err;           /* did the op fail? */
50         /*
51          * the next variables are used internally to alt
52          * they need not be initialized
53          */
54         Channel **tag;          /* pointer to rendez-vous tag */
55         int     entryno;        /* entry number */
56 };
57
58 struct Ref {
59         long    ref;
60 };
61
62 int     alt(Alt alts[]);
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 */
69 void    incref(Ref *r);
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);
76 void    needstack(int);
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);
101 int     threadid(void);
102 int     threadpid(int);
103 int     threadsetgrp(int);              /* set thread group, return old */
104 void    threadsetname(char *fmt, ...);
105 Channel*threadwaitchan(void);
106 void    yield(void);
107
108 #pragma varargck        argpos  threadsetname   1
109
110 extern  int     mainstacksize;
111
112 /* slave I/O processes */
113 typedef struct Ioproc Ioproc;
114
115 #pragma incomplete Ioproc
116
117
118 Ioproc* ioproc(void);
119 void    closeioproc(Ioproc*);
120 void    iointerrupt(Ioproc*);
121
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*);
130
131 long    iocall(Ioproc*, long (*)(va_list*), ...);