X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/8bd1d4d43b1cbdeec15247821932f6ca0971fd96..d9d29f9c45022aeb18af277c995291c0547bbc0d:/src/xbt/fifo.c diff --git a/src/xbt/fifo.c b/src/xbt/fifo.c index 399a8887fa..3f6714bc82 100644 --- a/src/xbt/fifo.c +++ b/src/xbt/fifo.c @@ -48,11 +48,15 @@ void xbt_fifo_free(xbt_fifo_t l) */ void xbt_fifo_reset(xbt_fifo_t l) { - xbt_fifo_item_t b, tmp; + xbt_fifo_item_t b = xbt_fifo_get_first_item(l); - for (b = xbt_fifo_get_first_item(l); b; - tmp = b, b = b->next, xbt_fifo_free_item(tmp)); - l->head = l->tail = NULL; + while (b) { + xbt_fifo_item_t tmp = b; + b = b->next; + xbt_fifo_free_item(tmp); + } + l->head = NULL; + l->tail = NULL; } /** Push @@ -82,12 +86,12 @@ xbt_fifo_item_t xbt_fifo_push(xbt_fifo_t l, void *t) */ void *xbt_fifo_pop(xbt_fifo_t l) { - xbt_fifo_item_t item; void *content; if (l == NULL) return NULL; - if (!(item = xbt_fifo_pop_item(l))) + xbt_fifo_item_t item = xbt_fifo_pop_item(l); + if (!item) return NULL; content = item->content; @@ -121,12 +125,12 @@ xbt_fifo_item_t xbt_fifo_unshift(xbt_fifo_t l, void *t) */ void *xbt_fifo_shift(xbt_fifo_t l) { - xbt_fifo_item_t item; void *content; if (l == NULL) return NULL; - if (!(item = xbt_fifo_shift_item(l))) + xbt_fifo_item_t item = xbt_fifo_shift_item(l); + if (!item) return NULL; content = item->content; @@ -235,7 +239,7 @@ xbt_fifo_item_t xbt_fifo_shift_item(xbt_fifo_t l) * \param l * \param t an objet * - * removes the first occurence of \a t from \a l. + * removes the first occurrence of \a t from \a l. * \warning it will not remove duplicates * \return 1 if an item was removed and 0 otherwise. */ @@ -245,13 +249,13 @@ int xbt_fifo_remove(xbt_fifo_t l, void *t) for (current = l->head; current; current = current_next) { current_next = current->next; - if (current->content != t) - continue; - /* remove the item */ - xbt_fifo_remove_item(l, current); - xbt_fifo_free_item(current); - /* WILL NOT REMOVE DUPLICATES */ - return 1; + if (current->content == t) { + /* remove the item */ + xbt_fifo_remove_item(l, current); + xbt_fifo_free_item(current); + /* WILL NOT REMOVE DUPLICATES */ + return 1; + } } return 0; } @@ -260,7 +264,7 @@ int xbt_fifo_remove(xbt_fifo_t l, void *t) * \param l * \param t an objet * - * removes all occurences of \a t from \a l. + * removes all occurrences of \a t from \a l. * \return 1 if an item was removed and 0 otherwise. */ int xbt_fifo_remove_all(xbt_fifo_t l, void *t) @@ -270,12 +274,12 @@ int xbt_fifo_remove_all(xbt_fifo_t l, void *t) for (current = l->head; current; current = current_next) { current_next = current->next; - if (current->content != t) - continue; - /* remove the item */ - xbt_fifo_remove_item(l, current); - xbt_fifo_free_item(current); - res = 1; + if (current->content == t){ + /* remove the item */ + xbt_fifo_remove_item(l, current); + xbt_fifo_free_item(current); + res = 1; + } } return res; } @@ -284,7 +288,7 @@ int xbt_fifo_remove_all(xbt_fifo_t l, void *t) * \param l a list * \param current a bucket * - * removes a bucket \a current from the list \a l. This function implicitely + * removes a bucket \a current from the list \a l. This function implicitly * 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) @@ -294,7 +298,8 @@ void xbt_fifo_remove_item(xbt_fifo_t l, xbt_fifo_item_t current) l->head = NULL; l->tail = NULL; (l->count)--; - current->prev = current->next = NULL; + current->prev = NULL; + current->next = NULL; return; } @@ -309,7 +314,8 @@ void xbt_fifo_remove_item(xbt_fifo_t l, xbt_fifo_item_t current) current->next->prev = current->prev; } (l->count)--; - current->prev = current->next = NULL; + current->prev = NULL; + current->next = NULL; } /** @@ -553,13 +559,13 @@ xbt_fifo_item_t xbt_fifo_getPrevItem(xbt_fifo_item_t i) * These are internal XBT functions called by xbt_preinit/postexit(). * It can be used several times to recreate the mallocator, for example when you switch to MC mode */ -void xbt_fifo_preinit(void) +void xbt_fifo_preinit() { item_mallocator = xbt_mallocator_new(65536, fifo_item_mallocator_new_f, fifo_item_mallocator_free_f, fifo_item_mallocator_reset_f); } -void xbt_fifo_postexit(void) +void xbt_fifo_postexit() { if (item_mallocator != NULL) { xbt_mallocator_free(item_mallocator);