-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchan.h
40 lines (29 loc) · 770 Bytes
/
chan.h
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
#ifndef CHAN_H
#define CHAN_H
#ifndef DEBUG_CHAN
#define DEBUG_CHAN 0
#endif
#ifndef IDCACHE_SIZE
#define IDCACHE_SIZE 10
#endif
#include "schedpool/threadpool.h"
typedef struct chan{
void** buffer;
int buf_head;
int pull_head;
int cap;
int id;
pthread_mutex_t lock; // lock for in/out operations
}chan;
static volatile int maxID = 0;
// ch_make creates a channel for data of type void*
// buffer specifies how many items this channel can allow
chan* ch_make(int buffer);
// ch_push adds a new item into the channel.
// and adding an item to a queue
void ch_push(chan* ch, void* item);
// ch_pull pulls an item from the channel and returns it to the caller
void* ch_pull(chan* ch);
// close a channel
void ch_close(chan* ch);
#endif