]> AND Public Git Repository - simgrid.git/blobdiff - src/kernel/activity/CommImpl.cpp
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove old wait any simcall
[simgrid.git] / src / kernel / activity / CommImpl.cpp
index eb45116210e301329f7eef70225eaec9b2c7f20d..efdec769a2b940ef9436b19c0d92e4f10b193b77 100644 (file)
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_network, kernel, "Kernel network-related synchronization");
 
-XBT_PRIVATE void simcall_HANDLER_comm_send(smx_simcall_t simcall, smx_actor_t src, smx_mailbox_t mbox, double task_size,
-                                           double rate, unsigned char* src_buff, size_t src_buff_size,
-                                           bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
-                                           void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
-                                           void* data, double timeout)
-{
-  simgrid::kernel::actor::CommIsendSimcall observer(src, mbox, task_size, rate, src_buff, src_buff_size, match_fun,
-                                                    nullptr, copy_data_fun, data, false);
-  simgrid::kernel::activity::ActivityImplPtr comm = simgrid::kernel::activity::CommImpl::isend(&observer);
-  simcall->mc_value_ = 0;
-  comm->wait_for(simcall->issuer_, timeout);
-}
-
-XBT_PRIVATE simgrid::kernel::activity::ActivityImplPtr simcall_HANDLER_comm_isend(
-    smx_simcall_t /*simcall*/, smx_actor_t src_proc, smx_mailbox_t mbox, double task_size, double rate,
-    unsigned char* src_buff, size_t src_buff_size,
-    bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
-    void (*clean_fun)(void*), // used to free the synchro in case of problem after a detached send
-    void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), // used to copy data if not default one
-    void* data, bool detached)
-{
-  simgrid::kernel::actor::CommIsendSimcall observer(src_proc, mbox, task_size, rate, src_buff, src_buff_size, match_fun,
-                                                    nullptr, copy_data_fun, data, false);
-  return simgrid::kernel::activity::CommImpl::isend(&observer);
-}
-
-XBT_PRIVATE void simcall_HANDLER_comm_recv(smx_simcall_t simcall, smx_actor_t receiver, smx_mailbox_t mbox,
-                                           unsigned char* dst_buff, size_t* dst_buff_size,
-                                           bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
-                                           void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
-                                           void* data, double timeout, double rate)
-{
-  simgrid::kernel::actor::CommIrecvSimcall observer(receiver, mbox, dst_buff, dst_buff_size, match_fun, copy_data_fun,
-                                                    data, rate);
-  simgrid::kernel::activity::ActivityImplPtr comm = simgrid::kernel::activity::CommImpl::irecv(&observer);
-  simcall->mc_value_ = 0;
-  comm->wait_for(simcall->issuer_, timeout);
-}
-
-XBT_PRIVATE simgrid::kernel::activity::ActivityImplPtr
-simcall_HANDLER_comm_irecv(smx_simcall_t /*simcall*/, smx_actor_t receiver, smx_mailbox_t mbox, unsigned char* dst_buff,
-                           size_t* dst_buff_size, bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
-                           void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data,
-                           double rate)
-{
-  simgrid::kernel::actor::CommIrecvSimcall observer(receiver, mbox, dst_buff, dst_buff_size, match_fun, copy_data_fun,
-                                                    data, rate);
-  return simgrid::kernel::activity::CommImpl::irecv(&observer);
-}
-
-void simcall_HANDLER_comm_wait(smx_simcall_t simcall, simgrid::kernel::activity::CommImpl* comm, double timeout)
-{
-  comm->wait_for(simcall->issuer_, timeout);
-}
-
-void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, simgrid::kernel::activity::CommImpl* comms[], size_t count,
-                                  double timeout)
-{
-  std::vector<simgrid::kernel::activity::CommImpl*> comms_vec(comms, comms + count);
-  simgrid::kernel::activity::CommImpl::wait_any_for(simcall->issuer_, comms_vec, timeout);
-}
-
 /******************************************************************************/
 /*                    SIMIX_comm_copy_data callbacks                       */
 /******************************************************************************/
@@ -128,6 +66,8 @@ CommImpl& CommImpl::set_rate(double rate)
 }
 CommImpl& CommImpl::set_mailbox(MailboxImpl* mbox)
 {
+  if (mbox != nullptr)
+    mbox_id_ = mbox->get_id();
   mbox_ = mbox;
   return *this;
 }
@@ -278,7 +218,7 @@ ActivityImplPtr CommImpl::isend(actor::CommIsendSimcall* observer)
    *
    * If it is not found then push our communication into the rendez-vous point */
   CommImplPtr other_comm =
-      mbox->find_matching_comm(CommImpl::Type::RECEIVE, observer->match_fun_, observer->get_payload(), this_comm,
+      mbox->find_matching_comm(CommImpl::Type::RECEIVE, observer->get_match_fun(), observer->get_payload(), this_comm,
                                /*done*/ false, /*remove_matching*/ true);
 
   if (not other_comm) {
@@ -299,10 +239,11 @@ ActivityImplPtr CommImpl::isend(actor::CommIsendSimcall* observer)
 
     other_comm->set_state(State::READY);
   }
+  observer->set_comm(other_comm.get());
 
   if (observer->is_detached()) {
     other_comm->detach();
-    other_comm->clean_fun = observer->clean_fun_;
+    other_comm->clean_fun = observer->get_clean_fun();
   } else {
     other_comm->clean_fun = nullptr;
     observer->get_issuer()->activities_.emplace_back(other_comm);
@@ -316,8 +257,8 @@ ActivityImplPtr CommImpl::isend(actor::CommIsendSimcall* observer)
       .set_size(observer->get_payload_size())
       .set_rate(observer->get_rate());
 
-  other_comm->match_fun     = observer->match_fun_;
-  other_comm->copy_data_fun = observer->copy_data_fun_;
+  other_comm->match_fun     = observer->get_match_fun();
+  other_comm->copy_data_fun = observer->get_copy_data_fun();
 
   if (MC_is_active() || MC_record_replay_is_active())
     other_comm->set_state(simgrid::kernel::activity::State::RUNNING);
@@ -338,7 +279,7 @@ ActivityImplPtr CommImpl::irecv(actor::CommIrecvSimcall* observer)
   if (mbox->is_permanent() && mbox->has_some_done_comm()) {
     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(CommImpl::Type::SEND, observer->match_fun_, observer->get_payload(),
+    other_comm = mbox->find_matching_comm(CommImpl::Type::SEND, observer->get_match_fun(), observer->get_payload(),
                                           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) {
@@ -360,7 +301,7 @@ ActivityImplPtr CommImpl::irecv(actor::CommIrecvSimcall* observer)
      * 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(CommImpl::Type::SEND, observer->match_fun_, observer->get_payload(),
+    other_comm = mbox->find_matching_comm(CommImpl::Type::SEND, observer->get_match_fun(), observer->get_payload(),
                                           this_synchro, /*done*/ false, /*remove_matching*/ true);
 
     if (other_comm == nullptr) {
@@ -374,6 +315,7 @@ ActivityImplPtr CommImpl::irecv(actor::CommIrecvSimcall* observer)
     }
     observer->get_issuer()->activities_.emplace_back(other_comm);
   }
+  observer->set_comm(other_comm.get());
 
   /* Setup communication synchro */
   other_comm->dst_actor_ = observer->get_issuer();
@@ -383,8 +325,8 @@ ActivityImplPtr CommImpl::irecv(actor::CommIrecvSimcall* observer)
   if (observer->get_rate() > -1.0 && (other_comm->get_rate() < 0.0 || observer->get_rate() < other_comm->get_rate()))
     other_comm->set_rate(observer->get_rate());
 
-  other_comm->match_fun     = observer->match_fun_;
-  other_comm->copy_data_fun = observer->copy_data_fun_;
+  other_comm->match_fun     = observer->get_match_fun();
+  other_comm->copy_data_fun = observer->get_copy_data_fun();
 
   if (MC_is_active() || MC_record_replay_is_active()) {
     other_comm->set_state(State::RUNNING);
@@ -409,16 +351,8 @@ void CommImpl::wait_for(actor::ActorImpl* issuer, double timeout)
   /* Associate this simcall to the wait synchro */
   register_simcall(&issuer->simcall_);
   if (MC_is_active() || MC_record_replay_is_active()) {
-    int idx = issuer->simcall_.mc_value_;
-    if (idx == 0) {
-      set_state(State::DONE);
-    } else {
-      /* If we reached this point, the wait simcall must have a timeout */
-      /* Otherwise it shouldn't be enabled and executed by the MC */
-      if (timeout < 0.0)
-        THROW_IMPOSSIBLE;
-      set_state(issuer == src_actor_ ? State::SRC_TIMEOUT : State::DST_TIMEOUT);
-    }
+    // FIXME: what about timeouts?
+    set_state(State::DONE);
     finish();
     return;
   }