-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy paththreading.h
More file actions
60 lines (52 loc) · 1.07 KB
/
threading.h
File metadata and controls
60 lines (52 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <pthread.h>
#define nil NULL
typedef unsigned char uchar;
typedef unsigned int uint;
typedef struct Lock Lock;
struct Lock
{
int init;
pthread_mutex_t mutex;
};
void lock(Lock *lk);
int canlock(Lock *lk);
void unlock(Lock *lk);
typedef struct Rendez Rendez;
struct Rendez
{
int init;
Lock *l;
pthread_cond_t cond;
};
void rsleep(Rendez *r);
void rwakeup(Rendez *r);
void rwakeupall(Rendez *r);
typedef struct Channel Channel;
struct Channel
{
int bufsize;
int elemsize;
uchar *buf;
int nbuf;
int off;
int closed;
Lock lock;
Rendez full, empty;
};
Channel *chancreate(int elemsize, int bufsize);
void chanclose(Channel *chan);
void chanfree(Channel *c);
int chansend(Channel *c, void *p);
int chanrecv(Channel *c, void *p);
int channbsend(Channel *c, void *p);
int channbrecv(Channel *c, void *p);
int threadmain(int argc, char *argv[]);
int threadcreate(void *(*f)(void*), void *arg);
void threadexits(void *ret);
int threadid(void);
void **threaddata(void);
void threadkill(int id);
void threadwait(int id);