XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_network, kernel, "Kernel network-related synchronization");
namespace simgrid::kernel::activity {
-xbt::signal<void(CommImpl const&)> CommImpl::on_start;
-xbt::signal<void(CommImpl const&)> CommImpl::on_completion;
-std::function<void(CommImpl*, void*, size_t)> CommImpl::copy_data_callback_ = &s4u::Comm::copy_pointer_callback;
+unsigned CommImpl::next_id_ = 0;
+
+std::function<void(CommImpl*, void*, size_t)> CommImpl::copy_data_callback_ = [](kernel::activity::CommImpl* comm,
+ void* buff, size_t buff_size) {
+ xbt_assert((buff_size == sizeof(void*)), "Cannot copy %zu bytes: must be sizeof(void*)", buff_size);
+ if (comm->dst_buff_ != nullptr) // get_async provided a buffer
+ *(void**)(comm->dst_buff_) = buff;
+ comm->payload_ = buff; // Setup what will be retrieved by s4u::Comm::get_payload()
+};
void CommImpl::set_copy_data_callback(const std::function<void(CommImpl*, void*, size_t)>& callback)
{
{
XBT_DEBUG("Really free communication %p in state %s (detached = %d)", this, get_state_str(), detached_);
- cleanup_surf();
+ clean_action();
if (detached_ && get_state() != State::DONE) {
/* the communication has failed and was detached:
model_action_->set_category(get_tracing_category());
set_start_time(model_action_->get_start_time());
set_state(State::RUNNING);
- on_start(*this);
XBT_DEBUG("Starting communication %p from '%s' to '%s' (model action: %p; state: %s)", this, from_->get_cname(),
to_->get_cname(), model_action_, get_state_str());
XBT_DEBUG("Communication from '%s' to '%s' failed to start because of a link failure", from_->get_cname(),
to_->get_cname());
set_state(State::LINK_FAILURE);
- post();
+ finish();
} else if ((src_actor_ != nullptr && src_actor_->is_suspended()) ||
(dst_actor_ != nullptr && dst_actor_->is_suspended())) {
{
size_t buff_size = src_buff_size_;
/* If there is no data to copy then return */
- if (not src_buff_ || not dst_buff_ || copied_)
+ if (not src_buff_ || not dst_buff_size_ || copied_)
return;
XBT_DEBUG("Copying comm %p data from %s (%p) -> %s (%p) (%zu bytes)", this,
if (MC_is_active() || MC_record_replay_is_active()) {
// FIXME: what about timeouts?
set_state(State::DONE);
- post();
+ finish();
return;
}
ActivityImpl::wait_for(issuer, timeout);
}
}
-/** @brief This is part of the cleanup process, probably an internal command */
-void CommImpl::cleanup_surf()
-{
- clean_action();
-
- if (src_timeout_) {
- src_timeout_->unref();
- src_timeout_ = nullptr;
- }
-
- if (dst_timeout_) {
- dst_timeout_->unref();
- dst_timeout_ = nullptr;
- }
-}
-
-void CommImpl::post()
-{
- on_completion(*this);
-
- /* Update synchro state */
- if (src_timeout_ && src_timeout_->get_state() == resource::Action::State::FINISHED)
- set_state(State::SRC_TIMEOUT);
- else if (dst_timeout_ && dst_timeout_->get_state() == resource::Action::State::FINISHED)
- set_state(State::DST_TIMEOUT);
- else if ((from_ && not from_->is_on()) || (src_timeout_ && src_timeout_->get_state() == resource::Action::State::FAILED))
- set_state(State::SRC_HOST_FAILURE);
- else if ((to_ && not to_->is_on()) || (dst_timeout_ && dst_timeout_->get_state() == resource::Action::State::FAILED))
- set_state(State::DST_HOST_FAILURE);
- else if (model_action_ && model_action_->get_state() == resource::Action::State::FAILED) {
- set_state(State::LINK_FAILURE);
- } else if (get_state() == State::RUNNING) {
- xbt_assert(from_ && from_->is_on());
- xbt_assert(to_ && to_->is_on());
- set_state(State::DONE);
- }
-
- XBT_DEBUG("CommImpl::post(): comm %p, state %s, src_proc %p, dst_proc %p, detached: %d", this, get_state_str(),
- src_actor_.get(), dst_actor_.get(), detached_);
-
- /* destroy the model actions associated with the communication activity */
- cleanup_surf();
-
- /* Answer all simcalls associated with the synchro */
- finish();
-}
void CommImpl::set_exception(actor::ActorImpl* issuer)
{
switch (get_state()) {
void CommImpl::finish()
{
- XBT_DEBUG("CommImpl::finish() in state %s", get_state_str());
+ XBT_DEBUG("CommImpl::finish() comm %p, state %s, src_proc %p, dst_proc %p, detached: %d", this, get_state_str(),
+ src_actor_.get(), dst_actor_.get(), detached_);
+
+ if (get_iface()) {
+ const auto& piface = static_cast<const s4u::Comm&>(*get_iface());
+ set_iface(nullptr); // reset iface to protect against multiple trigger of the on_completion signals
+ piface.fire_on_completion_for_real();
+ piface.fire_on_this_completion_for_real();
+ }
+
+ /* Update synchro state */
+ if (src_timeout_ && src_timeout_->get_state() == resource::Action::State::FINISHED)
+ set_state(State::SRC_TIMEOUT);
+ else if (dst_timeout_ && dst_timeout_->get_state() == resource::Action::State::FINISHED)
+ set_state(State::DST_TIMEOUT);
+ else if ((from_ && not from_->is_on()) ||
+ (src_timeout_ && src_timeout_->get_state() == resource::Action::State::FAILED))
+ set_state(State::SRC_HOST_FAILURE);
+ else if ((to_ && not to_->is_on()) || (dst_timeout_ && dst_timeout_->get_state() == resource::Action::State::FAILED))
+ set_state(State::DST_HOST_FAILURE);
+ else if (model_action_ && model_action_->get_state() == resource::Action::State::FAILED) {
+ set_state(State::LINK_FAILURE);
+ } else if (get_state() == State::RUNNING) {
+ xbt_assert(from_ && from_->is_on());
+ xbt_assert(to_ && to_->is_on());
+ set_state(State::DONE);
+ }
+ src_timeout_ = nullptr;
+ dst_timeout_ = nullptr;
+
+ /* destroy the model actions associated with the communication activity */
+ clean_action();
+
/* If the synchro is still in a rendez-vous point then remove from it */
if (mbox_)
mbox_->remove(this);