Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fight against multiple 'extern' specification
[simgrid.git] / src / xbt / dynar.c
index df177bf..6abfd76 100644 (file)
@@ -53,6 +53,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_dyn,xbt,"Dynamic arrays");
              THROW1(bound_error,0,            \
                     "dynar %p is empty", dynar)
 
+static void _dynar_map(const xbt_dynar_t  dynar,
+                      void_f_pvoid_t     const op);
 
 static XBT_INLINE 
 void _xbt_clear_mem(void * const ptr,
@@ -180,7 +182,7 @@ xbt_dynar_dump(xbt_dynar_t dynar) {
  */
 xbt_dynar_t 
 xbt_dynar_new(const unsigned long elmsize,
-               void_f_pvoid_t const free_f) {
+               void_f_pvoid_t const free_f) {
    
   xbt_dynar_t dynar = xbt_new0(s_xbt_dynar_t,1);
 
@@ -201,7 +203,7 @@ xbt_dynar_new(const unsigned long elmsize,
  */
 xbt_dynar_t 
 xbt_dynar_new_sync(const unsigned long elmsize,
-               void_f_pvoid_t const free_f) {
+               void_f_pvoid_t const free_f) {
    xbt_dynar_t res = xbt_dynar_new(elmsize,free_f);
    res->mutex = xbt_mutex_init();
    return res;
@@ -245,7 +247,7 @@ xbt_dynar_reset(xbt_dynar_t const dynar) {
    
   DEBUG1("Reset the dynar %p",(void*)dynar);
   if (dynar->free_f) {
-    xbt_dynar_map(dynar, dynar->free_f);
+    _dynar_map(dynar, dynar->free_f);
   }
      /*
   if (dynar->data)
@@ -426,17 +428,20 @@ static XBT_INLINE void *
 _xbt_dynar_insert_at_ptr(xbt_dynar_t const dynar,
                        const int            idx) {
    void *res;
+   unsigned long old_used;
+   unsigned long new_used;
+   unsigned long nb_shift;
    
   _sanity_check_dynar(dynar);
   _sanity_check_idx(idx);
   _check_sloppy_inbound_idx(dynar, idx);
 
-  const unsigned long old_used = dynar->used;
-  const unsigned long new_used = old_used + 1;
+  old_used = dynar->used;
+  new_used = old_used + 1;
 
   _xbt_dynar_expand(dynar, new_used);
 
-  const unsigned long nb_shift =  old_used - idx;
+  nb_shift =  old_used - idx;
 
   if (nb_shift)
      memmove(_xbt_dynar_elm(dynar, idx+1), 
@@ -611,6 +616,18 @@ xbt_dynar_shift(xbt_dynar_t  const dynar,
   xbt_dynar_remove_at(dynar, 0, dst);
 }
 
+static void _dynar_map(const xbt_dynar_t  dynar,
+                      void_f_pvoid_t     const op) {
+  char         elm[SIZEOF_MAX];
+  const unsigned long used = dynar->used;
+  unsigned long       i    = 0;
+
+  for (i = 0; i < used; i++) {
+    _xbt_dynar_get_elm(elm, dynar, i);
+    op(elm);
+  }
+}
+
 /** @brief Apply a function to each member of a dynar
  *
  * The mapped function may change the value of the element itself, 
@@ -622,21 +639,13 @@ xbt_dynar_shift(xbt_dynar_t  const dynar,
  */
 void
 xbt_dynar_map(const xbt_dynar_t  dynar,
-               void_f_pvoid_t     * const op) {
+               void_f_pvoid_t    const op) {
 
   _dynar_lock(dynar);
   _sanity_check_dynar(dynar);
 
-  {
-    char         elm[SIZEOF_MAX];
-    const unsigned long used = dynar->used;
-    unsigned long       i    = 0;
+  _dynar_map(dynar,op);
 
-    for (i = 0; i < used; i++) {
-      _xbt_dynar_get_elm(elm, dynar, i);
-      op(elm);
-    }
-  }
   _dynar_unlock(dynar);
 }
 
@@ -1166,8 +1175,8 @@ XBT_TEST_UNIT("synchronized int",test_dynar_sync_int,"Synchronized dynars of int
    
    xbt_test_add0("==== Have a pusher and a popper on the dynar");
    d=xbt_dynar_new_sync(sizeof(int),NULL);
-   pusher = xbt_thread_create(pusher_f,d);
-   poper = xbt_thread_create(poper_f,d);
+   pusher = xbt_thread_create("pusher",pusher_f,d);
+   poper = xbt_thread_create("poper",poper_f,d);
    xbt_thread_join(pusher);
    xbt_thread_join(poper);
    xbt_dynar_free(&d);