X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=Robust%2Fsrc%2FRuntime%2FQueue.c;h=3429dc6bffd0aea2ecdbe97f576392705b9326c1;hb=76263fb08dca40e3c50ec9403ff4ddd02c35bfe1;hp=ff4dba8a7dcf77889e7c86833417d4babe474a30;hpb=1a9c97fb00e96c7f55528e5b63e21e5106a1a038;p=IRC.git diff --git a/Robust/src/Runtime/Queue.c b/Robust/src/Runtime/Queue.c index ff4dba8a..3429dc6b 100644 --- a/Robust/src/Runtime/Queue.c +++ b/Robust/src/Runtime/Queue.c @@ -16,6 +16,11 @@ struct Queue * createQueue() { return queue; } +void initQueue(struct Queue * q) { + q->head=NULL; + q->tail=NULL; +} + void freeQueue(struct Queue * q) { RUNFREE(q); } @@ -57,6 +62,13 @@ struct QueueItem * addNewItemBack(struct Queue * queue, void * ptr) { } #ifdef MULTICORE +struct Queue * createQueue_I() { + struct Queue * queue = (struct Queue *)RUNMALLOC_I(sizeof(struct Queue)); + queue->head = NULL; + queue->tail = NULL; + return queue; +} + struct QueueItem * addNewItem_I(struct Queue * queue, void * ptr) { struct QueueItem * item=RUNMALLOC_I(sizeof(struct QueueItem)); item->objectptr=ptr; @@ -119,7 +131,7 @@ void * getItem(struct Queue * queue) { } queue->head=q->next; if(queue->tail == q) { - queue->tail = NULL; + queue->tail = NULL; } RUNFREE(q); return ptr; @@ -150,6 +162,17 @@ void * peekItemBack(struct Queue * queue) { return ptr; } +void clearQueue(struct Queue * queue) { + struct QueueItem * item=queue->head; + while(item!=NULL) { + struct QueueItem * next=item->next; + RUNFREE(item); + item=next; + } + queue->head=queue->tail=NULL; + return; +} + #ifdef DEBUG_QUEUE int assertQueue(struct Queue * queue) { @@ -170,7 +193,7 @@ int assertQueue(struct Queue * queue) { return 0; } - // i->prev != NULL + // i->prev != NULL } else { if( i->prev->next == NULL ) { return 0; @@ -184,7 +207,7 @@ int assertQueue(struct Queue * queue) { return 0; } - // i->next != NULL + // i->next != NULL } else { if( i->next->prev == NULL ) { return 0; @@ -207,8 +230,8 @@ void printQueue(struct Queue * queue) { struct QueueItem* i; printf("Queue empty? %d\n", isEmpty(queue)); - - printf("head "); + + printf("head "); i = queue->head; while( i != NULL ) { printf("item ");