Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[s4u] Allocate ConditionVariable on the heap and return ConditionVariablePtr
[simgrid.git] / examples / s4u / actions-comm / s4u_actions-comm.cpp
index 826d6c9..51c89d3 100644 (file)
@@ -163,12 +163,12 @@ static void action_wait(const char *const *action)
 /* 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);
@@ -188,9 +188,8 @@ static void action_barrier(const char *const *action)
 
   processes_arrived_sofar--;
   if (processes_arrived_sofar<=0) {
-    delete cond;
-    delete mutex;
-    mutex = NULL;
+    cond = nullptr;
+    mutex = nullptr;
   }
 }