Example #1
0
/* FIXME: that's a poor man's implementation: we should take the message exchanges into account */
static void action_barrier(const char *const *action)
{
  static smx_mutex_t mutex = NULL;
  static smx_cond_t cond = NULL;
  static int processes_arrived_sofar = 0;

  if (mutex == NULL) {          // first arriving on the barrier
    mutex = simcall_mutex_init();
    cond = simcall_cond_init();
    processes_arrived_sofar = 0;
  }
  ACT_DEBUG("Entering barrier: %s (%d already there)", NAME,
            processes_arrived_sofar);

  simcall_mutex_lock(mutex);
  if (++processes_arrived_sofar == communicator_size) {
    simcall_cond_broadcast(cond);
    simcall_mutex_unlock(mutex);
  } else {
    simcall_cond_wait(cond, mutex);
    simcall_mutex_unlock(mutex);
  }

  ACT_DEBUG("Exiting barrier: %s", NAME);

  processes_arrived_sofar--;
  if (!processes_arrived_sofar) {
    simcall_cond_destroy(cond);
    simcall_mutex_destroy(mutex);
    mutex = NULL;
  }
}
Example #2
0
void xbt_cond_broadcast(xbt_cond_t cond)
{
  simcall_cond_broadcast((smx_cond_t) cond);
}