-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCQueue.h
58 lines (44 loc) · 1.09 KB
/
CQueue.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
/****************************************************\
CQueue.h
功能:C语言实现的循环队列
日期:2009年3月5日
版本:V1.0
作者:郭盖华
\****************************************************/
#ifndef __CQUEUE__
#define __CQUEUE__
#define MAX_QUEUE_SIZE 17
typedef int q_int;
#define __QUEUE_LOCK__
#ifdef __QUEUE_LOCK__
#include <RTL.h>
#endif
//typedef void* QUEUE_ELEMENT
typedef void* QUEUE_ELEMENT;
typedef struct Queue
{
q_int head;
q_int tail;
QUEUE_ELEMENT pBuf[MAX_QUEUE_SIZE];
q_int maxsize;
#ifdef __QUEUE_LOCK__
OS_MUT mutex;
#endif
}Queue;
#ifdef __QUEUE_LOCK__
#define QUEUE_CREATELOCK(x) os_mut_init(x->mutex)
#define QUEUE_RELEASELOCK(x)
#define QUEUE_LOCK(x) os_mut_wait(x->mutex,0xFFFF)
#define QUEUE_ULOCK(x) os_mut_release(x->mutex)
#else
#define QUEUE_CREATELOCK(x)
#define QUEUE_RELEASELOCK(x)
#define QUEUE_LOCK(x)
#define QUEUE_ULOCK(x)
#endif
void InitialQueue(Queue *queue);
void ReleaseQueue(Queue *queue);
q_int QueuePush(Queue *queue, QUEUE_ELEMENT buf);
QUEUE_ELEMENT QueuePop(Queue *queue);
q_int QueueSize(Queue *queue);
#endif