From 7ba9ddb2180684b3fe1ab8e70b854d3f8558d8dc Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Fri, 10 Feb 2017 22:50:37 +0100 Subject: [PATCH] split simix::MailboxImpl to its own files --- .../CommunicationDeterminismChecker.cpp | 5 +- src/s4u/s4u_mailbox.cpp | 2 +- src/simix/MailboxImpl.cpp | 86 +++++++++++++++++++ src/simix/MailboxImpl.hpp | 46 ++++++++++ src/simix/smx_network.cpp | 82 +----------------- src/simix/smx_network_private.h | 36 +------- tools/cmake/DefinePackages.cmake | 4 +- 7 files changed, 141 insertions(+), 120 deletions(-) create mode 100644 src/simix/MailboxImpl.cpp create mode 100644 src/simix/MailboxImpl.hpp diff --git a/src/mc/checker/CommunicationDeterminismChecker.cpp b/src/mc/checker/CommunicationDeterminismChecker.cpp index e8999908e5..df6f64ecc7 100644 --- a/src/mc/checker/CommunicationDeterminismChecker.cpp +++ b/src/mc/checker/CommunicationDeterminismChecker.cpp @@ -197,7 +197,7 @@ void CommunicationDeterminismChecker::get_comm_pattern(xbt_dynar_t list, smx_sim static_cast(temp_synchro.getBuffer()); char* remote_name = mc_model_checker->process().read( - (std::uint64_t)(synchro->mbox ? &synchro->mbox->name : &synchro->mbox_cpy->name)); + (std::uint64_t)(synchro->mbox ? &synchro->mbox->name_ : &synchro->mbox_cpy->name_)); pattern->rdv = mc_model_checker->process().read_string(remote_name); pattern->src_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(synchro->src_proc))->pid; pattern->src_host = MC_smx_actor_get_host_name(issuer); @@ -244,8 +244,7 @@ void CommunicationDeterminismChecker::get_comm_pattern(xbt_dynar_t list, smx_sim simgrid::kernel::activity::Comm* comm = temp_comm.getBuffer(); char* remote_name; - mc_model_checker->process().read(&remote_name, - remote(comm->mbox ? &comm->mbox->name : &comm->mbox_cpy->name)); + mc_model_checker->process().read(&remote_name, remote(comm->mbox ? &comm->mbox->name_ : &comm->mbox_cpy->name_)); pattern->rdv = mc_model_checker->process().read_string(remote_name); pattern->dst_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(comm->dst_proc))->pid; pattern->dst_host = MC_smx_actor_get_host_name(issuer); diff --git a/src/s4u/s4u_mailbox.cpp b/src/s4u/s4u_mailbox.cpp index ea2a10893e..d6b0d967ee 100644 --- a/src/s4u/s4u_mailbox.cpp +++ b/src/s4u/s4u_mailbox.cpp @@ -17,7 +17,7 @@ namespace simgrid { namespace s4u { const char *Mailbox::name() { - return pimpl_->name; + return pimpl_->name_; } MailboxPtr Mailbox::byName(const char*name) diff --git a/src/simix/MailboxImpl.cpp b/src/simix/MailboxImpl.cpp new file mode 100644 index 0000000000..c30d784966 --- /dev/null +++ b/src/simix/MailboxImpl.cpp @@ -0,0 +1,86 @@ +/* Copyright (c) 2007-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. */ + +#include "src/simix/MailboxImpl.hpp" +#include "src/kernel/activity/SynchroComm.hpp" + +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); + +void SIMIX_mailbox_exit() +{ + xbt_dict_free(&mailboxes); +} + +/******************************************************************************/ +/* Rendez-Vous Points */ +/******************************************************************************/ + +smx_mailbox_t SIMIX_mbox_create(const char* name) +{ + xbt_assert(name, "Mailboxes must have a name"); + /* two processes may have pushed the same mbox_create simcall at the same time */ + smx_mailbox_t mbox = static_cast(xbt_dict_get_or_null(mailboxes, name)); + if (!mbox) { + mbox = new simgrid::simix::MailboxImpl(name); + XBT_DEBUG("Creating a mailbox at %p with name %s", mbox, name); + xbt_dict_set(mailboxes, mbox->name_, mbox, nullptr); + } + return mbox; +} + +void SIMIX_mbox_free(void* data) +{ + XBT_DEBUG("mbox free %p", data); + smx_mailbox_t mbox = static_cast(data); + delete mbox; +} + +smx_mailbox_t SIMIX_mbox_get_by_name(const char* name) +{ + return static_cast(xbt_dict_get_or_null(mailboxes, name)); +} + +/** + * \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; +} + +/** + * \brief Pushes a communication synchro into a rendez-vous point + * \param mbox The mailbox + * \param synchro The communication synchro + */ +void SIMIX_mbox_push(smx_mailbox_t mbox, smx_activity_t synchro) +{ + simgrid::kernel::activity::Comm* comm = static_cast(synchro); + mbox->comm_queue.push_back(comm); + comm->mbox = mbox; +} + +/** + * \brief Removes a communication synchro from a rendez-vous point + * \param mbox The rendez-vous point + * \param synchro The communication synchro + */ +void SIMIX_mbox_remove(smx_mailbox_t mbox, smx_activity_t synchro) +{ + simgrid::kernel::activity::Comm* comm = static_cast(synchro); + + comm->mbox = nullptr; + for (auto it = mbox->comm_queue.begin(); it != mbox->comm_queue.end(); it++) + if (*it == comm) { + mbox->comm_queue.erase(it); + return; + } + xbt_die("Cannot remove the comm %p that is not part of the mailbox %s", comm, mbox->name_); +} diff --git a/src/simix/MailboxImpl.hpp b/src/simix/MailboxImpl.hpp new file mode 100644 index 0000000000..0b27bd8cd4 --- /dev/null +++ b/src/simix/MailboxImpl.hpp @@ -0,0 +1,46 @@ +/* Copyright (c) 2007-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. */ + +#ifndef SIMIX_MAILBOXIMPL_H +#define SIMIX_MAILBOXIMPL_H + +#include + +#include "simgrid/s4u/Mailbox.hpp" +#include "src/simix/ActorImpl.hpp" + +#define MAX_MAILBOX_SIZE 10000000 +namespace simgrid { +namespace simix { + +/** @brief Rendez-vous point datatype */ + +class MailboxImpl { +public: + MailboxImpl(const char* name) + : piface_(this), name_(xbt_strdup(name)), comm_queue(MAX_MAILBOX_SIZE), done_comm_queue(MAX_MAILBOX_SIZE) + { + } + ~MailboxImpl() { xbt_free(name_); } + + simgrid::s4u::Mailbox piface_; // Our interface + char* name_; + boost::circular_buffer_space_optimized comm_queue; + boost::intrusive_ptr permanent_receiver; //process which the mailbox is attached to + boost::circular_buffer_space_optimized done_comm_queue;//messages already received in the permanent receive mode +}; +} +} + +XBT_PRIVATE void SIMIX_mailbox_exit(); + +XBT_PRIVATE smx_mailbox_t SIMIX_mbox_create(const char* name); +XBT_PRIVATE smx_mailbox_t SIMIX_mbox_get_by_name(const char* name); +XBT_PRIVATE void SIMIX_mbox_remove(smx_mailbox_t mbox, smx_activity_t comm); +XBT_PRIVATE void SIMIX_mbox_push(smx_mailbox_t mbox, smx_activity_t synchro); + +XBT_PRIVATE void SIMIX_mbox_set_receiver(smx_mailbox_t mbox, smx_actor_t proc); + +#endif /* SIMIX_MAILBOXIMPL_H */ diff --git a/src/simix/smx_network.cpp b/src/simix/smx_network.cpp index 22003ece7d..dc519f0fe2 100644 --- a/src/simix/smx_network.cpp +++ b/src/simix/smx_network.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2009-2016. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2009-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. */ @@ -25,89 +25,11 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_network, simix, "SIMIX network-related synchronization"); -static void SIMIX_mbox_free(void *data); -static xbt_dict_t mailboxes = xbt_dict_new_homogeneous(SIMIX_mbox_free); - static void SIMIX_waitany_remove_simcall_from_actions(smx_simcall_t simcall); static void SIMIX_comm_copy_data(smx_activity_t comm); -static inline void SIMIX_mbox_push(smx_mailbox_t mbox, smx_activity_t comm); +static void SIMIX_comm_start(smx_activity_t synchro); static smx_activity_t _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); -static void SIMIX_comm_start(smx_activity_t synchro); - -void SIMIX_mailbox_exit() -{ - xbt_dict_free(&mailboxes); -} - -/******************************************************************************/ -/* Rendez-Vous Points */ -/******************************************************************************/ - -smx_mailbox_t SIMIX_mbox_create(const char *name) -{ - xbt_assert(name, "Mailboxes must have a name"); - /* two processes may have pushed the same mbox_create simcall at the same time */ - smx_mailbox_t mbox = static_cast(xbt_dict_get_or_null(mailboxes, name)); - if (!mbox) { - mbox = new simgrid::simix::MailboxImpl(name); - XBT_DEBUG("Creating a mailbox at %p with name %s", mbox, name); - xbt_dict_set(mailboxes, mbox->name, mbox, nullptr); - } - return mbox; -} - -void SIMIX_mbox_free(void *data) -{ - XBT_DEBUG("mbox free %p", data); - smx_mailbox_t mbox = static_cast(data); - delete mbox; -} - -smx_mailbox_t SIMIX_mbox_get_by_name(const char *name) -{ - return static_cast(xbt_dict_get_or_null(mailboxes, name)); -} - -/** - * \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; -} - -/** - * \brief Pushes a communication synchro into a rendez-vous point - * \param mbox The mailbox - * \param synchro The communication synchro - */ -static inline void SIMIX_mbox_push(smx_mailbox_t mbox, smx_activity_t synchro) -{ - simgrid::kernel::activity::Comm *comm = static_cast(synchro); - mbox->comm_queue.push_back(comm); - comm->mbox = mbox; -} - -/** - * \brief Removes a communication synchro from a rendez-vous point - * \param mbox The rendez-vous point - * \param synchro The communication synchro - */ -void SIMIX_mbox_remove(smx_mailbox_t mbox, smx_activity_t synchro) -{ - simgrid::kernel::activity::Comm *comm = static_cast(synchro); - - comm->mbox = nullptr; - for (auto it = mbox->comm_queue.begin(); it != mbox->comm_queue.end(); it++) - if (*it == comm) { - mbox->comm_queue. erase(it); - return; - } - xbt_die("Cannot remove the comm %p that is not part of the mailbox %s",comm, mbox->name); -} /** * \brief Checks if there is a communication synchro queued in a deque matching our needs diff --git a/src/simix/smx_network_private.h b/src/simix/smx_network_private.h index af4ee08210..e40096bad8 100644 --- a/src/simix/smx_network_private.h +++ b/src/simix/smx_network_private.h @@ -7,44 +7,10 @@ #ifndef _SIMIX_NETWORK_PRIVATE_H #define _SIMIX_NETWORK_PRIVATE_H -#include - #include "simgrid/s4u/Mailbox.hpp" - #include "src/simix/ActorImpl.hpp" +#include "src/simix/MailboxImpl.hpp" - -#define MAX_MAILBOX_SIZE 10000000 -namespace simgrid { -namespace simix { - -/** @brief Rendez-vous point datatype */ - -class MailboxImpl { -public: - MailboxImpl(const char* name) - : piface_(this), name(xbt_strdup(name)), comm_queue(MAX_MAILBOX_SIZE), done_comm_queue(MAX_MAILBOX_SIZE) - { - } - ~MailboxImpl() { xbt_free(name); } - - simgrid::s4u::Mailbox piface_; // Our interface - char* name; - boost::circular_buffer_space_optimized comm_queue; - boost::intrusive_ptr permanent_receiver; //process which the mailbox is attached to - boost::circular_buffer_space_optimized done_comm_queue;//messages already received in the permanent receive mode -}; - -} -} - -XBT_PRIVATE void SIMIX_mailbox_exit(); - -XBT_PRIVATE smx_mailbox_t SIMIX_mbox_create(const char *name); -XBT_PRIVATE smx_mailbox_t SIMIX_mbox_get_by_name(const char *name); -XBT_PRIVATE void SIMIX_mbox_remove(smx_mailbox_t mbox, smx_activity_t comm); - -XBT_PRIVATE void SIMIX_mbox_set_receiver(smx_mailbox_t mbox, smx_actor_t proc); XBT_PRIVATE smx_activity_t SIMIX_comm_irecv(smx_actor_t dst_proc, smx_mailbox_t mbox, void *dst_buff, size_t *dst_buff_size, int (*match_fun)(void *, void *, smx_activity_t), diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 18f10a6806..51f098d0df 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -30,7 +30,6 @@ set(EXTRA_DIST src/simix/smx_io_private.h src/simix/smx_network_private.h src/simix/smx_private.h - src/simix/ActorImpl.hpp src/simix/smx_synchro_private.h src/kernel/activity/ActivityImpl.hpp src/kernel/activity/SynchroComm.hpp @@ -362,6 +361,9 @@ set(SIMIX_SRC src/simix/smx_io.cpp src/simix/smx_network.cpp src/simix/ActorImpl.cpp + src/simix/ActorImpl.hpp + src/simix/MailboxImpl.cpp + src/simix/MailboxImpl.hpp src/simix/smx_synchro.cpp src/simix/popping.cpp src/kernel/activity/ActivityImpl.cpp -- 2.20.1