-
Notifications
You must be signed in to change notification settings - Fork 5
/
ring_queue.h
55 lines (41 loc) · 914 Bytes
/
ring_queue.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
#ifndef __RING_QUEUE_H__
#define __RING_QUEUE_H__
/*
* ring queue
* for one producer and one consumer
*/
#include <pthread.h>
#include <string.h>
class Ring_queue
{
public:
Ring_queue(const int queue_size, const int entry_size);
~Ring_queue();
void make_empty();
/*
*put a product into the queue
* the caller will be blocked if queue is full.
*/
void put(const char* product);
/*
*pop a product from the queue
* the caller will be blocked if queue is empty.
*/
void pop(char* product);
private:
char** _queue;
int _qsize;
int _head;
int _tail;
/* condition variable,
it represents the number of product in the queue */
int _n_product;
pthread_cond_t _cond_n_product;
pthread_mutex_t _mutex_n_product;
/* condition variable,
it represents the number of space in the queue */
int _n_space;
pthread_cond_t _cond_n_space;
pthread_mutex_t _mutex_n_space;
};
#endif