Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
_SIMIX_cond_wait becomes ConditionVariable::wait
[simgrid.git] / src / simix / smx_network.cpp
index 9d36b98..54219f1 100644 (file)
@@ -43,15 +43,16 @@ XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_isend(
   XBT_DEBUG("send from mailbox %p", mbox);
 
   /* Prepare a synchro describing us, so that it gets passed to the user-provided filter of other side */
-  simgrid::kernel::activity::CommImplPtr this_comm =
-      simgrid::kernel::activity::CommImplPtr(new simgrid::kernel::activity::CommImpl(SIMIX_COMM_SEND));
+  simgrid::kernel::activity::CommImplPtr this_comm = simgrid::kernel::activity::CommImplPtr(
+      new simgrid::kernel::activity::CommImpl(simgrid::kernel::activity::CommImpl::Type::SEND));
 
   /* Look for communication synchro matching our needs. We also provide a description of
    * ourself so that the other side also gets a chance of choosing if it wants to match with us.
    *
    * If it is not found then push our communication into the rendez-vous point */
-  simgrid::kernel::activity::CommImplPtr other_comm = mbox->find_matching_comm(
-      SIMIX_COMM_RECEIVE, match_fun, data, this_comm, /*done*/ false, /*remove_matching*/ true);
+  simgrid::kernel::activity::CommImplPtr other_comm =
+      mbox->find_matching_comm(simgrid::kernel::activity::CommImpl::Type::RECEIVE, match_fun, data, this_comm,
+                               /*done*/ false, /*remove_matching*/ true);
 
   if (not other_comm) {
     other_comm = std::move(this_comm);
@@ -70,7 +71,7 @@ XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_isend(
     XBT_DEBUG("Receive already pushed");
 
     other_comm->state_ = SIMIX_READY;
-    other_comm->type = SIMIX_COMM_READY;
+    other_comm->type   = simgrid::kernel::activity::CommImpl::Type::READY;
   }
   src_proc->comms.push_back(other_comm);
 
@@ -121,8 +122,8 @@ XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_irecv(smx_simcall_t /*simcall*/,
                                                       void (*copy_data_fun)(smx_activity_t, void*, size_t), void* data,
                                                       double rate)
 {
-  simgrid::kernel::activity::CommImplPtr this_synchro =
-      simgrid::kernel::activity::CommImplPtr(new simgrid::kernel::activity::CommImpl(SIMIX_COMM_RECEIVE));
+  simgrid::kernel::activity::CommImplPtr this_synchro = simgrid::kernel::activity::CommImplPtr(
+      new simgrid::kernel::activity::CommImpl(simgrid::kernel::activity::CommImpl::Type::RECEIVE));
   XBT_DEBUG("recv from mbox %p. this_synchro=%p", mbox, this_synchro.get());
 
   simgrid::kernel::activity::CommImplPtr other_comm;
@@ -131,7 +132,8 @@ XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_irecv(smx_simcall_t /*simcall*/,
 
     XBT_DEBUG("We have a comm that has probably already been received, trying to match it, to skip the communication");
     //find a match in the list of already received comms
-    other_comm = mbox->find_matching_comm(SIMIX_COMM_SEND, match_fun, data, this_synchro, /*done*/ true,
+    other_comm = mbox->find_matching_comm(simgrid::kernel::activity::CommImpl::Type::SEND, match_fun, data,
+                                          this_synchro, /*done*/ true,
                                           /*remove_matching*/ true);
     //if not found, assume the receiver came first, register it to the mailbox in the classical way
     if (not other_comm) {
@@ -142,7 +144,7 @@ XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_irecv(smx_simcall_t /*simcall*/,
       if (other_comm->surf_action_ && other_comm->remains() < 1e-12) {
         XBT_DEBUG("comm %p has been already sent, and is finished, destroy it", other_comm.get());
         other_comm->state_ = SIMIX_DONE;
-        other_comm->type = SIMIX_COMM_DONE;
+        other_comm->type   = simgrid::kernel::activity::CommImpl::Type::DONE;
         other_comm->mbox = nullptr;
       }
     }
@@ -153,7 +155,8 @@ XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_irecv(smx_simcall_t /*simcall*/,
      * ourself so that the other side also gets a chance of choosing if it wants to match with us.
      *
      * If it is not found then push our communication into the rendez-vous point */
-    other_comm = mbox->find_matching_comm(SIMIX_COMM_SEND, match_fun, data, this_synchro, /*done*/ false,
+    other_comm = mbox->find_matching_comm(simgrid::kernel::activity::CommImpl::Type::SEND, match_fun, data,
+                                          this_synchro, /*done*/ false,
                                           /*remove_matching*/ true);
 
     if (other_comm == nullptr) {
@@ -164,7 +167,7 @@ XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_irecv(smx_simcall_t /*simcall*/,
       XBT_DEBUG("Match my %p with the existing %p", this_synchro.get(), other_comm.get());
 
       other_comm->state_ = SIMIX_READY;
-      other_comm->type = SIMIX_COMM_READY;
+      other_comm->type   = simgrid::kernel::activity::CommImpl::Type::READY;
     }
     receiver->comms.push_back(other_comm);
   }
@@ -224,7 +227,7 @@ void simcall_HANDLER_comm_wait(smx_simcall_t simcall, smx_activity_t synchro, do
   if (synchro->state_ != SIMIX_WAITING && synchro->state_ != SIMIX_RUNNING) {
     SIMIX_comm_finish(synchro);
   } else { /* we need a sleep action (even when there is no timeout) to be notified of host failures */
-    simgrid::kernel::resource::Action* sleep = simcall->issuer->host_->pimpl_cpu->sleep(timeout);
+    simgrid::kernel::resource::Action* sleep = simcall->issuer->get_host()->pimpl_cpu->sleep(timeout);
     sleep->set_data(synchro.get());
 
     simgrid::kernel::activity::CommImplPtr comm =
@@ -310,7 +313,7 @@ void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, xbt_dynar_t synchros, d
   if (timeout < 0.0){
     simcall->timer = NULL;
   } else {
-    simcall->timer = SIMIX_timer_set(SIMIX_get_clock() + timeout, [simcall]() {
+    simcall->timer = simgrid::simix::Timer::set(SIMIX_get_clock() + timeout, [simcall]() {
       SIMIX_waitany_remove_simcall_from_actions(simcall);
       simcall_comm_waitany__set__result(simcall, -1);
       SIMIX_simcall_answer(simcall);
@@ -370,7 +373,7 @@ void SIMIX_comm_finish(smx_activity_t synchro)
     if (simcall->call == SIMCALL_COMM_WAITANY) {
       SIMIX_waitany_remove_simcall_from_actions(simcall);
       if (simcall->timer) {
-        SIMIX_timer_remove(simcall->timer);
+        simcall->timer->remove();
         simcall->timer = nullptr;
       }
       if (not MC_is_active() && not MC_record_replay_is_active())
@@ -386,9 +389,9 @@ void SIMIX_comm_finish(smx_activity_t synchro)
 
     /* Check out for errors */
 
-    if (not simcall->issuer->host_->is_on()) {
+    if (not simcall->issuer->get_host()->is_on()) {
       simcall->issuer->context_->iwannadie = true;
-      simcall->issuer->exception =
+      simcall->issuer->exception_ =
           std::make_exception_ptr(simgrid::HostFailureException(XBT_THROW_POINT, "Host failed"));
     } else {
       switch (comm->state_) {
@@ -399,12 +402,12 @@ void SIMIX_comm_finish(smx_activity_t synchro)
           break;
 
         case SIMIX_SRC_TIMEOUT:
-          simcall->issuer->exception = std::make_exception_ptr(
+          simcall->issuer->exception_ = std::make_exception_ptr(
               simgrid::TimeoutError(XBT_THROW_POINT, "Communication timeouted because of the sender"));
           break;
 
         case SIMIX_DST_TIMEOUT:
-          simcall->issuer->exception = std::make_exception_ptr(
+          simcall->issuer->exception_ = std::make_exception_ptr(
               simgrid::TimeoutError(XBT_THROW_POINT, "Communication timeouted because of the receiver"));
           break;
 
@@ -412,7 +415,7 @@ void SIMIX_comm_finish(smx_activity_t synchro)
           if (simcall->issuer == comm->src_actor_)
             simcall->issuer->context_->iwannadie = true;
           else
-            simcall->issuer->exception =
+            simcall->issuer->exception_ =
                 std::make_exception_ptr(simgrid::NetworkFailureException(XBT_THROW_POINT, "Remote peer failed"));
           break;
 
@@ -420,16 +423,16 @@ void SIMIX_comm_finish(smx_activity_t synchro)
           if (simcall->issuer == comm->dst_actor_)
             simcall->issuer->context_->iwannadie = true;
           else
-            simcall->issuer->exception =
+            simcall->issuer->exception_ =
                 std::make_exception_ptr(simgrid::NetworkFailureException(XBT_THROW_POINT, "Remote peer failed"));
           break;
 
         case SIMIX_LINK_FAILURE:
           XBT_DEBUG("Link failure in synchro %p between '%s' and '%s': posting an exception to the issuer: %s (%p) "
                     "detached:%d",
-                    synchro.get(), comm->src_actor_ ? comm->src_actor_->host_->get_cname() : nullptr,
-                    comm->dst_actor_ ? comm->dst_actor_->host_->get_cname() : nullptr, simcall->issuer->get_cname(),
-                    simcall->issuer, comm->detached);
+                    synchro.get(), comm->src_actor_ ? comm->src_actor_->get_host()->get_cname() : nullptr,
+                    comm->dst_actor_ ? comm->dst_actor_->get_host()->get_cname() : nullptr,
+                    simcall->issuer->get_cname(), simcall->issuer, comm->detached);
           if (comm->src_actor_ == simcall->issuer) {
             XBT_DEBUG("I'm source");
           } else if (comm->dst_actor_ == simcall->issuer) {
@@ -443,9 +446,11 @@ void SIMIX_comm_finish(smx_activity_t synchro)
 
         case SIMIX_CANCELED:
           if (simcall->issuer == comm->dst_actor_)
-            SMX_EXCEPTION(simcall->issuer, cancel_error, 0, "Communication canceled by the sender");
+            simcall->issuer->exception_ = std::make_exception_ptr(
+                simgrid::CancelException(XBT_THROW_POINT, "Communication canceled by the sender"));
           else
-            SMX_EXCEPTION(simcall->issuer, cancel_error, 0, "Communication canceled by the receiver");
+            simcall->issuer->exception_ = std::make_exception_ptr(
+                simgrid::CancelException(XBT_THROW_POINT, "Communication canceled by the receiver"));
           break;
 
         default:
@@ -454,7 +459,7 @@ void SIMIX_comm_finish(smx_activity_t synchro)
     }
 
     /* if there is an exception during a waitany or a testany, indicate the position of the failed communication */
-    if (simcall->issuer->exception &&
+    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;
@@ -473,20 +478,16 @@ void SIMIX_comm_finish(smx_activity_t synchro)
 
       // In order to modify the exception we have to rethrow it:
       try {
-        std::rethrow_exception(simcall->issuer->exception);
+        std::rethrow_exception(simcall->issuer->exception_);
       } catch (simgrid::TimeoutError& e) {
         e.value                    = rank;
-        simcall->issuer->exception = std::make_exception_ptr(e);
+        simcall->issuer->exception_ = std::make_exception_ptr(e);
       } catch (simgrid::NetworkFailureException& e) {
         e.value                    = rank;
-        simcall->issuer->exception = std::make_exception_ptr(e);
-      } catch (xbt_ex& e) {
-        if (e.category == cancel_error) {
-          e.value                    = rank;
-          simcall->issuer->exception = std::make_exception_ptr(e);
-        } else {
-          xbt_die("Unexpected xbt_ex(%s). Please enhance this code", xbt_ex_catname(e.category));
-        }
+        simcall->issuer->exception_ = std::make_exception_ptr(e);
+      } catch (simgrid::CancelException& e) {
+        e.value                    = rank;
+        simcall->issuer->exception_ = std::make_exception_ptr(e);
       }
     }
 
@@ -506,7 +507,7 @@ void SIMIX_comm_finish(smx_activity_t synchro)
       }
     }
 
-    if (simcall->issuer->host_->is_on())
+    if (simcall->issuer->get_host()->is_on())
       SIMIX_simcall_answer(simcall);
     else
       simcall->issuer->context_->iwannadie = true;