00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CUCON_QUEUE_H
00019 #define CUCON_QUEUE_H
00020
00021 #include <cucon/fwd.h>
00022 #include <cu/diag.h>
00023
00024 CU_BEGIN_DECLARATIONS
00025
00026
00027
00028 struct cucon_queue_node
00029 {
00030 struct cucon_queue_node *next;
00031 char *begin;
00032 char *end;
00033 };
00034
00035 typedef struct cucon_queue *cucon_queue_t;
00036 struct cucon_queue
00037 {
00038 char *front_cur;
00039 struct cucon_queue_node *front;
00040 struct cucon_queue_node *back;
00041 char *back_cap_end;
00042 };
00043
00044 void cucon_queue_init(cucon_queue_t q);
00045 cucon_queue_t cucon_queue_new(void);
00046
00047 CU_SINLINE cu_bool_fast_t
00048 cucon_queue_is_empty(cucon_queue_t q)
00049 {
00050 return q->front_cur == q->back->end;
00051 }
00052
00053 void cuconP_queue_pop_mem(cucon_queue_t q);
00054 void *cuconP_queue_push_mem(cucon_queue_t q, size_t size);
00055
00056
00057
00058 CU_SINLINE void *
00059 cucon_queue_push_mem(cucon_queue_t q, size_t size)
00060 {
00061 char *tmp = q->back->end;
00062 if ((q->back->end += size) > q->back_cap_end)
00063 return cuconP_queue_push_mem(q, size);
00064 else
00065 return tmp;
00066 }
00067
00068
00069 #define cucon_queue_front_mem(q) ((void*)CU_MARG(cucon_queue_t, q)->front_cur)
00070
00071
00072 CU_SINLINE void
00073 cucon_queue_pop_mem(cucon_queue_t q, size_t size)
00074 {
00075 #ifndef CU_NDEBUG
00076 if (q->front_cur == NULL && size != 0)
00077 cu_bugf("cucon_queue_pop_mem called on empty queue.");
00078 #endif
00079 q->front_cur += size;
00080 if (q->front_cur >= q->front->end)
00081 cuconP_queue_pop_mem(q);
00082 }
00083
00084 #define cucon_queue_front_ptr(q) (*(void **)cucon_queue_front_mem(q))
00085 #define cucon_queue_pop_ptr(q) cucon_queue_pop_mem(q, sizeof(void *))
00086 #define cucon_queue_push_ptr(q, ptr) \
00087 ((void)(*(void **)cucon_queue_push_mem(q, sizeof(void *)) = (ptr)))
00088
00089 CU_END_DECLARATIONS
00090 #endif