12 struct Queue * createQueue() {
13 struct Queue * queue = (struct Queue *)RUNMALLOC(sizeof(struct Queue));
19 void freeQueue(struct Queue * q) {
23 struct QueueItem * addNewItem(struct Queue * queue, void * ptr) {
24 struct QueueItem * item=RUNMALLOC(sizeof(struct QueueItem));
27 if (queue->head==NULL) {
33 item->next=queue->head;
35 queue->head->prev=item;
41 struct QueueItem * addNewItemBack(struct Queue * queue, void * ptr) {
42 struct QueueItem * item=RUNMALLOC(sizeof(struct QueueItem));
45 if (queue->tail==NULL) {
51 item->prev=queue->tail;
53 queue->tail->next=item;
60 struct Queue * createQueue_I() {
61 struct Queue * queue = (struct Queue *)RUNMALLOC_I(sizeof(struct Queue));
67 struct QueueItem * addNewItem_I(struct Queue * queue, void * ptr) {
68 struct QueueItem * item=RUNMALLOC_I(sizeof(struct QueueItem));
71 if (queue->head==NULL) {
75 item->next=queue->head;
76 queue->head->prev=item;
83 struct QueueItem * getTail(struct Queue * queue) {
87 struct QueueItem * getHead(struct Queue * queue) {
91 struct QueueItem * getNextQueueItem(struct QueueItem * qi) {
95 struct QueueItem * findItem(struct Queue * queue, void *ptr) {
96 struct QueueItem * item=queue->head;
98 if (item->objectptr==ptr)
105 void removeItem(struct Queue * queue, struct QueueItem * item) {
106 struct QueueItem * prev=item->prev;
107 struct QueueItem * next=item->next;
108 if (queue->head==item)
112 if (queue->tail==item)
119 void * getItem(struct Queue * queue) {
120 struct QueueItem * q=queue->head;
121 void * ptr=q->objectptr;
122 if(queue->tail==queue->head) {
128 if(queue->tail == q) {
135 void * getItemBack(struct Queue * queue) {
136 struct QueueItem * q=queue->tail;
137 void * ptr=q->objectptr;
138 if(queue->head==queue->tail) {
148 void * peekItem(struct Queue * queue) {
149 struct QueueItem * q=queue->head;
150 void * ptr=q->objectptr;
154 void * peekItemBack(struct Queue * queue) {
155 struct QueueItem * q=queue->tail;
156 void * ptr=q->objectptr;
160 void clearQueue(struct Queue * queue) {
161 struct QueueItem * item=queue->head;
163 struct QueueItem * next=item->next;
167 queue->head=queue->tail=NULL;
172 int assertQueue(struct Queue * queue) {
174 struct QueueItem* i = queue->head;
176 if( i == NULL && queue->tail != NULL ) {
182 if( queue->head == i && i->prev != NULL ) {
186 if( i->prev == NULL ) {
187 if( queue->head != i ) {
193 if( i->prev->next == NULL ) {
195 } else if( i->prev->next != i ) {
200 if( i->next == NULL ) {
201 if( queue->tail != i ) {
207 if( i->next->prev == NULL ) {
209 } else if( i->next->prev != i ) {
214 if( queue->tail == i && i->next != NULL ) {
218 i = getNextQueueItem(i);
224 void printQueue(struct Queue * queue) {
227 printf("Queue empty? %d\n", isEmpty(queue));
233 i = getNextQueueItem(i);
237 printf("[%08x] ", (int)queue->head);
240 printf("[%08x] ", (int)i);
241 i = getNextQueueItem(i);
243 printf("[%08x]\n", (int)queue->tail);
248 printf("[%08x] ", (int)(i->next));
249 i = getNextQueueItem(i);
256 printf("[%08x] ", (int)(i->prev));
257 i = getNextQueueItem(i);