00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef CTRUMP_COMMON_QUEUE_H
00032 #define CTRUMP_COMMON_QUEUE_H
00033
00039 #include "ctrump/common/dll.h"
00040 #include <stddef.h>
00041
00042 #ifdef __cplusplus
00043 extern "C" {
00044 #endif
00045
00046 struct ctrump_mempool;
00047
00048
00052 struct ctrump_queue {
00053 size_t size;
00054 size_t elem_size;
00055 void *elements;
00056 unsigned int head;
00057 unsigned int tail;
00058 unsigned int rem;
00059 };
00060
00067 #define QUEUE_PUSH(t,q,e) \
00068 do { \
00069 if ((q)->rem==0) \
00070 ctrump_queue_realloc(q); \
00071 \
00072 ((t*)(q)->elements)[(q)->head] = (e); \
00073 (q)->rem --; \
00074 (q)->head ++; \
00075 if ((q)->head == (q)->size) \
00076 (q)->head = 0; \
00077 } while(0)
00078
00086 #define QUEUE_PUSH_PTR(t,q,dest) \
00087 do { \
00088 if ((q)->rem==0) \
00089 ctrump_queue_realloc(q); \
00090 \
00091 dest = &((t*)(q)->elements)[(q)->head]; \
00092 (q)->rem --; \
00093 (q)->head ++; \
00094 if ((q)->head == (q)->size) \
00095 (q)->head = 0; \
00096 } while(0)
00097
00104 #define QUEUE_POP(t,q,dest) \
00105 do { \
00106 (dest) = ((t*)(q)->elements)[(q)->tail]; \
00107 (q)->tail++; \
00108 (q)->rem++; \
00109 if ((q)->tail == (q)->size) \
00110 (q)->tail = 0; \
00111 } while (0)
00112
00119 CTRUMP_EXTDEF void ctrump_queue_init(struct ctrump_queue *q, size_t nelem, size_t elem_size);
00120
00125 CTRUMP_EXTDEF void ctrump_queue_realloc(struct ctrump_queue *q);
00126
00131 CTRUMP_EXTDEF void ctrump_queue_destroy(struct ctrump_queue *q);
00132
00133 #ifdef __cplusplus
00134 }
00135 #endif
00136
00137 #endif