X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/1b8b7ec966d302f6a49ec6fc84c5afca7901dfcd..169edc40a9d6aac50da8647a98df1e2b7cd92727:/src/xbt/fifo.c diff --git a/src/xbt/fifo.c b/src/xbt/fifo.c index 3ea147bfaf..2cd4f79d9c 100644 --- a/src/xbt/fifo.c +++ b/src/xbt/fifo.c @@ -9,7 +9,7 @@ #include "xbt/log.h" #include "fifo_private.h" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(fifo,xbt,"FIFO"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_fifo,xbt,"FIFO"); /** Constructor * \return a new fifo @@ -119,6 +119,7 @@ void *xbt_fifo_shift(xbt_fifo_t l) */ void xbt_fifo_push_item(xbt_fifo_t l, xbt_fifo_item_t new) { + xbt_assert0((new->next == NULL)&&(new->prev == NULL),"Invalid item!"); (l->count)++; if (l->head == NULL) { l->head = new; @@ -144,7 +145,7 @@ xbt_fifo_item_t xbt_fifo_pop_item(xbt_fifo_t l) return NULL; item = l->tail; - + l->tail = item->prev; if (l->tail == NULL) l->head = NULL; @@ -152,6 +153,9 @@ xbt_fifo_item_t xbt_fifo_pop_item(xbt_fifo_t l) l->tail->next = NULL; (l->count)--; + + item->prev = NULL; + return item; } @@ -163,6 +167,7 @@ xbt_fifo_item_t xbt_fifo_pop_item(xbt_fifo_t l) */ void xbt_fifo_unshift_item(xbt_fifo_t l, xbt_fifo_item_t new) { + xbt_assert0((new->next == NULL)&&(new->prev == NULL),"Invalid item!"); (l->count)++; if (l->head == NULL) { l->head = new; @@ -197,6 +202,9 @@ xbt_fifo_item_t xbt_fifo_shift_item(xbt_fifo_t l) l->head->prev = NULL; (l->count)--; + + item->next = NULL; + return item; } @@ -229,28 +237,32 @@ void xbt_fifo_remove(xbt_fifo_t l, void *t) * \param l a list * \param current a bucket * - * removes a the bucket \a current from the list \a l + * removes a bucket \a current from the list \a l. This function implicitely + * assumes (and doesn't check!) that this item belongs to this list... */ void xbt_fifo_remove_item(xbt_fifo_t l, xbt_fifo_item_t current) { if (l->head == l->tail) { /* special case */ - l->head = NULL; - l->tail = NULL; - (l->count)--; - return; - } - - if (current == l->head) { /* It's the head */ - l->head = current->next; - l->head->prev = NULL; - } else if (current == l->tail) { /* It's the tail */ - l->tail = current->prev; - l->tail->next = NULL; - } else { /* It's in the middle */ - current->prev->next = current->next; - current->next->prev = current->prev; - } + xbt_assert0((current==l->head),"This item is not in the list!"); + l->head = NULL; + l->tail = NULL; (l->count)--; + current->prev = current->next = NULL; + return; + } + + if (current == l->head) { /* It's the head */ + l->head = current->next; + l->head->prev = NULL; + } else if (current == l->tail) { /* It's the tail */ + l->tail = current->prev; + l->tail->next = NULL; + } else { /* It's in the middle */ + current->prev->next = current->next; + current->next->prev = current->prev; + } + (l->count)--; + current->prev = current->next = NULL; } /**