Beispiel #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;
  }
}
Beispiel #2
0
/** @brief Blocks the calling actor until the mutex can be obtained */
void Mutex::lock()
{
  simcall_mutex_lock(mutex_);
}
Beispiel #3
0
void xbt_mutex_acquire(xbt_mutex_t mutex)
{
  simcall_mutex_lock((smx_mutex_t) mutex);
}