Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change dynar parameter for waitany to a raw array (mimic testany).
[simgrid.git] / src / kernel / activity / CommImpl.cpp
index 3ec13f4..59c9f69 100644 (file)
@@ -294,30 +294,28 @@ void simcall_HANDLER_comm_testany(smx_simcall_t simcall, simgrid::kernel::activi
 
 static void SIMIX_waitany_remove_simcall_from_actions(smx_simcall_t simcall)
 {
-  unsigned int cursor  = 0;
-  xbt_dynar_t synchros = simcall_comm_waitany__get__comms(simcall);
-
-  simgrid::kernel::activity::ActivityImpl* ptr;
-  xbt_dynar_foreach (synchros, cursor, ptr) {
-    smx_activity_t synchro = simgrid::kernel::activity::ActivityImplPtr(ptr);
+  smx_activity_t* synchros = simcall_comm_waitany__get__comms(simcall);
+  size_t count             = simcall_comm_waitany__get__count(simcall);
 
+  for (size_t i = 0; i < count; i++) {
     // Remove the first occurence of simcall:
-    auto i = boost::range::find(synchro->simcalls_, simcall);
-    if (i != synchro->simcalls_.end())
-      synchro->simcalls_.erase(i);
+    smx_activity_t& synchro = synchros[i];
+    auto j                  = boost::range::find(synchro->simcalls_, simcall);
+    if (j != synchro->simcalls_.end())
+      synchro->simcalls_.erase(j);
   }
 }
-void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, xbt_dynar_t synchros, double timeout)
+void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, smx_activity_t* synchros, size_t count, double timeout)
 {
   if (MC_is_active() || MC_record_replay_is_active()) {
     if (timeout > 0.0)
       xbt_die("Timeout not implemented for waitany in the model-checker");
-    int idx                = SIMCALL_GET_MC_VALUE(simcall);
-    smx_activity_t synchro = xbt_dynar_get_as(synchros, idx, smx_activity_t);
+    int idx                 = SIMCALL_GET_MC_VALUE(simcall);
+    smx_activity_t& synchro = synchros[idx];
     synchro->simcalls_.push_back(simcall);
     simcall_comm_waitany__set__result(simcall, idx);
     synchro->state_ = SIMIX_DONE;
-    boost::static_pointer_cast<simgrid::kernel::activity::CommImpl>(synchro)->finish();
+    synchro->finish();
     return;
   }
 
@@ -331,16 +329,14 @@ void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, xbt_dynar_t synchros, d
     });
   }
 
-  unsigned int cursor;
-  simgrid::kernel::activity::ActivityImpl* ptr;
-  xbt_dynar_foreach (synchros, cursor, ptr) {
-    smx_activity_t synchro = simgrid::kernel::activity::ActivityImplPtr(ptr);
+  for (size_t i = 0; i < count; i++) {
     /* associate this simcall to the the synchro */
+    smx_activity_t& synchro = synchros[i];
     synchro->simcalls_.push_back(simcall);
 
     /* see if the synchro is already finished */
     if (synchro->state_ != SIMIX_WAITING && synchro->state_ != SIMIX_RUNNING) {
-      boost::static_pointer_cast<simgrid::kernel::activity::CommImpl>(synchro)->finish();
+      synchro->finish();
       break;
     }
   }
@@ -559,13 +555,12 @@ void CommImpl::post()
 
 void CommImpl::finish()
 {
-  smx_activity_t synchro = this;
   while (not simcalls_.empty()) {
     smx_simcall_t simcall = simcalls_.front();
     simcalls_.pop_front();
 
     /* If a waitany simcall is waiting for this synchro to finish, then remove it from the other synchros in the waitany
-     * list. Afterwards, get the position of the actual synchro in the waitany dynar and return it as the result of the
+     * list. Afterwards, get the position of the actual synchro in the waitany list and return it as the result of the
      * simcall */
 
     if (simcall->call == SIMCALL_NONE) // FIXME: maybe a better way to handle this case
@@ -576,9 +571,13 @@ void CommImpl::finish()
         simcall->timer->remove();
         simcall->timer = nullptr;
       }
-      if (not MC_is_active() && not MC_record_replay_is_active())
-        simcall_comm_waitany__set__result(simcall,
-                                          xbt_dynar_search(simcall_comm_waitany__get__comms(simcall), &synchro));
+      if (not MC_is_active() && not MC_record_replay_is_active()) {
+        CommImpl** comms   = simcall_comm_waitany__get__comms(simcall);
+        size_t count       = simcall_comm_waitany__get__count(simcall);
+        CommImpl** element = std::find(comms, comms + count, this);
+        int rank           = (element != comms + count) ? element - comms : -1;
+        simcall_comm_waitany__set__result(simcall, rank);
+      }
     }
 
     /* If the synchro is still in a rendez-vous point then remove from it */
@@ -657,24 +656,22 @@ void CommImpl::finish()
           xbt_die("Unexpected synchro state in CommImpl::finish: %d", static_cast<int>(state_));
       }
     }
-
     /* if there is an exception during a waitany or a testany, indicate the position of the failed communication */
     if (simcall->issuer->exception_ &&
         (simcall->call == SIMCALL_COMM_WAITANY || simcall->call == SIMCALL_COMM_TESTANY)) {
       // First retrieve the rank of our failing synchro
-      int rank = -1;
+      CommImpl** comms;
+      size_t count;
       if (simcall->call == SIMCALL_COMM_WAITANY) {
-        rank = xbt_dynar_search(simcall_comm_waitany__get__comms(simcall), &synchro);
-      } else if (simcall->call == SIMCALL_COMM_TESTANY) {
-        rank         = -1;
-        auto* comms  = simcall_comm_testany__get__comms(simcall);
-        auto count   = simcall_comm_testany__get__count(simcall);
-        auto element = std::find(comms, comms + count, this);
-        if (element == comms + count)
-          rank = -1;
-        else
-          rank = element - comms;
+        comms = simcall_comm_waitany__get__comms(simcall);
+        count = simcall_comm_waitany__get__count(simcall);
+      } else {
+        /* simcall->call == SIMCALL_COMM_TESTANY */
+        comms = simcall_comm_testany__get__comms(simcall);
+        count = simcall_comm_testany__get__count(simcall);
       }
+      CommImpl** element = std::find(comms, comms + count, this);
+      int rank           = (element != comms + count) ? element - comms : -1;
 
       // In order to modify the exception we have to rethrow it:
       try {