From 931d9cd88230c4a7e46fade22192a77eadba0649 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Mon, 29 May 2017 01:14:33 +0200 Subject: [PATCH] don't mix the refcount of s4u::Comm and the one of CommImpl --- src/s4u/s4u_comm.cpp | 20 +++----------------- src/simix/smx_network.cpp | 9 +++++---- src/surf/network_cm02.hpp | 3 +-- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/src/s4u/s4u_comm.cpp b/src/s4u/s4u_comm.cpp index 801e9b5f0e..4ecb4e698d 100644 --- a/src/s4u/s4u_comm.cpp +++ b/src/s4u/s4u_comm.cpp @@ -24,7 +24,7 @@ Comm::~Comm() xbt_backtrace_display_current(); } if (pimpl_) - pimpl_->unref(); + SIMIX_comm_unref(pimpl_); } s4u::CommPtr Comm::send_init(s4u::MailboxPtr chan) @@ -97,11 +97,6 @@ void Comm::start() { } else { xbt_die("Cannot start a communication before specifying whether we are the sender or the receiver"); } - while (refcount_ > 1) { // Pass all the refcounts we had to the underlying pimpl since we are delegating the - // refcounting to it afterward - refcount_--; - pimpl_->ref(); - } state_ = started; } void Comm::wait() { @@ -197,23 +192,14 @@ bool Comm::test() { void intrusive_ptr_release(simgrid::s4u::Comm* c) { - if (c->pimpl_ != nullptr) { - if (c->pimpl_->unref()) { - c->pimpl_ = nullptr; - delete c; - } - } else if (c->refcount_.fetch_sub(1, std::memory_order_release) == 1) { + if (c->refcount_.fetch_sub(1, std::memory_order_release) == 1) { std::atomic_thread_fence(std::memory_order_acquire); delete c; } } void intrusive_ptr_add_ref(simgrid::s4u::Comm* c) { - if (c->pimpl_ != nullptr) { - c->pimpl_->ref(); - } else { - c->refcount_.fetch_add(1, std::memory_order_relaxed); - } + c->refcount_.fetch_add(1, std::memory_order_relaxed); } } } // namespaces diff --git a/src/simix/smx_network.cpp b/src/simix/smx_network.cpp index d7096324d1..f1d9614bb5 100644 --- a/src/simix/smx_network.cpp +++ b/src/simix/smx_network.cpp @@ -58,7 +58,7 @@ _find_matching_comm(boost::circular_buffer_space_optimized* dequ XBT_DEBUG("Found a matching communication synchro %p", comm); if (remove_matching) deque->erase(it); - comm = static_cast(SIMIX_comm_ref(comm)); + SIMIX_comm_ref(comm); #if SIMGRID_HAVE_MC comm->mbox_cpy = comm->mbox; #endif @@ -465,12 +465,13 @@ static inline void SIMIX_comm_start(smx_activity_t synchro) simgrid::s4u::Host* sender = comm->src_proc->host; simgrid::s4u::Host* receiver = comm->dst_proc->host; - XBT_DEBUG("Starting communication %p from '%s' to '%s'", synchro, sender->cname(), receiver->cname()); - comm->surf_comm = surf_network_model->communicate(sender, receiver, comm->task_size, comm->rate); comm->surf_comm->setData(synchro); comm->state = SIMIX_RUNNING; + XBT_DEBUG("Starting communication %p from '%s' to '%s' (surf_action: %p)", synchro, sender->cname(), + receiver->cname(), comm->surf_comm); + /* If a link is failed, detect it immediately */ if (comm->surf_comm->getState() == simgrid::surf::Action::State::failed) { XBT_DEBUG("Communication from '%s' to '%s' failed to start because of a link failure", sender->cname(), @@ -527,7 +528,7 @@ void SIMIX_comm_finish(smx_activity_t synchro) /* If the synchro is still in a rendez-vous point then remove from it */ if (comm->mbox) - comm->mbox->remove(synchro); + comm->mbox->remove(comm); XBT_DEBUG("SIMIX_comm_finish: synchro state = %d", (int)synchro->state); diff --git a/src/surf/network_cm02.hpp b/src/surf/network_cm02.hpp index df834a8dd1..04f6d98786 100644 --- a/src/surf/network_cm02.hpp +++ b/src/surf/network_cm02.hpp @@ -1,5 +1,4 @@ -/* Copyright (c) 2013-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2013-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -- 2.20.1