From a568a13bc6d5eb7ddbbec34bdb42497bc3825f87 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Fri, 15 Feb 2019 09:43:08 +0100 Subject: [PATCH] make e_smx_comm_type_t be en enum class --- src/kernel/activity/CommImpl.cpp | 2 +- src/kernel/activity/CommImpl.hpp | 7 ++++--- src/kernel/activity/MailboxImpl.cpp | 22 ++++++++++------------ src/kernel/activity/MailboxImpl.hpp | 4 ++-- src/mc/mc_base.cpp | 3 ++- src/simix/smx_network.cpp | 25 ++++++++++++++----------- 6 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/kernel/activity/CommImpl.cpp b/src/kernel/activity/CommImpl.cpp index 0409ebdd64..f16fe42313 100644 --- a/src/kernel/activity/CommImpl.cpp +++ b/src/kernel/activity/CommImpl.cpp @@ -37,7 +37,7 @@ namespace simgrid { namespace kernel { namespace activity { -CommImpl::CommImpl(e_smx_comm_type_t _type) : type(_type) +CommImpl::CommImpl(CommImpl::Type type) : type(type) { state_ = SIMIX_WAITING; src_data_ = nullptr; diff --git a/src/kernel/activity/CommImpl.hpp b/src/kernel/activity/CommImpl.hpp index 4c7a715d91..acebe1d6eb 100644 --- a/src/kernel/activity/CommImpl.hpp +++ b/src/kernel/activity/CommImpl.hpp @@ -10,7 +10,6 @@ #include "src/simix/ActorImpl.hpp" #include "surf/surf.hpp" -enum e_smx_comm_type_t { SIMIX_COMM_SEND, SIMIX_COMM_RECEIVE, SIMIX_COMM_READY, SIMIX_COMM_DONE }; namespace simgrid { namespace kernel { @@ -20,7 +19,9 @@ class XBT_PUBLIC CommImpl : public ActivityImpl { ~CommImpl() override; public: - explicit CommImpl(e_smx_comm_type_t type); + enum class Type { SEND = 0, RECEIVE, READY, DONE }; + + explicit CommImpl(Type type); void start(); void copy_data(); void suspend() override; @@ -30,7 +31,7 @@ public: double remains(); void cleanupSurf(); // FIXME: make me protected - e_smx_comm_type_t type; /* Type of the communication (SIMIX_COMM_SEND or SIMIX_COMM_RECEIVE) */ + CommImpl::Type type; /* Type of the communication (SIMIX_COMM_SEND or SIMIX_COMM_RECEIVE) */ smx_mailbox_t mbox = nullptr; /* Rendez-vous where the comm is queued */ #if SIMGRID_HAVE_MC diff --git a/src/kernel/activity/MailboxImpl.cpp b/src/kernel/activity/MailboxImpl.cpp index c676b12d6e..9aaa5e6cc1 100644 --- a/src/kernel/activity/MailboxImpl.cpp +++ b/src/kernel/activity/MailboxImpl.cpp @@ -90,24 +90,22 @@ smx_activity_t MailboxImpl::iprobe(int type, int (*match_fun)(void*, void*, Comm XBT_DEBUG("iprobe from %p %p", this, &comm_queue_); CommImplPtr this_comm; - int smx_type; + CommImpl::Type smx_type; if (type == 1) { - this_comm = CommImplPtr(new CommImpl(SIMIX_COMM_SEND)); - smx_type = SIMIX_COMM_RECEIVE; + this_comm = CommImplPtr(new CommImpl(CommImpl::Type::SEND)); + smx_type = CommImpl::Type::SEND; } else { - this_comm = CommImplPtr(new CommImpl(SIMIX_COMM_RECEIVE)); - smx_type = SIMIX_COMM_SEND; + this_comm = CommImplPtr(new CommImpl(CommImpl::Type::RECEIVE)); + smx_type = CommImpl::Type::RECEIVE; } smx_activity_t other_synchro = nullptr; if (permanent_receiver_ != nullptr && not done_comm_queue_.empty()) { XBT_DEBUG("first check in the permanent recv mailbox, to see if we already got something"); - other_synchro = find_matching_comm((e_smx_comm_type_t)smx_type, match_fun, data, this_comm, /*done*/ true, - /*remove_matching*/ false); + other_synchro = find_matching_comm(smx_type, match_fun, data, this_comm, /*done*/ true, /*remove_matching*/ false); } if (not other_synchro) { XBT_DEBUG("check if we have more luck in the normal mailbox"); - other_synchro = find_matching_comm((e_smx_comm_type_t)smx_type, match_fun, data, this_comm, /*done*/ false, - /*remove_matching*/ false); + other_synchro = find_matching_comm(smx_type, match_fun, data, this_comm, /*done*/ false, /*remove_matching*/ false); } return other_synchro; @@ -122,7 +120,7 @@ smx_activity_t MailboxImpl::iprobe(int type, int (*match_fun)(void*, void*, Comm * @param remove_matching whether or not to clean the found object from the queue * @return The communication activity if found, nullptr otherwise */ -CommImplPtr MailboxImpl::find_matching_comm(e_smx_comm_type_t type, int (*match_fun)(void*, void*, CommImpl*), +CommImplPtr MailboxImpl::find_matching_comm(CommImpl::Type type, int (*match_fun)(void*, void*, CommImpl*), void* this_user_data, CommImplPtr my_synchro, bool done, bool remove_matching) { @@ -136,9 +134,9 @@ CommImplPtr MailboxImpl::find_matching_comm(e_smx_comm_type_t type, int (*match_ for (auto it = deque->begin(); it != deque->end(); it++) { CommImplPtr comm = boost::dynamic_pointer_cast(std::move(*it)); - if (comm->type == SIMIX_COMM_SEND) { + if (comm->type == CommImpl::Type::SEND) { other_user_data = comm->src_data_; - } else if (comm->type == SIMIX_COMM_RECEIVE) { + } else if (comm->type == CommImpl::Type::RECEIVE) { other_user_data = comm->dst_data_; } if (comm->type == type && (match_fun == nullptr || match_fun(this_user_data, other_user_data, comm.get())) && diff --git a/src/kernel/activity/MailboxImpl.hpp b/src/kernel/activity/MailboxImpl.hpp index ffdbbb0570..c248f9d23e 100644 --- a/src/kernel/activity/MailboxImpl.hpp +++ b/src/kernel/activity/MailboxImpl.hpp @@ -39,8 +39,8 @@ public: void push(activity::CommImplPtr comm); void remove(smx_activity_t activity); smx_activity_t iprobe(int type, int (*match_fun)(void*, void*, CommImpl*), void* data); - CommImplPtr find_matching_comm(e_smx_comm_type_t type, int (*match_fun)(void*, void*, CommImpl*), - void* this_user_data, CommImplPtr my_synchro, bool done, bool remove_matching); + CommImplPtr find_matching_comm(CommImpl::Type type, int (*match_fun)(void*, void*, CommImpl*), void* this_user_data, + CommImplPtr my_synchro, bool done, bool remove_matching); private: simgrid::s4u::Mailbox piface_; diff --git a/src/mc/mc_base.cpp b/src/mc/mc_base.cpp index 27ad062792..bbc1d548ca 100644 --- a/src/mc/mc_base.cpp +++ b/src/mc/mc_base.cpp @@ -95,7 +95,8 @@ bool actor_is_enabled(smx_actor_t actor) return true; } /* On the other hand if it hasn't a timeout, check if the comm is ready.*/ - else if (act->detached && act->src_actor_ == nullptr && act->type == SIMIX_COMM_READY) + else if (act->detached && act->src_actor_ == nullptr && + act->type == simgrid::kernel::activity::CommImpl::Type::READY) return (act->dst_actor_ != nullptr); return (act->src_actor_ && act->dst_actor_); } diff --git a/src/simix/smx_network.cpp b/src/simix/smx_network.cpp index 9d36b981b4..b855c9fc0a 100644 --- a/src/simix/smx_network.cpp +++ b/src/simix/smx_network.cpp @@ -43,15 +43,16 @@ XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_isend( XBT_DEBUG("send from mailbox %p", mbox); /* Prepare a synchro describing us, so that it gets passed to the user-provided filter of other side */ - simgrid::kernel::activity::CommImplPtr this_comm = - simgrid::kernel::activity::CommImplPtr(new simgrid::kernel::activity::CommImpl(SIMIX_COMM_SEND)); + simgrid::kernel::activity::CommImplPtr this_comm = simgrid::kernel::activity::CommImplPtr( + new simgrid::kernel::activity::CommImpl(simgrid::kernel::activity::CommImpl::Type::SEND)); /* Look for communication synchro matching our needs. We also provide a description of * 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::CommImplPtr other_comm = mbox->find_matching_comm( - SIMIX_COMM_RECEIVE, match_fun, data, this_comm, /*done*/ false, /*remove_matching*/ true); + simgrid::kernel::activity::CommImplPtr other_comm = + mbox->find_matching_comm(simgrid::kernel::activity::CommImpl::Type::RECEIVE, match_fun, data, this_comm, + /*done*/ false, /*remove_matching*/ true); if (not other_comm) { other_comm = std::move(this_comm); @@ -70,7 +71,7 @@ XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_isend( XBT_DEBUG("Receive already pushed"); other_comm->state_ = SIMIX_READY; - other_comm->type = SIMIX_COMM_READY; + other_comm->type = simgrid::kernel::activity::CommImpl::Type::READY; } src_proc->comms.push_back(other_comm); @@ -121,8 +122,8 @@ XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_irecv(smx_simcall_t /*simcall*/, void (*copy_data_fun)(smx_activity_t, void*, size_t), void* data, double rate) { - simgrid::kernel::activity::CommImplPtr this_synchro = - simgrid::kernel::activity::CommImplPtr(new simgrid::kernel::activity::CommImpl(SIMIX_COMM_RECEIVE)); + simgrid::kernel::activity::CommImplPtr this_synchro = simgrid::kernel::activity::CommImplPtr( + new simgrid::kernel::activity::CommImpl(simgrid::kernel::activity::CommImpl::Type::RECEIVE)); XBT_DEBUG("recv from mbox %p. this_synchro=%p", mbox, this_synchro.get()); simgrid::kernel::activity::CommImplPtr other_comm; @@ -131,7 +132,8 @@ XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_irecv(smx_simcall_t /*simcall*/, XBT_DEBUG("We have a comm that has probably already been received, trying to match it, to skip the communication"); //find a match in the list of already received comms - other_comm = mbox->find_matching_comm(SIMIX_COMM_SEND, match_fun, data, this_synchro, /*done*/ true, + other_comm = mbox->find_matching_comm(simgrid::kernel::activity::CommImpl::Type::SEND, match_fun, data, + this_synchro, /*done*/ true, /*remove_matching*/ true); //if not found, assume the receiver came first, register it to the mailbox in the classical way if (not other_comm) { @@ -142,7 +144,7 @@ XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_irecv(smx_simcall_t /*simcall*/, if (other_comm->surf_action_ && other_comm->remains() < 1e-12) { XBT_DEBUG("comm %p has been already sent, and is finished, destroy it", other_comm.get()); other_comm->state_ = SIMIX_DONE; - other_comm->type = SIMIX_COMM_DONE; + other_comm->type = simgrid::kernel::activity::CommImpl::Type::DONE; other_comm->mbox = nullptr; } } @@ -153,7 +155,8 @@ XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_irecv(smx_simcall_t /*simcall*/, * 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 */ - other_comm = mbox->find_matching_comm(SIMIX_COMM_SEND, match_fun, data, this_synchro, /*done*/ false, + other_comm = mbox->find_matching_comm(simgrid::kernel::activity::CommImpl::Type::SEND, match_fun, data, + this_synchro, /*done*/ false, /*remove_matching*/ true); if (other_comm == nullptr) { @@ -164,7 +167,7 @@ XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_irecv(smx_simcall_t /*simcall*/, XBT_DEBUG("Match my %p with the existing %p", this_synchro.get(), other_comm.get()); other_comm->state_ = SIMIX_READY; - other_comm->type = SIMIX_COMM_READY; + other_comm->type = simgrid::kernel::activity::CommImpl::Type::READY; } receiver->comms.push_back(other_comm); } -- 2.20.1