From: Arnaud Giersch Date: Sat, 21 Dec 2019 14:55:59 +0000 (+0100) Subject: [sonar] Use a RAII idiom instead of calling lock() explicitely. X-Git-Tag: v3.25~245 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/6438297cb5646fdb26055758cd7bc53894e5b7c9 [sonar] Use a RAII idiom instead of calling lock() explicitely. --- diff --git a/src/kernel/actor/ActorImpl.cpp b/src/kernel/actor/ActorImpl.cpp index 821db95d43..f9b38a5d55 100644 --- a/src/kernel/actor/ActorImpl.cpp +++ b/src/kernel/actor/ActorImpl.cpp @@ -136,6 +136,20 @@ void ActorImpl::detach() context->attach_stop(); } +void ActorImpl::cleanup_from_simix() +{ + const std::lock_guard lock(simix_global->mutex); + simix_global->process_list.erase(pid_); + if (host_ && host_actor_list_hook.is_linked()) + host_->pimpl_->remove_actor(this); + if (not smx_destroy_list_hook.is_linked()) { +#if SIMGRID_HAVE_MC + xbt_dynar_push_as(simix_global->dead_actors_vector, ActorImpl*, this); +#endif + simix_global->actors_to_destroy.push_back(*this); + } +} + void ActorImpl::cleanup() { finished_ = true; @@ -172,20 +186,7 @@ void ActorImpl::cleanup() kill_timer->remove(); kill_timer = nullptr; } - - simix_global->mutex.lock(); - - simix_global->process_list.erase(pid_); - if (host_ && host_actor_list_hook.is_linked()) - host_->pimpl_->remove_actor(this); - if (not smx_destroy_list_hook.is_linked()) { -#if SIMGRID_HAVE_MC - xbt_dynar_push_as(simix_global->dead_actors_vector, ActorImpl*, this); -#endif - simix_global->actors_to_destroy.push_back(*this); - } - - simix_global->mutex.unlock(); + cleanup_from_simix(); context_->iwannadie = false; // don't let the simcall's yield() do a Context::stop(), to avoid infinite loops actor::simcall([this] { s4u::Actor::on_termination(*ciface()); }); diff --git a/src/kernel/actor/ActorImpl.hpp b/src/kernel/actor/ActorImpl.hpp index c0883ae97d..e7ea0d9d7d 100644 --- a/src/kernel/actor/ActorImpl.hpp +++ b/src/kernel/actor/ActorImpl.hpp @@ -107,6 +107,7 @@ public: private: s4u::Actor piface_; // Our interface is part of ourselves + void cleanup_from_simix(); void undaemonize(); public: