1 /*
2  * Queue header file
3  * Copyright (C) 2006 Unix Solutions Ltd.
4  *
5  * Released under MIT license.
6  * See LICENSE-MIT.txt for license terms.
7  */
8 #ifndef QUEUE_H
9 # define QUEUE_H
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 #include <pthread.h>
16 
17 typedef struct QNODE {
18 	struct QNODE *next;
19 	void *data;
20 } QNODE;
21 
22 typedef struct QUEUE {
23 	QNODE *head;
24 	QNODE *tail;
25 	pthread_mutex_t *mutex;	// queue's mutex.
26 	pthread_cond_t  *cond;	// queue's condition variable.
27 	int items;				// number of messages in queue
28 } QUEUE;
29 
30 QUEUE *queue_new		(void);
31 void queue_free			(QUEUE **q);
32 
33 void queue_add			(QUEUE *q, void *data);
34 void *queue_get			(QUEUE *q);
35 void *queue_get_nowait	(QUEUE *q);
36 void queue_wakeup		(QUEUE *q);
37 
38 #ifdef __cplusplus
39 }
40 #endif
41 
42 #endif
43