1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  */
4 /***
5 * cqueue.h - c circle queue c header
6 */
7 
8 #ifndef C_QUEUE_H
9 #define C_QUEUE_H 1
10 
11 #if defined(__cplusplus)
12 extern "C" {
13 #endif
14 
15 enum {
16     CQ_OK = 0,
17     CQ_ERR,
18 };
19 
20 typedef unsigned char CQItemType;
21 
22 typedef struct __CQueue
23 {
24     int read;
25     int write;
26     int size;
27     int len;
28     CQItemType *base;
29 }CQueue;
30 
31 /* Init Queue */
32 int InitCQueue(CQueue *Q, unsigned int size, CQItemType *buf);
33 /* Is Queue Empty */
34 int IsEmptyCQueue(CQueue *Q);
35 /* Filled Length Of Queue */
36 int LengthOfCQueue(CQueue *Q);
37 /* Empty Length Of Queue */
38 int AvailableOfCQueue(CQueue *Q);
39 /* Push Data Into Queue (Tail) */
40 int EnCQueue(CQueue *Q, CQItemType *e, unsigned int len);
41 /* Push Data Into Queue (Tail) */
42 int EnCQueue_AI(CQueue *Q, CQItemType *e, unsigned int len);
43 /* Push Data Into Front Of Queue */
44 int EnCQueueFront(CQueue *Q, CQItemType *e, unsigned int len);
45 /* Pop Data Data From Queue (Front) */
46 int DeCQueue(CQueue *Q, CQItemType *e, unsigned int len);
47 /* Peek But Not Pop Data From Queue (Front) */
48 int PeekCQueue(CQueue *Q, unsigned int len_want, CQItemType **e1, unsigned int *len1, CQItemType **e2, unsigned int *len2);
49 /* Peek data to buf e, But Not Pop Data From Queue (Front) */
50 int PeekCQueueToBuf(CQueue *Q, CQItemType *e, unsigned int len);
51 int PullCQueue(CQueue *Q, CQItemType *e, unsigned int len);
52 /* Dump Queue */
53 int DumpCQueue(CQueue *Q);
54 
55 void ResetCqueue(CQueue *Q);
56 
57 #if defined(__cplusplus)
58 }
59 #endif
60 
61 #endif /* C_QUEUE_H */
62