Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Friday smell chase
[simgrid.git] / src / xbt / fifo.c
index 9e022d7..55a6ab0 100644 (file)
@@ -23,8 +23,7 @@ static xbt_mallocator_t item_mallocator = NULL;
  */
 xbt_fifo_t xbt_fifo_new(void)
 {
-  xbt_fifo_t fifo;
-  fifo = xbt_new0(struct xbt_fifo, 1);
+  xbt_fifo_t fifo = xbt_new0(struct xbt_fifo, 1);
 
   return fifo;
 }
@@ -48,9 +47,13 @@ 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));
+  while (b) {
+    xbt_fifo_item_t tmp = b;
+    b = b->next;
+    xbt_fifo_free_item(tmp);
+  }
   l->head = NULL;
   l->tail = NULL;
 }
@@ -64,9 +67,7 @@ void xbt_fifo_reset(xbt_fifo_t l)
  */
 xbt_fifo_item_t xbt_fifo_push(xbt_fifo_t l, void *t)
 {
-  xbt_fifo_item_t new;
-
-  new = xbt_fifo_new_item();
+  xbt_fifo_item_t new = xbt_fifo_new_item();
   new->content = t;
 
   xbt_fifo_push_item(l, new);
@@ -82,15 +83,13 @@ xbt_fifo_item_t xbt_fifo_push(xbt_fifo_t l, void *t)
  */
 void *xbt_fifo_pop(xbt_fifo_t l)
 {
-  void *content;
-
   if (l == NULL)
     return NULL;
   xbt_fifo_item_t item = xbt_fifo_pop_item(l);
   if (!item)
     return NULL;
 
-  content = item->content;
+  void *content = item->content;
   xbt_fifo_free_item(item);
   return content;
 }
@@ -104,9 +103,7 @@ void *xbt_fifo_pop(xbt_fifo_t l)
  */
 xbt_fifo_item_t xbt_fifo_unshift(xbt_fifo_t l, void *t)
 {
-  xbt_fifo_item_t new;
-
-  new = xbt_fifo_new_item();
+  xbt_fifo_item_t new = xbt_fifo_new_item();
   new->content = t;
   xbt_fifo_unshift_item(l, new);
   return new;
@@ -121,15 +118,13 @@ xbt_fifo_item_t xbt_fifo_unshift(xbt_fifo_t l, void *t)
  */
 void *xbt_fifo_shift(xbt_fifo_t l)
 {
-  void *content;
-
   if (l == NULL)
     return NULL;
   xbt_fifo_item_t item = xbt_fifo_shift_item(l);
   if (!item)
     return NULL;
 
-  content = item->content;
+  void *content = item->content;
   xbt_fifo_free_item(item);
   return content;
 }
@@ -162,12 +157,10 @@ void xbt_fifo_push_item(xbt_fifo_t l, xbt_fifo_item_t new)
  */
 xbt_fifo_item_t xbt_fifo_pop_item(xbt_fifo_t l)
 {
-  xbt_fifo_item_t item;
-
   if (l->tail == NULL)
     return NULL;
 
-  item = l->tail;
+  xbt_fifo_item_t item = l->tail;
 
   l->tail = item->prev;
   if (l->tail == NULL)
@@ -200,7 +193,6 @@ void xbt_fifo_unshift_item(xbt_fifo_t l, xbt_fifo_item_t new)
   new->next = l->head;
   new->next->prev = new;
   l->head = new;
-  return;
 }
 
 /** Shift bucket
@@ -211,12 +203,10 @@ void xbt_fifo_unshift_item(xbt_fifo_t l, xbt_fifo_item_t new)
  */
 xbt_fifo_item_t xbt_fifo_shift_item(xbt_fifo_t l)
 {
-  xbt_fifo_item_t item;
-
   if (l->head == NULL)
     return NULL;
 
-  item = l->head;
+  xbt_fifo_item_t item = l->head;
 
   l->head = item->next;
   if (l->head == NULL)
@@ -241,7 +231,8 @@ xbt_fifo_item_t xbt_fifo_shift_item(xbt_fifo_t l)
  */
 int xbt_fifo_remove(xbt_fifo_t l, void *t)
 {
-  xbt_fifo_item_t current, current_next;
+  xbt_fifo_item_t current;
+  xbt_fifo_item_t current_next;
 
   for (current = l->head; current; current = current_next) {
     current_next = current->next;
@@ -265,7 +256,8 @@ int xbt_fifo_remove(xbt_fifo_t l, void *t)
  */
 int xbt_fifo_remove_all(xbt_fifo_t l, void *t)
 {
-  xbt_fifo_item_t current, current_next;
+  xbt_fifo_item_t current;
+  xbt_fifo_item_t current_next;
   int res = 0;
 
   for (current = l->head; current; current = current_next) {
@@ -390,11 +382,9 @@ void **xbt_fifo_to_array(xbt_fifo_t f)
  */
 xbt_fifo_t xbt_fifo_copy(xbt_fifo_t f)
 {
-  xbt_fifo_t copy = NULL;
+  xbt_fifo_t copy = xbt_fifo_new();
   xbt_fifo_item_t b;
 
-  copy = xbt_fifo_new();
-
   for (b = xbt_fifo_get_first_item(f); b; b = b->next) {
     xbt_fifo_push(copy, b->content);
   }
@@ -457,7 +447,6 @@ inline void *xbt_fifo_get_item_content(xbt_fifo_item_t i)
 inline void xbt_fifo_free_item(xbt_fifo_item_t b)
 {
   xbt_mallocator_release(item_mallocator, b);
-  return;
 }
 
 /** Destructor
@@ -467,7 +456,6 @@ inline void xbt_fifo_freeitem(xbt_fifo_item_t b)
 {
   XBT_CWARN(xbt_fifo, "This function is deprecated. Use xbt_fifo_free_item.");
   xbt_fifo_free_item(b);
-  return;
 }
 
 /**
@@ -555,13 +543,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);