Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
catch some bugs in fifo and parmap
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 1 Jul 2016 12:18:45 +0000 (14:18 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 1 Jul 2016 12:18:45 +0000 (14:18 +0200)
src/xbt/fifo.c
src/xbt/parmap.cpp

index 399a888..9e022d7 100644 (file)
@@ -50,9 +50,9 @@ void xbt_fifo_reset(xbt_fifo_t l)
 {
   xbt_fifo_item_t b, tmp;
 
 {
   xbt_fifo_item_t b, tmp;
 
-  for (b = xbt_fifo_get_first_item(l); b;
-       tmp = b, b = b->next, xbt_fifo_free_item(tmp));
-  l->head = l->tail = NULL;
+  for (b = xbt_fifo_get_first_item(l); b; tmp = b, b = b->next, xbt_fifo_free_item(tmp));
+  l->head = NULL;
+  l->tail = NULL;
 }
 
 /** Push
 }
 
 /** Push
@@ -82,12 +82,12 @@ xbt_fifo_item_t xbt_fifo_push(xbt_fifo_t l, void *t)
  */
 void *xbt_fifo_pop(xbt_fifo_t l)
 {
  */
 void *xbt_fifo_pop(xbt_fifo_t l)
 {
-  xbt_fifo_item_t item;
   void *content;
 
   if (l == NULL)
     return NULL;
   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;
     return NULL;
 
   content = item->content;
@@ -121,12 +121,12 @@ xbt_fifo_item_t xbt_fifo_unshift(xbt_fifo_t l, void *t)
  */
 void *xbt_fifo_shift(xbt_fifo_t l)
 {
  */
 void *xbt_fifo_shift(xbt_fifo_t l)
 {
-  xbt_fifo_item_t item;
   void *content;
 
   if (l == NULL)
     return NULL;
   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;
     return NULL;
 
   content = item->content;
@@ -235,7 +235,7 @@ xbt_fifo_item_t xbt_fifo_shift_item(xbt_fifo_t l)
  * \param l
  * \param t an objet
  *
  * \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.
  */
  * \warning it will not remove duplicates
  * \return 1 if an item was removed and 0 otherwise.
  */
@@ -245,13 +245,13 @@ int xbt_fifo_remove(xbt_fifo_t l, void *t)
 
   for (current = l->head; current; current = current_next) {
     current_next = current->next;
 
   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;
 }
   }
   return 0;
 }
@@ -260,7 +260,7 @@ int xbt_fifo_remove(xbt_fifo_t l, void *t)
  * \param l
  * \param t an objet
  *
  * \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)
  * \return 1 if an item was removed and 0 otherwise.
  */
 int xbt_fifo_remove_all(xbt_fifo_t l, void *t)
@@ -270,12 +270,12 @@ int xbt_fifo_remove_all(xbt_fifo_t l, void *t)
 
   for (current = l->head; current; current = current_next) {
     current_next = current->next;
 
   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;
 }
   }
   return res;
 }
@@ -284,7 +284,7 @@ int xbt_fifo_remove_all(xbt_fifo_t l, void *t)
  * \param l a list
  * \param current a bucket
  *
  * \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)
  * 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 +294,8 @@ void xbt_fifo_remove_item(xbt_fifo_t l, xbt_fifo_item_t current)
     l->head = NULL;
     l->tail = NULL;
     (l->count)--;
     l->head = NULL;
     l->tail = NULL;
     (l->count)--;
-    current->prev = current->next = NULL;
+    current->prev = NULL;
+    current->next = NULL;
     return;
   }
 
     return;
   }
 
@@ -309,7 +310,8 @@ void xbt_fifo_remove_item(xbt_fifo_t l, xbt_fifo_item_t current)
     current->next->prev = current->prev;
   }
   (l->count)--;
     current->next->prev = current->prev;
   }
   (l->count)--;
-  current->prev = current->next = NULL;
+  current->prev = NULL;
+  current->next = NULL;
 }
 
 /**
 }
 
 /**
index 62a691d..7a0fab3 100644 (file)
@@ -258,9 +258,11 @@ void* xbt_parmap_next(xbt_parmap_t parmap)
 
 static void xbt_parmap_work(xbt_parmap_t parmap)
 {
 
 static void xbt_parmap_work(xbt_parmap_t parmap)
 {
-  unsigned index;
-  while ((index = parmap->index++) < xbt_dynar_length(parmap->data))
+  unsigned int index = parmap->index++;
+  while (index < xbt_dynar_length(parmap->data)){
     parmap->fun(xbt_dynar_get_as(parmap->data, index, void*));
     parmap->fun(xbt_dynar_get_as(parmap->data, index, void*));
+    index = parmap->index++;
+  }
 }
 
 /**
 }
 
 /**
@@ -269,7 +271,7 @@ static void xbt_parmap_work(xbt_parmap_t parmap)
  */
 static void *xbt_parmap_worker_main(void *arg)
 {
  */
 static void *xbt_parmap_worker_main(void *arg)
 {
-  xbt_parmap_thread_data_t data = (xbt_parmap_thread_data_t) arg;
+  xbt_parmap_thread_data_t data = static_cast<xbt_parmap_thread_data_t>(arg);
   xbt_parmap_t parmap = data->parmap;
   unsigned round = 0;
   smx_context_t context = SIMIX_context_new(std::function<void()>(), nullptr, nullptr);
   xbt_parmap_t parmap = data->parmap;
   unsigned round = 0;
   smx_context_t context = SIMIX_context_new(std::function<void()>(), nullptr, nullptr);
@@ -279,7 +281,8 @@ static void *xbt_parmap_worker_main(void *arg)
 
   /* Worker's main loop */
   while (1) {
 
   /* Worker's main loop */
   while (1) {
-    parmap->worker_wait_f(parmap, ++round);
+    round++;
+    parmap->worker_wait_f(parmap, round);
     if (parmap->status == XBT_PARMAP_WORK) {
       XBT_DEBUG("Worker %d got a job", data->worker_id);
 
     if (parmap->status == XBT_PARMAP_WORK) {
       XBT_DEBUG("Worker %d got a job", data->worker_id);
 
@@ -337,7 +340,8 @@ static void xbt_parmap_posix_master_wait(xbt_parmap_t parmap)
 static void xbt_parmap_posix_worker_signal(xbt_parmap_t parmap)
 {
   xbt_os_mutex_acquire(parmap->done_mutex);
 static void xbt_parmap_posix_worker_signal(xbt_parmap_t parmap)
 {
   xbt_os_mutex_acquire(parmap->done_mutex);
-  if (++parmap->thread_counter == parmap->num_workers) {
+  parmap->thread_counter++;
+  if (parmap->thread_counter == parmap->num_workers) {
     /* all workers have finished, wake the controller */
     xbt_os_cond_signal(parmap->done_cond);
   }
     /* all workers have finished, wake the controller */
     xbt_os_cond_signal(parmap->done_cond);
   }