checking in working system
[IRC.git] / Robust / src / Runtime / Queue.c
1 #include "mem.h"
2 #include "Queue.h"
3
4 struct Queue * createQueue() {
5   return RUNMALLOC(sizeof(struct Queue));
6 }
7
8 int isEmpty(struct Queue *queue) {
9   return queue->head==NULL;
10 }
11
12 struct QueueItem * addNewItem(struct Queue * queue, void * ptr) {
13   struct QueueItem * item=RUNMALLOC(sizeof(struct QueueItem));
14   item->objectptr=ptr;
15   item->queue=queue;
16   if (queue->head==NULL) {
17     queue->head=item;
18     queue->tail=item;
19   } else {
20     item->next=queue->head;
21     queue->head->prev=item;
22     queue->head=item;
23   }
24   return item;
25 }
26
27 void removeItem(struct Queue * queue, struct QueueItem * item) {
28   struct QueueItem * prev=item->prev;
29   struct QueueItem * next=item->next;
30   if (queue->head==item)
31     queue->head=next;
32   else
33     prev->next=next;
34   if (queue->tail==item)
35     queue->tail=prev;
36   else
37     next->prev=prev;
38   RUNFREE(item);
39 }
40
41 struct QueueItem * getTail(struct Queue * queue) {
42   return queue->tail;
43 }
44
45 struct QueueItem * getNext(struct QueueItem * qi) {
46   return qi->next;
47 }