From 5ed4f61f0e696847734a909eba544fdfe6066abd Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Wed, 16 Feb 2022 12:25:00 +0100 Subject: [PATCH] Don't mix public and private data members (sonar). --- src/kernel/activity/CommImpl.cpp | 20 ++++++++++---------- src/kernel/activity/CommImpl.hpp | 4 ++-- src/kernel/actor/SimcallObserver.hpp | 11 +++++++++-- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/kernel/activity/CommImpl.cpp b/src/kernel/activity/CommImpl.cpp index 15b5cdf64c..98a52224af 100644 --- a/src/kernel/activity/CommImpl.cpp +++ b/src/kernel/activity/CommImpl.cpp @@ -267,7 +267,7 @@ void CommImpl::copy_data() copied_ = true; } -ActivityImplPtr CommImpl::isend(actor::CommIsendSimcall* observer) +ActivityImplPtr CommImpl::isend(const actor::CommIsendSimcall* observer) { auto* mbox = observer->get_mailbox(); XBT_DEBUG("send from mailbox %p", mbox); @@ -280,7 +280,7 @@ ActivityImplPtr CommImpl::isend(actor::CommIsendSimcall* observer) * * If it is not found then push our communication into the rendez-vous point */ CommImplPtr other_comm = - mbox->find_matching_comm(CommImpl::Type::RECEIVE, observer->match_fun_, observer->get_payload(), this_comm, + mbox->find_matching_comm(CommImpl::Type::RECEIVE, observer->get_match_fun(), observer->get_payload(), this_comm, /*done*/ false, /*remove_matching*/ true); if (not other_comm) { @@ -304,7 +304,7 @@ ActivityImplPtr CommImpl::isend(actor::CommIsendSimcall* observer) if (observer->is_detached()) { other_comm->detach(); - other_comm->clean_fun = observer->clean_fun_; + other_comm->clean_fun = observer->get_clean_fun(); } else { other_comm->clean_fun = nullptr; observer->get_issuer()->activities_.emplace_back(other_comm); @@ -318,8 +318,8 @@ ActivityImplPtr CommImpl::isend(actor::CommIsendSimcall* observer) .set_size(observer->get_payload_size()) .set_rate(observer->get_rate()); - other_comm->match_fun = observer->match_fun_; - other_comm->copy_data_fun = observer->copy_data_fun_; + other_comm->match_fun = observer->get_match_fun(); + other_comm->copy_data_fun = observer->get_copy_data_fun(); if (MC_is_active() || MC_record_replay_is_active()) other_comm->set_state(simgrid::kernel::activity::State::RUNNING); @@ -329,7 +329,7 @@ ActivityImplPtr CommImpl::isend(actor::CommIsendSimcall* observer) return (observer->is_detached() ? nullptr : other_comm); } -ActivityImplPtr CommImpl::irecv(actor::CommIrecvSimcall* observer) +ActivityImplPtr CommImpl::irecv(const actor::CommIrecvSimcall* observer) { CommImplPtr this_synchro(new CommImpl(CommImpl::Type::RECEIVE)); auto* mbox = observer->get_mailbox(); @@ -340,7 +340,7 @@ ActivityImplPtr CommImpl::irecv(actor::CommIrecvSimcall* observer) if (mbox->is_permanent() && mbox->has_some_done_comm()) { 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(CommImpl::Type::SEND, observer->match_fun_, observer->get_payload(), + other_comm = mbox->find_matching_comm(CommImpl::Type::SEND, observer->get_match_fun(), observer->get_payload(), 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) { @@ -362,7 +362,7 @@ ActivityImplPtr CommImpl::irecv(actor::CommIrecvSimcall* observer) * 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(CommImpl::Type::SEND, observer->match_fun_, observer->get_payload(), + other_comm = mbox->find_matching_comm(CommImpl::Type::SEND, observer->get_match_fun(), observer->get_payload(), this_synchro, /*done*/ false, /*remove_matching*/ true); if (other_comm == nullptr) { @@ -385,8 +385,8 @@ ActivityImplPtr CommImpl::irecv(actor::CommIrecvSimcall* observer) if (observer->get_rate() > -1.0 && (other_comm->get_rate() < 0.0 || observer->get_rate() < other_comm->get_rate())) other_comm->set_rate(observer->get_rate()); - other_comm->match_fun = observer->match_fun_; - other_comm->copy_data_fun = observer->copy_data_fun_; + other_comm->match_fun = observer->get_match_fun(); + other_comm->copy_data_fun = observer->get_copy_data_fun(); if (MC_is_active() || MC_record_replay_is_active()) { other_comm->set_state(State::RUNNING); diff --git a/src/kernel/activity/CommImpl.hpp b/src/kernel/activity/CommImpl.hpp index 3837b6b28f..7141785702 100644 --- a/src/kernel/activity/CommImpl.hpp +++ b/src/kernel/activity/CommImpl.hpp @@ -53,8 +53,8 @@ public: std::vector get_traversed_links() const; void copy_data(); - static ActivityImplPtr isend(actor::CommIsendSimcall* observer); - static ActivityImplPtr irecv(actor::CommIrecvSimcall* observer); + static ActivityImplPtr isend(const actor::CommIsendSimcall* observer); + static ActivityImplPtr irecv(const actor::CommIrecvSimcall* observer); bool test(actor::ActorImpl* issuer) override; void wait_for(actor::ActorImpl* issuer, double timeout) override; diff --git a/src/kernel/actor/SimcallObserver.hpp b/src/kernel/actor/SimcallObserver.hpp index f75ae91321..98cada2d2d 100644 --- a/src/kernel/actor/SimcallObserver.hpp +++ b/src/kernel/actor/SimcallObserver.hpp @@ -218,11 +218,11 @@ class CommIsendSimcall : public SimcallObserver { void* payload_; bool detached_; -public: bool (*match_fun_)(void*, void*, activity::CommImpl*); void (*clean_fun_)(void*); // used to free the synchro in case of problem after a detached send void (*copy_data_fun_)(activity::CommImpl*, void*, size_t); // used to copy data if not default one +public: CommIsendSimcall(ActorImpl* actor, activity::MailboxImpl* mbox, double payload_size, double rate, unsigned char* src_buff, size_t src_buff_size, bool (*match_fun)(void*, void*, activity::CommImpl*), void (*clean_fun)(void*), // used to free the synchro in case of problem after a detached send @@ -250,6 +250,10 @@ public: size_t get_src_buff_size() const { return src_buff_size_; } void* get_payload() const { return payload_; } bool is_detached() const { return detached_; } + + auto get_match_fun() const { return match_fun_; } + auto get_clean_fun() const { return clean_fun_; } + auto get_copy_data_fun() const { return copy_data_fun_; } }; class CommIrecvSimcall : public SimcallObserver { @@ -259,10 +263,10 @@ class CommIrecvSimcall : public SimcallObserver { void* payload_; double rate_; -public: bool (*match_fun_)(void*, void*, activity::CommImpl*); void (*copy_data_fun_)(activity::CommImpl*, void*, size_t); // used to copy data if not default one +public: CommIrecvSimcall(ActorImpl* actor, activity::MailboxImpl* mbox, unsigned char* dst_buff, size_t* dst_buff_size, bool (*match_fun)(void*, void*, activity::CommImpl*), void (*copy_data_fun)(activity::CommImpl*, void*, size_t), void* payload, double rate) @@ -283,6 +287,9 @@ public: unsigned char* get_dst_buff() const { return dst_buff_; } size_t* get_dst_buff_size() const { return dst_buff_size_; } void* get_payload() const { return payload_; } + + auto get_match_fun() const { return match_fun_; }; + auto get_copy_data_fun() const { return copy_data_fun_; } }; } // namespace actor -- 2.20.1