From d68a0ac239494f0a1c7f21b7c195f453ee7a31eb Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 6 Jun 2017 08:16:34 +0200 Subject: [PATCH] first attempt (ongoing WIP) --- include/simgrid/forward.h | 14 ++++- include/simgrid/s4u/Activity.hpp | 2 +- src/kernel/activity/MailboxImpl.cpp | 5 +- src/kernel/activity/MailboxImpl.hpp | 2 +- src/kernel/activity/SynchroIo.cpp | 6 +-- src/kernel/activity/SynchroIo.hpp | 17 +++--- src/kernel/activity/SynchroRaw.cpp | 8 +-- src/kernel/activity/SynchroRaw.hpp | 17 +++--- .../CommunicationDeterminismChecker.cpp | 2 +- src/mc/mc_base.cpp | 4 +- src/mc/mc_state.h | 2 +- src/msg/msg_gos.cpp | 22 ++++---- src/msg/msg_private.h | 4 +- src/s4u/s4u_comm.cpp | 3 +- src/simix/ActorImpl.cpp | 53 +++++++++++-------- src/simix/libsmx.cpp | 3 +- src/simix/smx_global.cpp | 14 ++--- src/simix/smx_host.cpp | 20 ++++--- src/simix/smx_host_private.h | 2 +- src/simix/smx_io.cpp | 12 ++--- src/simix/smx_network.cpp | 52 ++++++++++-------- src/simix/smx_synchro.cpp | 13 ++--- src/smpi/smpi_global.cpp | 3 +- src/smpi/smpi_request.cpp | 6 +-- 24 files changed, 165 insertions(+), 121 deletions(-) diff --git a/include/simgrid/forward.h b/include/simgrid/forward.h index 64730e0711..f4fede1504 100644 --- a/include/simgrid/forward.h +++ b/include/simgrid/forward.h @@ -17,8 +17,20 @@ namespace simgrid { namespace kernel { namespace activity { class ActivityImpl; + using ActivityImplPtr = boost::intrusive_ptr; XBT_PUBLIC(void) intrusive_ptr_add_ref(ActivityImpl* activity); XBT_PUBLIC(void) intrusive_ptr_release(ActivityImpl* activity); + + class CommImpl; + using CommImplPtr = boost::intrusive_ptr; + class ExecImpl; + using ExecImplPtr = boost::intrusive_ptr; + class IoImpl; + using IoImplPtr = boost::intrusive_ptr; + class RawImpl; + using RawImplPtr = boost::intrusive_ptr; + class SleepImpl; + using SleepImplPtr = boost::intrusive_ptr; } namespace routing { class NetPoint; @@ -46,7 +58,7 @@ typedef simgrid::s4u::Link s4u_Link; typedef simgrid::s4u::File s4u_File; typedef simgrid::s4u::Storage s4u_Storage; typedef simgrid::s4u::NetZone s4u_NetZone; -typedef simgrid::kernel::activity::ActivityImpl* smx_activity_t; +typedef boost::intrusive_ptr smx_activity_t; typedef simgrid::kernel::routing::NetPoint routing_NetPoint; typedef simgrid::surf::Resource surf_Resource; typedef simgrid::trace_mgr::trace tmgr_Trace; diff --git a/include/simgrid/s4u/Activity.hpp b/include/simgrid/s4u/Activity.hpp index aaa9e38dd4..57ab0371c0 100644 --- a/include/simgrid/s4u/Activity.hpp +++ b/include/simgrid/s4u/Activity.hpp @@ -61,7 +61,7 @@ public: void *getUserData() { return userData_; } private: - simgrid::kernel::activity::ActivityImpl *pimpl_ = nullptr; + simgrid::kernel::activity::ActivityImplPtr pimpl_ = nullptr; e_s4u_activity_state_t state_ = inited; double remains_ = 0; void *userData_ = nullptr; diff --git a/src/kernel/activity/MailboxImpl.cpp b/src/kernel/activity/MailboxImpl.cpp index 8c66d352d1..9c7ef0404f 100644 --- a/src/kernel/activity/MailboxImpl.cpp +++ b/src/kernel/activity/MailboxImpl.cpp @@ -53,7 +53,7 @@ void MailboxImpl::setReceiver(s4u::ActorPtr actor) /** @brief Pushes a communication activity into a mailbox * @param comm What to add */ -void MailboxImpl::push(activity::CommImpl* comm) +void MailboxImpl::push(activity::CommImplPtr comm) { this->comm_queue.push_back(comm); comm->mbox = this; @@ -64,7 +64,8 @@ void MailboxImpl::push(activity::CommImpl* comm) */ void MailboxImpl::remove(smx_activity_t activity) { - simgrid::kernel::activity::CommImpl* comm = static_cast(activity); + simgrid::kernel::activity::CommImplPtr comm = + boost::static_pointer_cast(activity); comm->mbox = nullptr; for (auto it = this->comm_queue.begin(); it != this->comm_queue.end(); it++) diff --git a/src/kernel/activity/MailboxImpl.hpp b/src/kernel/activity/MailboxImpl.hpp index ea9b272fba..6f13daafe5 100644 --- a/src/kernel/activity/MailboxImpl.hpp +++ b/src/kernel/activity/MailboxImpl.hpp @@ -31,7 +31,7 @@ public: static MailboxImpl* byNameOrNull(const char* name); static MailboxImpl* byNameOrCreate(const char* name); void setReceiver(s4u::ActorPtr actor); - void push(activity::CommImpl* comm); + void push(activity::CommImplPtr comm); void remove(smx_activity_t activity); simgrid::s4u::Mailbox piface_; // Our interface char* name_; diff --git a/src/kernel/activity/SynchroIo.cpp b/src/kernel/activity/SynchroIo.cpp index cef2ced0f2..012165b614 100644 --- a/src/kernel/activity/SynchroIo.cpp +++ b/src/kernel/activity/SynchroIo.cpp @@ -7,19 +7,19 @@ #include "src/surf/surf_interface.hpp" #include "src/simix/smx_private.h" -void simgrid::kernel::activity::Io::suspend() +void simgrid::kernel::activity::IoImpl::suspend() { if (surf_io) surf_io->suspend(); } -void simgrid::kernel::activity::Io::resume() +void simgrid::kernel::activity::IoImpl::resume() { if (surf_io) surf_io->resume(); } -void simgrid::kernel::activity::Io::post() +void simgrid::kernel::activity::IoImpl::post() { for (smx_simcall_t simcall : simcalls) { switch (simcall->call) { diff --git a/src/kernel/activity/SynchroIo.hpp b/src/kernel/activity/SynchroIo.hpp index b9c405daa3..7a229bf749 100644 --- a/src/kernel/activity/SynchroIo.hpp +++ b/src/kernel/activity/SynchroIo.hpp @@ -13,14 +13,15 @@ namespace simgrid { namespace kernel { namespace activity { - XBT_PUBLIC_CLASS Io : public ActivityImpl { - public: - void suspend() override; - void resume() override; - void post() override; - - sg_host_t host = nullptr; - surf_action_t surf_io = nullptr; +XBT_PUBLIC_CLASS IoImpl : public ActivityImpl +{ +public: + void suspend() override; + void resume() override; + void post() override; + + sg_host_t host = nullptr; + surf_action_t surf_io = nullptr; }; }}} // namespace simgrid::kernel::activity diff --git a/src/kernel/activity/SynchroRaw.cpp b/src/kernel/activity/SynchroRaw.cpp index 0f9e29f30d..509c41d5cd 100644 --- a/src/kernel/activity/SynchroRaw.cpp +++ b/src/kernel/activity/SynchroRaw.cpp @@ -9,21 +9,21 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_synchro); -simgrid::kernel::activity::Raw::~Raw() +simgrid::kernel::activity::RawImpl::~RawImpl() { sleep->unref(); } -void simgrid::kernel::activity::Raw::suspend() +void simgrid::kernel::activity::RawImpl::suspend() { /* The suspension of raw synchros is delayed to when the process is rescheduled. */ } -void simgrid::kernel::activity::Raw::resume() +void simgrid::kernel::activity::RawImpl::resume() { /* I cannot resume raw synchros directly. This is delayed to when the process is rescheduled at * the end of the synchro. */ } -void simgrid::kernel::activity::Raw::post() +void simgrid::kernel::activity::RawImpl::post() { XBT_IN("(%p)",this); if (sleep->getState() == simgrid::surf::Action::State::failed) diff --git a/src/kernel/activity/SynchroRaw.hpp b/src/kernel/activity/SynchroRaw.hpp index b85e06f638..f5ef90d2fc 100644 --- a/src/kernel/activity/SynchroRaw.hpp +++ b/src/kernel/activity/SynchroRaw.hpp @@ -14,14 +14,15 @@ namespace kernel { namespace activity { /** Used to implement mutexes, semaphores and conditions */ - XBT_PUBLIC_CLASS Raw : public ActivityImpl { - public: - ~Raw() override; - void suspend() override; - void resume() override; - void post() override; - - surf_action_t sleep = nullptr; +XBT_PUBLIC_CLASS RawImpl : public ActivityImpl +{ +public: + ~RawImpl() override; + void suspend() override; + void resume() override; + void post() override; + + surf_action_t sleep = nullptr; }; }}} // namespace simgrid::kernel::activity diff --git a/src/mc/checker/CommunicationDeterminismChecker.cpp b/src/mc/checker/CommunicationDeterminismChecker.cpp index 2410b9d1dc..bd712ee457 100644 --- a/src/mc/checker/CommunicationDeterminismChecker.cpp +++ b/src/mc/checker/CommunicationDeterminismChecker.cpp @@ -185,7 +185,7 @@ void CommunicationDeterminismChecker::get_comm_pattern(xbt_dynar_t list, smx_sim if (call_type == MC_CALL_TYPE_SEND) { /* Create comm pattern */ pattern->type = simgrid::mc::PatternCommunicationType::send; - pattern->comm_addr = simcall_comm_isend__get__result(request); + pattern->comm_addr = &*simcall_comm_isend__get__result(request); simgrid::mc::Remote temp_synchro; mc_model_checker->process().read(temp_synchro, diff --git a/src/mc/mc_base.cpp b/src/mc/mc_base.cpp index ee5098ee8b..f1b7d8054c 100644 --- a/src/mc/mc_base.cpp +++ b/src/mc/mc_base.cpp @@ -79,7 +79,7 @@ bool request_is_enabled(smx_simcall_t req) { /* FIXME: check also that src and dst processes are not suspended */ simgrid::kernel::activity::CommImpl* act = - static_cast(simcall_comm_wait__get__comm(req)); + static_cast(&*simcall_comm_wait__get__comm(req)); #if SIMGRID_HAVE_MC // Fetch from MCed memory: @@ -107,7 +107,7 @@ bool request_is_enabled(smx_simcall_t req) case SIMCALL_COMM_WAITANY: { xbt_dynar_t comms; simgrid::kernel::activity::CommImpl* act = - static_cast(simcall_comm_wait__get__comm(req)); + static_cast(&*simcall_comm_wait__get__comm(req)); #if SIMGRID_HAVE_MC s_xbt_dynar_t comms_buffer; diff --git a/src/mc/mc_state.h b/src/mc/mc_state.h index e4eb0d9d30..d6ee81450e 100644 --- a/src/mc/mc_state.h +++ b/src/mc/mc_state.h @@ -24,7 +24,7 @@ enum class PatternCommunicationType { struct PatternCommunication { int num = 0; - smx_activity_t comm_addr; + simgrid::kernel::activity::CommImpl* comm_addr; PatternCommunicationType type = PatternCommunicationType::send; unsigned long src_proc = 0; unsigned long dst_proc = 0; diff --git a/src/msg/msg_gos.cpp b/src/msg/msg_gos.cpp index 77c1b3d892..27fd37dc22 100644 --- a/src/msg/msg_gos.cpp +++ b/src/msg/msg_gos.cpp @@ -5,6 +5,7 @@ #include +#include "src/kernel/activity/ExecImpl.hpp" #include "src/msg/msg_private.h" #include "src/simix/smx_private.h" /* MSG_task_listen looks inside the rdv directly. Not clean. */ @@ -66,12 +67,13 @@ msg_error_t MSG_parallel_task_execute_with_timeout(msg_task_t task, double timeo simdata->setUsed(); if (simdata->host_nb > 0) { - simdata->compute = static_cast(simcall_execution_parallel_start( - task->name, simdata->host_nb, simdata->host_list, simdata->flops_parallel_amount, - simdata->bytes_parallel_amount, 1.0, -1.0, timeout)); + simdata->compute = + boost::static_pointer_cast(simcall_execution_parallel_start( + task->name, simdata->host_nb, simdata->host_list, simdata->flops_parallel_amount, + simdata->bytes_parallel_amount, 1.0, -1.0, timeout)); XBT_DEBUG("Parallel execution action created: %p", simdata->compute); } else { - simdata->compute = static_cast( + simdata->compute = boost::static_pointer_cast( simcall_execution_start(task->name, simdata->flops_amount, simdata->priority, simdata->bound)); } simcall_set_category(simdata->compute, task->category); @@ -315,7 +317,7 @@ static inline msg_comm_t MSG_task_isend_internal(msg_task_t task, const char *al /* Send it by calling SIMIX network layer */ smx_activity_t act = simcall_comm_isend(myself->getImpl(), mailbox->getImpl(), t_simdata->bytes_amount, t_simdata->rate, task, sizeof(void *), match_fun, cleanup, nullptr, match_data,detached); - t_simdata->comm = static_cast(act); + t_simdata->comm = boost::static_pointer_cast(act); msg_comm_t comm = nullptr; if (not detached) { @@ -522,7 +524,7 @@ int MSG_comm_testany(xbt_dynar_t comms) int finished_index = -1; /* Create the equivalent array with SIMIX objects: */ - std::vector s_comms; + std::vector s_comms; s_comms.reserve(xbt_dynar_length(comms)); msg_comm_t comm; unsigned int cursor; @@ -710,7 +712,8 @@ msg_task_t MSG_comm_get_task(msg_comm_t comm) */ void MSG_comm_copy_data_from_SIMIX(smx_activity_t synchro, void* buff, size_t buff_size) { - simgrid::kernel::activity::CommImpl* comm = static_cast(synchro); + simgrid::kernel::activity::CommImplPtr comm = + boost::static_pointer_cast(synchro); SIMIX_comm_copy_pointer_callback(comm, buff, buff_size); @@ -797,7 +800,7 @@ msg_error_t MSG_task_send_with_timeout(msg_task_t task, const char *alias, doubl t_simdata->rate, task, sizeof(void *), nullptr, nullptr, nullptr, task, 0); if (TRACE_is_enabled()) simcall_set_category(comm, task->category); - t_simdata->comm = static_cast(comm); + t_simdata->comm = boost::static_pointer_cast(comm); simcall_comm_wait(comm, timeout); comm->unref(); } @@ -868,7 +871,8 @@ int MSG_task_listen(const char *alias) int MSG_task_listen_from(const char *alias) { simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(alias); - simgrid::kernel::activity::CommImpl* comm = static_cast(mbox->front()); + simgrid::kernel::activity::CommImplPtr comm = + boost::static_pointer_cast(mbox->front()); if (not comm) return -1; diff --git a/src/msg/msg_private.h b/src/msg/msg_private.h index b0831034d1..00164dbd14 100644 --- a/src/msg/msg_private.h +++ b/src/msg/msg_private.h @@ -42,8 +42,8 @@ typedef struct simdata_task { this->isused = false; } - simgrid::kernel::activity::ExecImpl* compute = nullptr; /* SIMIX modeling of computation */ - simgrid::kernel::activity::CommImpl* comm = nullptr; /* SIMIX modeling of communication */ + simgrid::kernel::activity::ExecImplPtr compute = nullptr; /* SIMIX modeling of computation */ + simgrid::kernel::activity::CommImplPtr comm = nullptr; /* SIMIX modeling of communication */ double bytes_amount = 0.0; /* Data size */ double flops_amount = 0.0; /* Computation size */ msg_process_t sender = nullptr; diff --git a/src/s4u/s4u_comm.cpp b/src/s4u/s4u_comm.cpp index c168cffad2..8340bd320b 100644 --- a/src/s4u/s4u_comm.cpp +++ b/src/s4u/s4u_comm.cpp @@ -177,7 +177,8 @@ s4u::CommPtr Comm::recv_async(MailboxPtr dest, void** data) void Comm::cancel() { - simgrid::kernel::activity::CommImpl* commPimpl = static_cast(pimpl_); + simgrid::kernel::activity::CommImplPtr commPimpl = + boost::static_pointer_cast(pimpl_); commPimpl->cancel(); } diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index 2c59aab6d3..d105dffe43 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -95,7 +95,8 @@ void SIMIX_process_cleanup(smx_actor_t process) /* cancel non-blocking communications */ smx_activity_t synchro = static_cast(process->comms.front()); while (not process->comms.empty()) { - simgrid::kernel::activity::CommImpl* comm = static_cast(synchro); + simgrid::kernel::activity::CommImplPtr comm = + boost::static_pointer_cast(synchro); /* make sure no one will finish the comm after this process is destroyed, * because src_proc or dst_proc would be an invalid pointer */ @@ -423,14 +424,16 @@ void SIMIX_process_kill(smx_actor_t process, smx_actor_t issuer) { /* destroy the blocking synchro if any */ if (process->waiting_synchro) { - simgrid::kernel::activity::ExecImpl* exec = - dynamic_cast(process->waiting_synchro); - simgrid::kernel::activity::CommImpl* comm = - dynamic_cast(process->waiting_synchro); - simgrid::kernel::activity::SleepImpl* sleep = - dynamic_cast(process->waiting_synchro); - simgrid::kernel::activity::Raw *raw = dynamic_cast(process->waiting_synchro); - simgrid::kernel::activity::Io *io = dynamic_cast(process->waiting_synchro); + simgrid::kernel::activity::ExecImplPtr exec = + boost::dynamic_pointer_cast(process->waiting_synchro); + simgrid::kernel::activity::CommImplPtr comm = + boost::dynamic_pointer_cast(process->waiting_synchro); + simgrid::kernel::activity::SleepImplPtr sleep = + boost::dynamic_pointer_cast(process->waiting_synchro); + simgrid::kernel::activity::RawImplPtr raw = + boost::dynamic_pointer_cast(process->waiting_synchro); + simgrid::kernel::activity::IoImplPtr io = + boost::dynamic_pointer_cast(process->waiting_synchro); if (exec != nullptr) { exec->unref(); @@ -448,7 +451,7 @@ void SIMIX_process_kill(smx_actor_t process, smx_actor_t issuer) { } else if (raw != nullptr) { SIMIX_synchro_stop_waiting(process, &process->simcall); - delete process->waiting_synchro; + process->waiting_synchro->unref(); } else if (io != nullptr) { SIMIX_io_destroy(process->waiting_synchro); @@ -485,21 +488,21 @@ void SIMIX_process_throw(smx_actor_t process, xbt_errcat_t cat, int value, const /* cancel the blocking synchro if any */ if (process->waiting_synchro) { - simgrid::kernel::activity::ExecImpl* exec = - dynamic_cast(process->waiting_synchro); + simgrid::kernel::activity::ExecImplPtr exec = + boost::dynamic_pointer_cast(process->waiting_synchro); if (exec != nullptr) { SIMIX_execution_cancel(process->waiting_synchro); } - simgrid::kernel::activity::CommImpl* comm = - dynamic_cast(process->waiting_synchro); + simgrid::kernel::activity::CommImplPtr comm = + boost::dynamic_pointer_cast(process->waiting_synchro); if (comm != nullptr) { process->comms.remove(comm); comm->cancel(); } - simgrid::kernel::activity::SleepImpl* sleep = - dynamic_cast(process->waiting_synchro); + simgrid::kernel::activity::SleepImplPtr sleep = + boost::dynamic_pointer_cast(process->waiting_synchro); if (sleep != nullptr) { SIMIX_process_sleep_destroy(process->waiting_synchro); if (not xbt_dynar_member(simix_global->process_to_run, &(process)) && process != SIMIX_process_self()) { @@ -508,12 +511,14 @@ void SIMIX_process_throw(smx_actor_t process, xbt_errcat_t cat, int value, const } } - simgrid::kernel::activity::Raw *raw = dynamic_cast(process->waiting_synchro); + simgrid::kernel::activity::RawImplPtr raw = + boost::dynamic_pointer_cast(process->waiting_synchro); if (raw != nullptr) { SIMIX_synchro_stop_waiting(process, &process->simcall); } - simgrid::kernel::activity::Io *io = dynamic_cast(process->waiting_synchro); + simgrid::kernel::activity::IoImplPtr io = + boost::dynamic_pointer_cast(process->waiting_synchro); if (io != nullptr) { SIMIX_io_destroy(process->waiting_synchro); } @@ -694,7 +699,8 @@ void simcall_HANDLER_process_join(smx_simcall_t simcall, smx_actor_t process, do simcall->issuer->waiting_synchro = sync; } -static int SIMIX_process_join_finish(smx_process_exit_status_t status, smx_activity_t synchro){ +static int SIMIX_process_join_finish(smx_process_exit_status_t status, void* synchro) +{ simgrid::kernel::activity::SleepImpl* sleep = static_cast(synchro); if (sleep->surf_sleep) { @@ -724,14 +730,14 @@ static int SIMIX_process_join_finish(smx_process_exit_status_t status, smx_activ smx_activity_t SIMIX_process_join(smx_actor_t issuer, smx_actor_t process, double timeout) { smx_activity_t res = SIMIX_process_sleep(issuer, timeout); - static_cast(res)->ref(); + (&*res)->ref(); /* We are leaking the process here, but if we don't take the ref, we get a "use after free". * The correct solution would be to derivate the type SynchroSleep into a SynchroProcessJoin, * but the code is not clean enough for now for this. * The C API should first be properly replaced with the C++ one, which is a fair amount of work. */ intrusive_ptr_add_ref(process); - SIMIX_process_on_exit(process, (int_f_pvoid_pvoid_t)SIMIX_process_join_finish, res); + SIMIX_process_on_exit(process, (int_f_pvoid_pvoid_t)SIMIX_process_join_finish, &*res); return res; } @@ -757,7 +763,7 @@ smx_activity_t SIMIX_process_sleep(smx_actor_t process, double duration) simgrid::kernel::activity::SleepImpl* synchro = new simgrid::kernel::activity::SleepImpl(); synchro->host = host; - synchro->surf_sleep = host->pimpl_cpu->sleep(duration); + synchro->surf_sleep = host->pimpl_cpu->sleep(duration); synchro->surf_sleep->setData(synchro); XBT_DEBUG("Create sleep synchronization %p", synchro); @@ -767,7 +773,8 @@ smx_activity_t SIMIX_process_sleep(smx_actor_t process, double duration) void SIMIX_process_sleep_destroy(smx_activity_t synchro) { XBT_DEBUG("Destroy synchro %p", synchro); - simgrid::kernel::activity::SleepImpl* sleep = static_cast(synchro); + simgrid::kernel::activity::SleepImplPtr sleep = + boost::dynamic_pointer_cast(synchro); if (sleep->surf_sleep) { sleep->surf_sleep->unref(); diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index ddb760abb6..5c1ee870bf 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -459,7 +459,8 @@ smx_activity_t simcall_comm_iprobe(smx_mailbox_t mbox, int type, int src, int ta void simcall_comm_cancel(smx_activity_t synchro) { simgrid::simix::kernelImmediate([synchro] { - simgrid::kernel::activity::CommImpl* comm = static_cast(synchro); + simgrid::kernel::activity::CommImplPtr comm = + boost::static_pointer_cast(synchro); comm->cancel(); }); } diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index 6511f0cf18..808f19a1ac 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -356,7 +356,7 @@ static void SIMIX_wake_processes() XBT_DEBUG("Handling the processes whose action failed (if any)"); while ((action = surf_model_extract_failed_action_set(model))) { XBT_DEBUG(" Handling Action %p",action); - SIMIX_simcall_exit((smx_activity_t) action->getData()); + SIMIX_simcall_exit(static_cast(action->getData())); } XBT_DEBUG("Handling the processes whose action terminated normally (if any)"); while ((action = surf_model_extract_done_action_set(model))) { @@ -364,7 +364,7 @@ static void SIMIX_wake_processes() if (action->getData() == nullptr) XBT_DEBUG("probably vcpu's action %p, skip", action); else - SIMIX_simcall_exit((smx_activity_t) action->getData()); + SIMIX_simcall_exit(static_cast(action->getData())); } } } @@ -653,19 +653,19 @@ void SIMIX_display_process_status() const char* synchro_description = "unknown"; - if (dynamic_cast(process->waiting_synchro) != nullptr) + if (boost::dynamic_pointer_cast(process->waiting_synchro) != nullptr) synchro_description = "execution"; - if (dynamic_cast(process->waiting_synchro) != nullptr) + if (boost::dynamic_pointer_cast(process->waiting_synchro) != nullptr) synchro_description = "communication"; - if (dynamic_cast(process->waiting_synchro) != nullptr) + if (boost::dynamic_pointer_cast(process->waiting_synchro) != nullptr) synchro_description = "sleeping"; - if (dynamic_cast(process->waiting_synchro) != nullptr) + if (boost::dynamic_pointer_cast(process->waiting_synchro) != nullptr) synchro_description = "synchronization"; - if (dynamic_cast(process->waiting_synchro) != nullptr) + if (boost::dynamic_pointer_cast(process->waiting_synchro) != nullptr) synchro_description = "I/O"; diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index e4592493c0..6fd7c620e0 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -215,7 +215,8 @@ smx_activity_t SIMIX_execution_parallel_start(const char* name, int host_nb, sg_ void SIMIX_execution_cancel(smx_activity_t synchro) { XBT_DEBUG("Cancel synchro %p", synchro); - simgrid::kernel::activity::ExecImpl* exec = static_cast(synchro); + simgrid::kernel::activity::ExecImplPtr exec = + boost::static_pointer_cast(synchro); if (exec->surf_exec) exec->surf_exec->cancel(); @@ -223,21 +224,24 @@ void SIMIX_execution_cancel(smx_activity_t synchro) void SIMIX_execution_set_priority(smx_activity_t synchro, double priority) { - simgrid::kernel::activity::ExecImpl* exec = static_cast(synchro); + simgrid::kernel::activity::ExecImplPtr exec = + boost::static_pointer_cast(synchro); if(exec->surf_exec) exec->surf_exec->setPriority(priority); } void SIMIX_execution_set_bound(smx_activity_t synchro, double bound) { - simgrid::kernel::activity::ExecImpl* exec = static_cast(synchro); + simgrid::kernel::activity::ExecImplPtr exec = + boost::static_pointer_cast(synchro); if(exec->surf_exec) static_cast(exec->surf_exec)->setBound(bound); } void simcall_HANDLER_execution_wait(smx_simcall_t simcall, smx_activity_t synchro) { - simgrid::kernel::activity::ExecImpl* exec = static_cast(synchro); + simgrid::kernel::activity::ExecImplPtr exec = + boost::static_pointer_cast(synchro); XBT_DEBUG("Wait for execution of synchro %p, state %d", synchro, (int)synchro->state); /* Associate this simcall to the synchro */ @@ -256,7 +260,7 @@ void simcall_HANDLER_execution_wait(smx_simcall_t simcall, smx_activity_t synchr SIMIX_execution_finish(exec); } -void SIMIX_execution_finish(simgrid::kernel::activity::ExecImpl* exec) +void SIMIX_execution_finish(simgrid::kernel::activity::ExecImplPtr exec) { for (smx_simcall_t simcall : exec->simcalls) { switch (exec->state) { @@ -304,13 +308,15 @@ void SIMIX_set_category(smx_activity_t synchro, const char *category) if (synchro->state != SIMIX_RUNNING) return; - simgrid::kernel::activity::ExecImpl* exec = dynamic_cast(synchro); + simgrid::kernel::activity::ExecImplPtr exec = + boost::dynamic_pointer_cast(synchro); if (exec != nullptr) { exec->surf_exec->setCategory(category); return; } - simgrid::kernel::activity::CommImpl* comm = dynamic_cast(synchro); + simgrid::kernel::activity::CommImplPtr comm = + boost::dynamic_pointer_cast(synchro); if (comm != nullptr) { comm->surf_comm->setCategory(category); } diff --git a/src/simix/smx_host_private.h b/src/simix/smx_host_private.h index 91149d1479..7537eb4245 100644 --- a/src/simix/smx_host_private.h +++ b/src/simix/smx_host_private.h @@ -57,7 +57,7 @@ XBT_PRIVATE void SIMIX_execution_cancel(smx_activity_t synchro); XBT_PRIVATE void SIMIX_execution_set_priority(smx_activity_t synchro, double priority); XBT_PRIVATE void SIMIX_execution_set_bound(smx_activity_t synchro, double bound); -XBT_PRIVATE void SIMIX_execution_finish(simgrid::kernel::activity::ExecImpl* exec); +XBT_PRIVATE void SIMIX_execution_finish(simgrid::kernel::activity::ExecImplPtr exec); XBT_PRIVATE void SIMIX_set_category(smx_activity_t synchro, const char *category); diff --git a/src/simix/smx_io.cpp b/src/simix/smx_io.cpp index 9ba2b7e3b7..4371b8da76 100644 --- a/src/simix/smx_io.cpp +++ b/src/simix/smx_io.cpp @@ -33,7 +33,7 @@ smx_activity_t SIMIX_file_read(smx_file_t fd, sg_size_t size, sg_host_t host) if (host->isOff()) THROWF(host_error, 0, "Host %s failed, you cannot call this function", host->cname()); - simgrid::kernel::activity::Io *synchro = new simgrid::kernel::activity::Io(); + simgrid::kernel::activity::IoImpl* synchro = new simgrid::kernel::activity::IoImpl(); synchro->host = host; synchro->surf_io = surf_host_read(host, fd->surf_file, size); @@ -56,7 +56,7 @@ smx_activity_t SIMIX_file_write(smx_file_t fd, sg_size_t size, sg_host_t host) if (host->isOff()) THROWF(host_error, 0, "Host %s failed, you cannot call this function", host->cname()); - simgrid::kernel::activity::Io *synchro = new simgrid::kernel::activity::Io(); + simgrid::kernel::activity::IoImpl* synchro = new simgrid::kernel::activity::IoImpl(); synchro->host = host; synchro->surf_io = surf_host_write(host, fd->surf_file, size); synchro->surf_io->setData(synchro); @@ -78,7 +78,7 @@ smx_activity_t SIMIX_file_open(const char* fullpath, sg_host_t host) if (host->isOff()) THROWF(host_error, 0, "Host %s failed, you cannot call this function", host->cname()); - simgrid::kernel::activity::Io *synchro = new simgrid::kernel::activity::Io(); + simgrid::kernel::activity::IoImpl* synchro = new simgrid::kernel::activity::IoImpl(); synchro->host = host; synchro->surf_io = surf_host_open(host, fullpath); synchro->surf_io->setData(synchro); @@ -100,7 +100,7 @@ smx_activity_t SIMIX_file_close(smx_file_t fd, sg_host_t host) if (host->isOff()) THROWF(host_error, 0, "Host %s failed, you cannot call this function", host->cname()); - simgrid::kernel::activity::Io *synchro = new simgrid::kernel::activity::Io(); + simgrid::kernel::activity::IoImpl* synchro = new simgrid::kernel::activity::IoImpl(); synchro->host = host; synchro->surf_io = surf_host_close(host, fd->surf_file); synchro->surf_io->setData(synchro); @@ -178,11 +178,11 @@ int SIMIX_file_move(smx_actor_t process, smx_file_t file, const char* fullpath) void SIMIX_io_destroy(smx_activity_t synchro) { - simgrid::kernel::activity::Io *io = static_cast(synchro); + simgrid::kernel::activity::IoImplPtr io = boost::static_pointer_cast(synchro); XBT_DEBUG("Destroy synchro %p", synchro); if (io->surf_io) io->surf_io->unref(); - delete io; + io->unref(); } void SIMIX_io_finish(smx_activity_t synchro) diff --git a/src/simix/smx_network.cpp b/src/simix/smx_network.cpp index 1fbcb08dde..09b33a8804 100644 --- a/src/simix/smx_network.cpp +++ b/src/simix/smx_network.cpp @@ -27,7 +27,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_network, simix, "SIMIX network-related syn static void SIMIX_waitany_remove_simcall_from_actions(smx_simcall_t simcall); static void SIMIX_comm_copy_data(smx_activity_t comm); static void SIMIX_comm_start(smx_activity_t synchro); -static simgrid::kernel::activity::CommImpl* +static simgrid::kernel::activity::CommImplPtr _find_matching_comm(boost::circular_buffer_space_optimized* deque, e_smx_comm_type_t type, int (*match_fun)(void*, void*, smx_activity_t), void* user_data, smx_activity_t my_synchro, bool remove_matching); @@ -37,7 +37,7 @@ _find_matching_comm(boost::circular_buffer_space_optimized* dequ * \param type The type of communication we are looking for (comm_send, comm_recv) * \return The communication activity if found, nullptr otherwise */ -static simgrid::kernel::activity::CommImpl* +static simgrid::kernel::activity::CommImplPtr _find_matching_comm(boost::circular_buffer_space_optimized* deque, e_smx_comm_type_t type, int (*match_fun)(void*, void*, smx_activity_t), void* this_user_data, smx_activity_t my_synchro, bool remove_matching) @@ -46,7 +46,8 @@ _find_matching_comm(boost::circular_buffer_space_optimized* dequ for(auto it = deque->begin(); it != deque->end(); it++){ smx_activity_t synchro = *it; - simgrid::kernel::activity::CommImpl* comm = static_cast(synchro); + simgrid::kernel::activity::CommImplPtr comm = + boost::dynamic_pointer_cast(synchro); if (comm->type == SIMIX_COMM_SEND) { other_user_data = comm->src_data; @@ -105,7 +106,7 @@ XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_isend(smx_simcall_t simcall, smx * 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::CommImpl* other_comm = + simgrid::kernel::activity::CommImplPtr other_comm = _find_matching_comm(&mbox->comm_queue, SIMIX_COMM_RECEIVE, match_fun, data, this_comm, /*remove_matching*/ true); if (not other_comm) { @@ -185,10 +186,11 @@ smx_activity_t SIMIX_comm_irecv(smx_actor_t dst_proc, smx_mailbox_t mbox, void * void (*copy_data_fun)(smx_activity_t, void*, size_t), // used to copy data if not default one void *data, double rate) { - simgrid::kernel::activity::CommImpl* this_synchro = new simgrid::kernel::activity::CommImpl(SIMIX_COMM_RECEIVE); + simgrid::kernel::activity::CommImplPtr this_synchro = + simgrid::kernel::activity::CommImplPtr(new simgrid::kernel::activity::CommImpl(SIMIX_COMM_RECEIVE)); XBT_DEBUG("recv from %p %p. this_synchro=%p", mbox, &mbox->comm_queue, this_synchro); - simgrid::kernel::activity::CommImpl* other_comm; + simgrid::kernel::activity::CommImplPtr other_comm; //communication already done, get it inside the list of completed comms if (mbox->permanent_receiver != nullptr && not mbox->done_comm_queue.empty()) { @@ -230,8 +232,6 @@ smx_activity_t SIMIX_comm_irecv(smx_actor_t dst_proc, smx_mailbox_t mbox, void * } else { XBT_DEBUG("Match my %p with the existing %p", this_synchro, other_comm); - other_comm = static_cast(other_comm); - other_comm->state = SIMIX_READY; other_comm->type = SIMIX_COMM_READY; this_synchro->unref(); @@ -318,7 +318,8 @@ void simcall_HANDLER_comm_wait(smx_simcall_t simcall, smx_activity_t synchro, do if (timeout < 0.0) THROW_IMPOSSIBLE; - simgrid::kernel::activity::CommImpl* comm = static_cast(synchro); + simgrid::kernel::activity::CommImplPtr comm = + boost::static_pointer_cast(synchro); if (comm->src_proc == simcall->issuer) comm->state = SIMIX_SRC_TIMEOUT; else @@ -335,9 +336,10 @@ void simcall_HANDLER_comm_wait(smx_simcall_t simcall, smx_activity_t synchro, do SIMIX_comm_finish(synchro); } else { /* if (timeout >= 0) { we need a surf sleep action even when there is no timeout, otherwise surf won't tell us when the host fails */ surf_action_t sleep = simcall->issuer->host->pimpl_cpu->sleep(timeout); - sleep->setData(synchro); + sleep->setData(&*synchro); - simgrid::kernel::activity::CommImpl* comm = static_cast(synchro); + simgrid::kernel::activity::CommImplPtr comm = + boost::static_pointer_cast(synchro); if (simcall->issuer == comm->src_proc) comm->src_timeout = sleep; else @@ -347,7 +349,8 @@ void simcall_HANDLER_comm_wait(smx_simcall_t simcall, smx_activity_t synchro, do void simcall_HANDLER_comm_test(smx_simcall_t simcall, smx_activity_t synchro) { - simgrid::kernel::activity::CommImpl* comm = static_cast(synchro); + simgrid::kernel::activity::CommImplPtr comm = + boost::static_pointer_cast(synchro); if (MC_is_active() || MC_record_replay_is_active()){ simcall_comm_test__set__result(simcall, comm->src_proc && comm->dst_proc); @@ -370,8 +373,8 @@ void simcall_HANDLER_comm_test(smx_simcall_t simcall, smx_activity_t synchro) } } -void simcall_HANDLER_comm_testany( - smx_simcall_t simcall, simgrid::kernel::activity::ActivityImpl* comms[], size_t count) +void simcall_HANDLER_comm_testany(smx_simcall_t simcall, simgrid::kernel::activity::ActivityImplPtr comms[], + size_t count) { // The default result is -1 -- this means, "nothing is ready". // It can be changed below, but only if something matches. @@ -382,7 +385,7 @@ void simcall_HANDLER_comm_testany( if(idx == -1){ SIMIX_simcall_answer(simcall); }else{ - simgrid::kernel::activity::ActivityImpl* synchro = comms[idx]; + simgrid::kernel::activity::ActivityImplPtr synchro = comms[idx]; simcall_comm_testany__set__result(simcall, idx); synchro->simcalls.push_back(simcall); synchro->state = SIMIX_DONE; @@ -392,7 +395,7 @@ void simcall_HANDLER_comm_testany( } for (std::size_t i = 0; i != count; ++i) { - simgrid::kernel::activity::ActivityImpl* synchro = comms[i]; + simgrid::kernel::activity::ActivityImplPtr synchro = comms[i]; if (synchro->state != SIMIX_WAITING && synchro->state != SIMIX_RUNNING) { simcall_comm_testany__set__result(simcall, i); synchro->simcalls.push_back(simcall); @@ -462,7 +465,8 @@ void SIMIX_waitany_remove_simcall_from_actions(smx_simcall_t simcall) */ static inline void SIMIX_comm_start(smx_activity_t synchro) { - simgrid::kernel::activity::CommImpl* comm = static_cast(synchro); + simgrid::kernel::activity::CommImplPtr comm = + boost::static_pointer_cast(synchro); /* If both the sender and the receiver are already there, start the communication */ if (synchro->state == SIMIX_READY) { @@ -471,7 +475,7 @@ static inline void SIMIX_comm_start(smx_activity_t synchro) simgrid::s4u::Host* receiver = comm->dst_proc->host; comm->surf_comm = surf_network_model->communicate(sender, receiver, comm->task_size, comm->rate); - comm->surf_comm->setData(synchro); + comm->surf_comm->setData(&*synchro); comm->state = SIMIX_RUNNING; XBT_DEBUG("Starting communication %p from '%s' to '%s' (surf_action: %p)", synchro, sender->cname(), @@ -508,7 +512,8 @@ static inline void SIMIX_comm_start(smx_activity_t synchro) */ void SIMIX_comm_finish(smx_activity_t synchro) { - simgrid::kernel::activity::CommImpl* comm = static_cast(synchro); + simgrid::kernel::activity::CommImplPtr comm = + boost::static_pointer_cast(synchro); while (not synchro->simcalls.empty()) { smx_simcall_t simcall = synchro->simcalls.front(); @@ -666,7 +671,8 @@ void SIMIX_comm_set_copy_data_callback(void (*callback) (smx_activity_t, void*, void SIMIX_comm_copy_pointer_callback(smx_activity_t synchro, void* buff, size_t buff_size) { - simgrid::kernel::activity::CommImpl* comm = static_cast(synchro); + simgrid::kernel::activity::CommImplPtr comm = + boost::static_pointer_cast(synchro); xbt_assert((buff_size == sizeof(void *)), "Cannot copy %zu bytes: must be sizeof(void*)", buff_size); *(void **) (comm->dst_buff) = buff; @@ -674,7 +680,8 @@ void SIMIX_comm_copy_pointer_callback(smx_activity_t synchro, void* buff, size_t void SIMIX_comm_copy_buffer_callback(smx_activity_t synchro, void* buff, size_t buff_size) { - simgrid::kernel::activity::CommImpl* comm = static_cast(synchro); + simgrid::kernel::activity::CommImplPtr comm = + boost::static_pointer_cast(synchro); XBT_DEBUG("Copy the data over"); memcpy(comm->dst_buff, buff, buff_size); @@ -690,7 +697,8 @@ void SIMIX_comm_copy_buffer_callback(smx_activity_t synchro, void* buff, size_t */ void SIMIX_comm_copy_data(smx_activity_t synchro) { - simgrid::kernel::activity::CommImpl* comm = static_cast(synchro); + simgrid::kernel::activity::CommImplPtr comm = + boost::static_pointer_cast(synchro); size_t buff_size = comm->src_buff_size; /* If there is no data to copy then return */ diff --git a/src/simix/smx_synchro.cpp b/src/simix/smx_synchro.cpp index c063d085b0..8ea26ceefe 100644 --- a/src/simix/smx_synchro.cpp +++ b/src/simix/smx_synchro.cpp @@ -27,9 +27,10 @@ static smx_activity_t SIMIX_synchro_wait(sg_host_t smx_host, double timeout) { XBT_IN("(%p, %f)",smx_host,timeout); - simgrid::kernel::activity::Raw *sync = new simgrid::kernel::activity::Raw(); + simgrid::kernel::activity::RawImplPtr sync = + simgrid::kernel::activity::RawImplPtr(new simgrid::kernel::activity::RawImpl()); sync->sleep = smx_host->pimpl_cpu->sleep(timeout); - sync->sleep->setData(sync); + sync->sleep->setData(&*sync); XBT_OUT(); return sync; } @@ -89,7 +90,7 @@ void SIMIX_synchro_finish(smx_activity_t synchro) SIMIX_synchro_stop_waiting(simcall->issuer, simcall); simcall->issuer->waiting_synchro = nullptr; - delete synchro; + synchro->unref(); SIMIX_simcall_answer(simcall); XBT_OUT(); } @@ -175,7 +176,7 @@ void MutexImpl::unlock(smx_actor_t issuer) if (xbt_swag_size(this->sleeping) > 0) { /*process to wake up */ smx_actor_t p = (smx_actor_t) xbt_swag_extract(this->sleeping); - delete p->waiting_synchro; + p->waiting_synchro->unref(); p->waiting_synchro = nullptr; this->owner = p; SIMIX_simcall_answer(&p->simcall); @@ -318,7 +319,7 @@ void SIMIX_cond_signal(smx_cond_t cond) if ((proc = (smx_actor_t) xbt_swag_extract(cond->sleeping))) { /* Destroy waiter's synchronization */ - delete proc->waiting_synchro; + proc->waiting_synchro->unref(); proc->waiting_synchro = nullptr; /* Now transform the cond wait simcall into a mutex lock one */ @@ -431,7 +432,7 @@ void SIMIX_sem_release(smx_sem_t sem) XBT_DEBUG("Sem release semaphore %p", sem); if ((proc = (smx_actor_t) xbt_swag_extract(sem->sleeping))) { - delete proc->waiting_synchro; + proc->waiting_synchro->unref(); proc->waiting_synchro = nullptr; SIMIX_simcall_answer(&proc->simcall); } else { diff --git a/src/smpi/smpi_global.cpp b/src/smpi/smpi_global.cpp index ad0834c9ba..66a8f26d7a 100644 --- a/src/smpi/smpi_global.cpp +++ b/src/smpi/smpi_global.cpp @@ -144,7 +144,8 @@ static void check_blocks(std::vector> &private_blocks, void smpi_comm_copy_buffer_callback(smx_activity_t synchro, void *buff, size_t buff_size) { - simgrid::kernel::activity::CommImpl* comm = dynamic_cast(synchro); + simgrid::kernel::activity::CommImplPtr comm = + boost::dynamic_pointer_cast(synchro); int src_shared = 0; int dst_shared = 0; size_t src_offset = 0; diff --git a/src/smpi/smpi_request.cpp b/src/smpi/smpi_request.cpp index 27d5142577..a20b4afdf9 100644 --- a/src/smpi/smpi_request.cpp +++ b/src/smpi/smpi_request.cpp @@ -544,7 +544,7 @@ int Request::testsome(int incount, MPI_Request requests[], int *indices, MPI_Sta int Request::testany(int count, MPI_Request requests[], int *index, MPI_Status * status) { - std::vector comms; + std::vector comms; comms.reserve(count); int i; @@ -652,8 +652,8 @@ void Request::iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* } if (request->action_ != nullptr){ - simgrid::kernel::activity::CommImpl* sync_comm = - static_cast(request->action_); + simgrid::kernel::activity::CommImplPtr sync_comm = + boost::static_pointer_cast(request->action_); MPI_Request req = static_cast(sync_comm->src_data); *flag = 1; if(status != MPI_STATUS_IGNORE && (req->flags_ & PREPARED) == 0) { -- 2.20.1