From: alegrand Date: Mon, 6 Aug 2007 12:10:59 +0000 (+0000) Subject: Adding convenient function. X-Git-Tag: v3.3~1378 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/0e6d2fea3ba3887101358f2ef4f24192a40de603?hp=343790d5b27cea6cead9ed4f0ec7e05ea331aa58;ds=sidebyside Adding convenient function. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3982 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/include/xbt/fifo.h b/include/xbt/fifo.h index c63c371ec6..b32551212e 100644 --- a/include/xbt/fifo.h +++ b/include/xbt/fifo.h @@ -66,6 +66,7 @@ XBT_PUBLIC(void) xbt_fifo_unshift_item(xbt_fifo_t, xbt_fifo_item_t); XBT_PUBLIC(xbt_fifo_item_t) xbt_fifo_shift_item(xbt_fifo_t); XBT_PUBLIC(int) xbt_fifo_remove(xbt_fifo_t, void *); +XBT_PUBLIC(int) xbt_fifo_remove_all(xbt_fifo_t, void *); XBT_PUBLIC(void) xbt_fifo_remove_item(xbt_fifo_t, xbt_fifo_item_t); XBT_PUBLIC(xbt_fifo_item_t) xbt_fifo_get_first_item(xbt_fifo_t l); diff --git a/src/xbt/fifo.c b/src/xbt/fifo.c index f91ab8321f..bf3e61e6fe 100644 --- a/src/xbt/fifo.c +++ b/src/xbt/fifo.c @@ -249,6 +249,31 @@ int xbt_fifo_remove(xbt_fifo_t l, void *t) 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; +} + /** * \param l a list * \param current a bucket