X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/b591838fb09269e35740c6c8991a7ca478d64303..c28b7e03130c89fae7bad65806977cdbccb79c53:/src/xbt/fifo.c diff --git a/src/xbt/fifo.c b/src/xbt/fifo.c index 09fed3254e..bf3e61e6fe 100644 --- a/src/xbt/fifo.c +++ b/src/xbt/fifo.c @@ -229,8 +229,9 @@ xbt_fifo_item_t xbt_fifo_shift_item(xbt_fifo_t l) * * removes the first occurence of \a t from \a l. * \warning it will not remove duplicates + * \return 1 if an item was removed and 0 otherwise. */ -void xbt_fifo_remove(xbt_fifo_t l, void *t) +int xbt_fifo_remove(xbt_fifo_t l, void *t) { xbt_fifo_item_t current, current_next; @@ -243,9 +244,34 @@ void xbt_fifo_remove(xbt_fifo_t l, void *t) xbt_fifo_remove_item(l, current); xbt_fifo_free_item(current); /* WILL NOT REMOVE DUPLICATES */ - break; + return 1; } - return; + return 0; +} + + +/** + * \param l + * \param t an objet + * + * removes all occurences 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) +{ + xbt_fifo_item_t current, current_next; + int res=0; + + 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; + } + return res; } /**