-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathring_buffer.h
58 lines (47 loc) · 1017 Bytes
/
ring_buffer.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/***
*
* Multi-threaded limited circular buffer,
* with one producer and one consumer.
*
**/
/*
* ring buffer handle used to keep a pointer to the ring buffer instance
* */
typedef void* rbhandle_t;
/**
* Compare two ring buffer items
*
* Returns:
* 0 if entries are equal
* 1 if *e1 > *e2
* -1 if *e1 < *e2
*/
typedef int (*ecomp_t) (void* e1, void* e2);
/**
* Create a new ring buffer instance
*/
rbhandle_t
RBufferCreate(int buf_size, ecomp_t comp, int entry_size);
/**
* Insert new entry to the ring buffer
*/
int
RBufferInsert(rbhandle_t h, void* e);
/**
* Get an entry from the ring buffer
* Blocking call. It waits for new entry if the buffer is empty
*/
int
RBufferGet(rbhandle_t h, void** e);
/**
* Get an entry from the ring buffer
* Non-blocking call. Returns immediatelly if buffer is empty
*/
int
RBufferTryGet(rbhandle_t h, void** e);
/**
* Destroy the ring buffer
*
*/
void
RBufferDestroy(rbhandle_t h);