HIPC  0.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
queue.c
Go to the documentation of this file.
1 #include <hipc/atomic.h>
2 #include <hipc/queue.h>
3 
12 void hipcQueueInit(struct HIPC_queue *const que_p,
13  void *const buf_p,
14  const size_t item_size, const size_t n_slot)
15 {
16  que_p->buf_p = buf_p;
17  que_p->item_size = item_size;
18  que_p->n_slot = n_slot;
19  que_p->head = 0;
20  que_p->tail = 0;
22 
23  return;
24 }
25 
32 size_t hipcQueueItemSize(struct HIPC_queue * const que_p)
33 {
34  return que_p->item_size;
35 }
36 
44 void *hipcQueueEmpty(struct HIPC_queue *const que_p)
45 {
46  if (que_p->head == que_p->tail) {
47  return NULL;
48  }
49 
50  return ((unsigned char *) (que_p->buf_p)) +
51  (que_p->head * que_p->item_size);
52 }
53 
61 void hipcQueuePop(struct HIPC_queue *const que_p)
62 {
64  que_p->head = (que_p->head + 1) % que_p->n_slot;
65 
66  return;
67 }
68 
76 void *hipcQueueFull(struct HIPC_queue const *const que_p)
77 {
78  if (que_p->head == ((que_p->tail + 1) % que_p->n_slot)) {
79  return NULL;
80  }
81 
82  return ((unsigned char *) que_p->buf_p) +
83  (que_p->tail * que_p->item_size);
84 }
85 
93 void hipcQueuePush(struct HIPC_queue *const que_p)
94 {
96  que_p->tail = (que_p->tail + 1) % que_p->n_slot;
97 
98  return;
99 }
100 
108 void hipcQueueClear(struct HIPC_queue *const que_p)
109 {
111  que_p->head = que_p->tail;
112 
113  return;
114 }
volatile size_t tail
Definition: queue.h:11
size_t hipcQueueItemSize(struct HIPC_queue *const que_p)
Gets item size.
Definition: queue.c:32
void * hipcQueueEmpty(struct HIPC_queue *const que_p)
Returns an address of the head item if it exists.
Definition: queue.c:44
size_t item_size
Definition: queue.h:8
void hipcQueueClear(struct HIPC_queue *const que_p)
Clears a queue.
Definition: queue.c:108
volatile size_t head
Definition: queue.h:10
#define HIPC_MEM_BARRIER
Definition: atomic.h:7
size_t n_slot
Definition: queue.h:9
void * hipcQueueFull(struct HIPC_queue const *const que_p)
Returns an address of an empty slot if it exists.
Definition: queue.c:76
void hipcQueuePush(struct HIPC_queue *const que_p)
Pushes an item and occupies a slot.
Definition: queue.c:93
void hipcQueueInit(struct HIPC_queue *const que_p, void *const buf_p, const size_t item_size, const size_t n_slot)
Initializes a queue.
Definition: queue.c:12
void hipcQueuePop(struct HIPC_queue *const que_p)
Pops an item and releases a slot.
Definition: queue.c:61
void * buf_p
Definition: queue.h:7