Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
have barrier_wait return XBT/MSG_BARRIER_SERIAL_PROCESS for one process
authorAugustin Degomme <degomme@idpann.imag.fr>
Tue, 6 May 2014 16:09:39 +0000 (18:09 +0200)
committerAugustin Degomme <degomme@idpann.imag.fr>
Tue, 6 May 2014 16:09:39 +0000 (18:09 +0200)
Also have it reset the counter when barrier is completed, to allow reuse

include/msg/msg.h
include/xbt/synchro_core.h
src/msg/msg_synchro.c
src/xbt/xbt_sg_synchro.c

index 3ff9838..341afa2 100644 (file)
@@ -421,10 +421,12 @@ XBT_PUBLIC(int) MSG_sem_would_block(msg_sem_t sem);
  *  @ingroup msg_synchro
  *  @hideinitializer
  */
+
+#define MSG_BARRIER_SERIAL_PROCESS -1
 typedef struct s_xbt_bar *msg_bar_t;
 XBT_PUBLIC(msg_bar_t) MSG_barrier_init( unsigned int count);
 XBT_PUBLIC(void) MSG_barrier_destroy(msg_bar_t bar);
-XBT_PUBLIC(void) MSG_barrier_wait(msg_bar_t bar);
+XBT_PUBLIC(int) MSG_barrier_wait(msg_bar_t bar);
 
 /** @brief Opaque type describing a Virtual Machine.
  *  @ingroup msg_VMs
index 5313a9c..d427488 100644 (file)
@@ -107,10 +107,11 @@ XBT_PUBLIC(void) xbt_cond_broadcast(xbt_cond_t cond);
 XBT_PUBLIC(void) xbt_cond_destroy(xbt_cond_t cond);
 
 
+#define XBT_BARRIER_SERIAL_PROCESS -1
 typedef struct s_xbt_bar_ *xbt_bar_t;
 XBT_PUBLIC(xbt_bar_t) xbt_barrier_init( unsigned int count);
 XBT_PUBLIC(void) xbt_barrier_destroy(xbt_bar_t bar);
-XBT_PUBLIC(void) xbt_barrier_wait(xbt_bar_t bar);
+XBT_PUBLIC(int) xbt_barrier_wait(xbt_bar_t bar);
 
 /** @} */
 
index 186fcef..70f1383 100644 (file)
@@ -76,8 +76,11 @@ void MSG_barrier_destroy(msg_bar_t bar) {
 }
 
 /** @brief Performs a barrier already initialized */
-void MSG_barrier_wait(msg_bar_t bar) {
-  xbt_barrier_wait((xbt_bar_t)bar);
+int MSG_barrier_wait(msg_bar_t bar) {
+  if(xbt_barrier_wait((xbt_bar_t)bar) == XBT_BARRIER_SERIAL_PROCESS)
+    return MSG_BARRIER_SERIAL_PROCESS;
+  else
+    return 0;
 }
 
 /**@}*/
index e04f5a1..724755b 100644 (file)
@@ -204,16 +204,21 @@ xbt_bar_t xbt_barrier_init(unsigned int count)
 }
 
 
-void xbt_barrier_wait(xbt_bar_t bar)
+int xbt_barrier_wait(xbt_bar_t bar)
 {
+   int ret=0;
    xbt_mutex_acquire(bar->mutex);
    if (++bar->arrived_processes == bar->expected_processes) {
      xbt_cond_broadcast(bar->cond);
      xbt_mutex_release(bar->mutex);
+     ret=XBT_BARRIER_SERIAL_PROCESS;
+     bar->arrived_processes = 0;
    } else {
      xbt_cond_wait(bar->cond, bar->mutex);
      xbt_mutex_release(bar->mutex);
    }
+
+   return ret;
 }
 
 void xbt_barrier_destroy(xbt_bar_t bar)