/* 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 simgrid::s4u::Mutex *mutex = NULL;
- static simgrid::s4u::ConditionVariable *cond = NULL;
+ static simgrid::s4u::MutexPtr mutex = nullptr;
+ static simgrid::s4u::ConditionVariablePtr cond = nullptr;
static int processes_arrived_sofar = 0;
- if (mutex == NULL) { // first arriving on the barrier
- mutex = new simgrid::s4u::Mutex();
- cond = new simgrid::s4u::ConditionVariable();
+ if (mutex == nullptr) { // first arriving on the barrier
+ mutex = simgrid::s4u::Mutex::createMutex();
+ cond = simgrid::s4u::ConditionVariable::createConditionVariable();
processes_arrived_sofar = 0;
}
ACT_DEBUG("Entering barrier: %s (%d already there)", NAME, processes_arrived_sofar);
- std::unique_lock<simgrid::s4u::Mutex> lock(*mutex);
- if (++processes_arrived_sofar == communicator_size) {
- // We can notify without the lock:
- lock.unlock();
- cond->notify_all();
- } else {
- cond->wait(lock);
+ {
+ std::unique_lock<simgrid::s4u::Mutex> lock(*mutex);
+ if (++processes_arrived_sofar == communicator_size) {
+ // We can notify without the lock:
+ lock.unlock();
+ cond->notify_all();
+ } else {
+ cond->wait(lock);
+ }
}
ACT_DEBUG("Exiting barrier: %s", NAME);
processes_arrived_sofar--;
if (processes_arrived_sofar<=0) {
- delete cond;
- delete mutex;
- mutex = NULL;
+ cond = nullptr;
+ mutex = nullptr;
}
}