From 1a9c97fb00e96c7f55528e5b63e21e5106a1a038 Mon Sep 17 00:00:00 2001 From: jjenista Date: Wed, 5 Aug 2009 00:12:01 +0000 Subject: [PATCH] added peek functions --- Robust/src/Runtime/Queue.c | 36 ++++++++++++++++++++++++------------ Robust/src/Runtime/Queue.h | 18 ++++++++++++------ 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/Robust/src/Runtime/Queue.c b/Robust/src/Runtime/Queue.c index adb35e8d..ff4dba8a 100644 --- a/Robust/src/Runtime/Queue.c +++ b/Robust/src/Runtime/Queue.c @@ -73,6 +73,18 @@ struct QueueItem * addNewItem_I(struct Queue * queue, void * ptr) { } #endif +struct QueueItem * getTail(struct Queue * queue) { + return queue->tail; +} + +struct QueueItem * getHead(struct Queue * queue) { + return queue->head; +} + +struct QueueItem * getNextQueueItem(struct QueueItem * qi) { + return qi->next; +} + struct QueueItem * findItem(struct Queue * queue, void *ptr) { struct QueueItem * item=queue->head; while(item!=NULL) { @@ -97,18 +109,6 @@ void removeItem(struct Queue * queue, struct QueueItem * item) { RUNFREE(item); } -struct QueueItem * getTail(struct Queue * queue) { - return queue->tail; -} - -struct QueueItem * getHead(struct Queue * queue) { - return queue->head; -} - -struct QueueItem * getNextQueueItem(struct QueueItem * qi) { - return qi->next; -} - void * getItem(struct Queue * queue) { struct QueueItem * q=queue->head; void * ptr=q->objectptr; @@ -138,6 +138,18 @@ void * getItemBack(struct Queue * queue) { return ptr; } +void * peekItem(struct Queue * queue) { + struct QueueItem * q=queue->head; + void * ptr=q->objectptr; + return ptr; +} + +void * peekItemBack(struct Queue * queue) { + struct QueueItem * q=queue->tail; + void * ptr=q->objectptr; + return ptr; +} + #ifdef DEBUG_QUEUE int assertQueue(struct Queue * queue) { diff --git a/Robust/src/Runtime/Queue.h b/Robust/src/Runtime/Queue.h index 2e11bc64..d0617e28 100644 --- a/Robust/src/Runtime/Queue.h +++ b/Robust/src/Runtime/Queue.h @@ -15,22 +15,28 @@ struct QueueItem { #define isEmpty(x) ((x)->head==NULL) -void * getItem(struct Queue * queue); -void freeQueue(struct Queue * q); struct Queue * createQueue(); +void freeQueue(struct Queue * q); + struct QueueItem * addNewItem(struct Queue * queue, void * ptr); +struct QueueItem * addNewItemBack(struct Queue * queue, void * ptr); #ifdef MULTICORE struct QueueItem * addNewItem_I(struct Queue * queue, void * ptr); #endif -struct QueueItem * findItem(struct Queue * queue, void * ptr); -void removeItem(struct Queue * queue, struct QueueItem * item); + struct QueueItem * getTail(struct Queue * queue); struct QueueItem * getHead(struct Queue * queue); struct QueueItem * getNextQueueItem(struct QueueItem * qi); -// to implement a double-ended queue +struct QueueItem * findItem(struct Queue * queue, void * ptr); + +void removeItem(struct Queue * queue, struct QueueItem * item); + +void * getItem(struct Queue * queue); void * getItemBack(struct Queue * queue); -struct QueueItem * addNewItemBack(struct Queue * queue, void * ptr); + +void * peekItem(struct Queue * queue); +void * peekItemBack(struct Queue * queue); // for debugging, only included if macro is defined -- 2.34.1