From: Martin Quinson Date: Sun, 12 Feb 2017 20:48:53 +0000 (+0100) Subject: finish the conversion C++ of simix::MailboxImpl X-Git-Tag: v3_15~409 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/8250fdfeb9c8dd3ae2a1d19f3c89871c9599d0f8?hp=208e489bc3916de52273592bdaf2cffe384575b9 finish the conversion C++ of simix::MailboxImpl --- diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index 40db256252..56c644edeb 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -134,6 +134,7 @@ namespace s4u { XBT_PUBLIC_CLASS Actor { friend Mailbox; friend simgrid::simix::ActorImpl; + friend simgrid::simix::MailboxImpl; simix::ActorImpl* pimpl_ = nullptr; /** Wrap a (possibly non-copyable) single-use task into a `std::function` */ diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index 053849aa42..02d8112b02 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -291,11 +291,6 @@ XBT_PUBLIC(void) simcall_process_join(smx_actor_t process, double timeout); XBT_PUBLIC(e_smx_state_t) simcall_process_sleep(double duration); /************************** Comunication simcalls *****************************/ -/***** Rendez-vous points *****/ - -XBT_PUBLIC(void) simcall_mbox_set_receiver(smx_mailbox_t mbox , smx_actor_t process); - -/***** Communication simcalls *****/ XBT_PUBLIC(void) simcall_comm_send(smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate, void *src_buff, diff --git a/src/s4u/s4u_mailbox.cpp b/src/s4u/s4u_mailbox.cpp index 9e5f3f4c9c..ed78c0338c 100644 --- a/src/s4u/s4u_mailbox.cpp +++ b/src/s4u/s4u_mailbox.cpp @@ -47,7 +47,9 @@ smx_activity_t Mailbox::front() } void Mailbox::setReceiver(ActorPtr actor) { - simcall_mbox_set_receiver(pimpl_, actor == nullptr ? nullptr : actor->pimpl_); + simix::kernelImmediate([this, actor]() { + this->pimpl_->setReceiver(actor); + }); } /** @brief get the receiver (process associated to the mailbox) */ diff --git a/src/simix/MailboxImpl.cpp b/src/simix/MailboxImpl.cpp index 993644819a..7a19d18a32 100644 --- a/src/simix/MailboxImpl.cpp +++ b/src/simix/MailboxImpl.cpp @@ -8,34 +8,19 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_mailbox, simix, "Mailbox implementation"); -static void SIMIX_mbox_free(void* data); -static xbt_dict_t mailboxes = xbt_dict_new_homogeneous(SIMIX_mbox_free); +static xbt_dict_t mailboxes = xbt_dict_new_homogeneous([](void* data) { + delete static_cast(data); +}); void SIMIX_mailbox_exit() { xbt_dict_free(&mailboxes); } -void SIMIX_mbox_free(void* data) -{ - XBT_DEBUG("mbox free %p", data); - smx_mailbox_t mbox = static_cast(data); - delete mbox; -} /******************************************************************************/ /* Rendez-Vous Points */ /******************************************************************************/ -/** - * \brief set the receiver of the rendez vous point to allow eager sends - * \param mbox The rendez-vous point - * \param process The receiving process - */ -void SIMIX_mbox_set_receiver(smx_mailbox_t mbox, smx_actor_t process) -{ - mbox->permanent_receiver = process; -} - namespace simgrid { namespace simix { /** @brief Returns the mailbox of that name, or nullptr */ @@ -56,6 +41,13 @@ MailboxImpl* MailboxImpl::byNameOrCreate(const char* name) } return mbox; } +/** @brief set the receiver of the mailbox to allow eager sends + * \param actor The receiving dude + */ +void MailboxImpl::setReceiver(s4u::ActorPtr actor) +{ + this->permanent_receiver = actor.get()->getImpl(); +} /** @brief Pushes a communication activity into a mailbox * @param activity What to add */ diff --git a/src/simix/MailboxImpl.hpp b/src/simix/MailboxImpl.hpp index bd9c49b62b..4fb573ff7a 100644 --- a/src/simix/MailboxImpl.hpp +++ b/src/simix/MailboxImpl.hpp @@ -28,6 +28,7 @@ public: static MailboxImpl* byNameOrNull(const char* name); static MailboxImpl* byNameOrCreate(const char* name); + void setReceiver(s4u::ActorPtr actor); void push(smx_activity_t synchro); void remove(smx_activity_t activity); simgrid::s4u::Mailbox piface_; // Our interface @@ -42,6 +43,4 @@ public: XBT_PRIVATE void SIMIX_mailbox_exit(); -XBT_PRIVATE void SIMIX_mbox_set_receiver(smx_mailbox_t mbox, smx_actor_t proc); - #endif /* SIMIX_MAILBOXIMPL_H */ diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index a580e9aac9..bbc509cc4f 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -367,11 +367,6 @@ e_smx_state_t simcall_process_sleep(double duration) return (e_smx_state_t) simcall_BODY_process_sleep(duration); } -void simcall_mbox_set_receiver(smx_mailbox_t mbox, smx_actor_t process) -{ - simcall_BODY_mbox_set_receiver(mbox, process); -} - /** * \ingroup simix_comm_management */ diff --git a/src/simix/popping_accessors.h b/src/simix/popping_accessors.h index 5070dfdf83..fadfc1bb22 100644 --- a/src/simix/popping_accessors.h +++ b/src/simix/popping_accessors.h @@ -284,19 +284,6 @@ static inline void simcall_process_restart__set__result(smx_simcall_t simcall, s simgrid::simix::marshal(simcall->result, result); } -static inline smx_mailbox_t simcall_mbox_set_receiver__get__mbox(smx_simcall_t simcall) { - return simgrid::simix::unmarshal(simcall->args[0]); -} -static inline void simcall_mbox_set_receiver__set__mbox(smx_simcall_t simcall, smx_mailbox_t arg) { - simgrid::simix::marshal(simcall->args[0], arg); -} -static inline smx_actor_t simcall_mbox_set_receiver__get__receiver(smx_simcall_t simcall) { - return simgrid::simix::unmarshal(simcall->args[1]); -} -static inline void simcall_mbox_set_receiver__set__receiver(smx_simcall_t simcall, smx_actor_t arg) { - simgrid::simix::marshal(simcall->args[1], arg); -} - static inline smx_mailbox_t simcall_comm_iprobe__get__mbox(smx_simcall_t simcall) { return simgrid::simix::unmarshal(simcall->args[0]); } diff --git a/src/simix/popping_bodies.cpp b/src/simix/popping_bodies.cpp index 0bcb22dc13..ccdeaaf337 100644 --- a/src/simix/popping_bodies.cpp +++ b/src/simix/popping_bodies.cpp @@ -143,12 +143,6 @@ inline static smx_actor_t simcall_BODY_process_restart(smx_actor_t process) { return simcall(SIMCALL_PROCESS_RESTART, process); } -inline static void simcall_BODY_mbox_set_receiver(smx_mailbox_t mbox, smx_actor_t receiver) { - /* Go to that function to follow the code flow through the simcall barrier */ - if (0) SIMIX_mbox_set_receiver(mbox, receiver); - return simcall(SIMCALL_MBOX_SET_RECEIVER, mbox, receiver); - } - inline static smx_activity_t simcall_BODY_comm_iprobe(smx_mailbox_t mbox, int type, int src, int tag, simix_match_func_t match_fun, void* data) { /* Go to that function to follow the code flow through the simcall barrier */ if (0) simcall_HANDLER_comm_iprobe(&SIMIX_process_self()->simcall, mbox, type, src, tag, match_fun, data); diff --git a/src/simix/popping_enum.h b/src/simix/popping_enum.h index 27a3f572db..40a740555b 100644 --- a/src/simix/popping_enum.h +++ b/src/simix/popping_enum.h @@ -36,7 +36,6 @@ typedef enum { SIMCALL_PROCESS_ON_EXIT, SIMCALL_PROCESS_AUTO_RESTART_SET, SIMCALL_PROCESS_RESTART, - SIMCALL_MBOX_SET_RECEIVER, SIMCALL_COMM_IPROBE, SIMCALL_COMM_SEND, SIMCALL_COMM_ISEND, diff --git a/src/simix/popping_generated.cpp b/src/simix/popping_generated.cpp index 689f2ef2b9..9c7bb3097a 100644 --- a/src/simix/popping_generated.cpp +++ b/src/simix/popping_generated.cpp @@ -42,7 +42,6 @@ const char* simcall_names[] = { "SIMCALL_PROCESS_ON_EXIT", "SIMCALL_PROCESS_AUTO_RESTART_SET", "SIMCALL_PROCESS_RESTART", - "SIMCALL_MBOX_SET_RECEIVER", "SIMCALL_COMM_IPROBE", "SIMCALL_COMM_SEND", "SIMCALL_COMM_ISEND", @@ -184,11 +183,6 @@ case SIMCALL_PROCESS_RESTART: SIMIX_simcall_answer(simcall); break; -case SIMCALL_MBOX_SET_RECEIVER: - SIMIX_mbox_set_receiver(simgrid::simix::unmarshal(simcall->args[0]), simgrid::simix::unmarshal(simcall->args[1])); - SIMIX_simcall_answer(simcall); - break; - case SIMCALL_COMM_IPROBE: simgrid::simix::marshal(simcall->result, simcall_HANDLER_comm_iprobe(simcall, simgrid::simix::unmarshal(simcall->args[0]), simgrid::simix::unmarshal(simcall->args[1]), simgrid::simix::unmarshal(simcall->args[2]), simgrid::simix::unmarshal(simcall->args[3]), simgrid::simix::unmarshal(simcall->args[4]), simgrid::simix::unmarshal(simcall->args[5]))); SIMIX_simcall_answer(simcall); diff --git a/src/simix/simcalls.in b/src/simix/simcalls.in index 77ce2e8f53..8a565e7d33 100644 --- a/src/simix/simcalls.in +++ b/src/simix/simcalls.in @@ -57,8 +57,6 @@ void process_on_exit(smx_actor_t process, int_f_pvoid_pvoid_t fun, void void process_auto_restart_set(smx_actor_t process, int auto_restart) [[nohandler]]; smx_actor_t process_restart(smx_actor_t process); -void mbox_set_receiver(smx_mailbox_t mbox, smx_actor_t receiver) [[nohandler]]; - smx_activity_t comm_iprobe(smx_mailbox_t mbox, int type, int src, int tag, simix_match_func_t match_fun, void* data); void comm_send(smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate, void* src_buff, size_t src_buff_size, simix_match_func_t match_fun, simix_copy_data_func_t copy_data_fun, void* data, double timeout) [[block]]; smx_activity_t comm_isend(smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate, void* src_buff, size_t src_buff_size, simix_match_func_t match_fun, simix_clean_func_t clean_fun, simix_copy_data_func_t copy_data_fun, void* data, int detached); diff --git a/src/smpi/smpi_global.cpp b/src/smpi/smpi_global.cpp index a36fe01a20..b7b181cf95 100644 --- a/src/smpi/smpi_global.cpp +++ b/src/smpi/smpi_global.cpp @@ -145,7 +145,7 @@ void smpi_process_init(int *argc, char ***argv) data->argc = argc; data->argv = argv; // set the process attached to the mailbox - simcall_mbox_set_receiver(data->mailbox_small->getImpl(), proc); + data->mailbox_small->setReceiver(simgrid::s4u::Actor::self()); XBT_DEBUG("<%d> New process in the game: %p", index, proc); } xbt_assert(smpi_process_data(),