Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics: make more fields private
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 7 May 2019 12:45:53 +0000 (14:45 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 7 May 2019 12:45:53 +0000 (14:45 +0200)
src/kernel/activity/CommImpl.cpp
src/kernel/activity/CommImpl.hpp
src/kernel/activity/MailboxImpl.cpp
src/kernel/activity/MailboxImpl.hpp
src/kernel/activity/MutexImpl.hpp
src/kernel/activity/SemaphoreImpl.hpp
src/mc/checker/CommunicationDeterminismChecker.cpp
src/mc/mc_base.cpp
src/mc/mc_request.cpp
src/mc/mc_state.cpp
src/smpi/internals/smpi_global.cpp

index 1410e40..4a1c8f6 100644 (file)
@@ -73,7 +73,7 @@ XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_isend(
   }
 
   if (detached) {
-    other_comm->detached_ = true;
+    other_comm->detach();
     other_comm->clean_fun = clean_fun;
   } else {
     other_comm->clean_fun = nullptr;
@@ -137,8 +137,7 @@ XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_irecv(
       if (other_comm->surf_action_ && other_comm->get_remaining() < 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->set_type(simgrid::kernel::activity::CommImpl::Type::DONE);
-        other_comm->mbox   = nullptr;
+        other_comm->set_type(simgrid::kernel::activity::CommImpl::Type::DONE).set_mailbox(nullptr);
       }
     }
   } else {
@@ -340,8 +339,8 @@ void SIMIX_comm_copy_buffer_callback(simgrid::kernel::activity::CommImpl* comm,
 {
   XBT_DEBUG("Copy the data over");
   memcpy(comm->dst_buff_, buff, buff_size);
-  if (comm->detached_) { // if this is a detached send, the source buffer was duplicated by SMPI sender to make the
-                        // original buffer available to the application ASAP
+  if (comm->detached()) { // if this is a detached send, the source buffer was duplicated by SMPI sender to make the
+                          // original buffer available to the application ASAP
     xbt_free(buff);
     comm->src_buff_ = nullptr;
   }
@@ -379,6 +378,11 @@ CommImpl& CommImpl::set_rate(double rate)
   rate_ = rate;
   return *this;
 }
+CommImpl& CommImpl::set_mailbox(MailboxImpl* mbox)
+{
+  mbox_ = mbox;
+  return *this;
+}
 
 CommImpl& CommImpl::set_src_buff(unsigned char* buff, size_t size)
 {
@@ -394,6 +398,12 @@ CommImpl& CommImpl::set_dst_buff(unsigned char* buff, size_t* size)
   return *this;
 }
 
+CommImpl& CommImpl::detach()
+{
+  detached_ = true;
+  return *this;
+}
+
 CommImpl::~CommImpl()
 {
   XBT_DEBUG("Really free communication %p in state %d (detached = %d)", this, static_cast<int>(state_), detached_);
@@ -406,8 +416,8 @@ CommImpl::~CommImpl()
     if (clean_fun)
       clean_fun(src_buff_);
     src_buff_ = nullptr;
-  } else if (mbox) {
-    mbox->remove(this);
+  } else if (mbox_) {
+    mbox_->remove(this);
   }
 }
 
@@ -459,7 +469,7 @@ void CommImpl::copy_data()
 {
   size_t buff_size = src_buff_size_;
   /* If there is no data to copy then return */
-  if (not src_buff_ || not dst_buff_ || copied)
+  if (not src_buff_ || not dst_buff_ || copied_)
     return;
 
   XBT_DEBUG("Copying comm %p data from %s (%p) -> %s (%p) (%zu bytes)", this,
@@ -483,7 +493,7 @@ void CommImpl::copy_data()
 
   /* Set the copied flag so we copy data only once */
   /* (this function might be called from both communication ends) */
-  copied = true;
+  copied_ = true;
 }
 
 void CommImpl::suspend()
@@ -507,7 +517,7 @@ void CommImpl::cancel()
   /* if the synchro is a waiting state means that it is still in a mbox so remove from it and delete it */
   if (state_ == SIMIX_WAITING) {
     if (not detached_) {
-      mbox->remove(this);
+      mbox_->remove(this);
       state_ = SIMIX_CANCELED;
     }
   } else if (not MC_is_active() /* when running the MC there are no surf actions */
@@ -588,8 +598,8 @@ void CommImpl::finish()
     }
 
     /* If the synchro is still in a rendez-vous point then remove from it */
-    if (mbox)
-      mbox->remove(this);
+    if (mbox_)
+      mbox_->remove(this);
 
     XBT_DEBUG("CommImpl::finish(): synchro state = %d", static_cast<int>(state_));
 
index 559fd9d..9321faf 100644 (file)
@@ -19,8 +19,11 @@ class XBT_PUBLIC CommImpl : public ActivityImpl_T<CommImpl> {
   ~CommImpl() override;
   void cleanupSurf();
 
-  double rate_ = 0.0;
-  double size_ = 0.0;
+  double rate_       = 0.0;
+  double size_       = 0.0;
+  bool detached_     = false;   /* If detached or not */
+  bool copied_       = false;   /* whether the data were already copied */
+  MailboxImpl* mbox_ = nullptr; /* Rendez-vous where the comm is queued */
 
 public:
   enum class Type { SEND = 0, RECEIVE, READY, DONE };
@@ -30,7 +33,12 @@ public:
   CommImpl& set_src_buff(unsigned char* buff, size_t size);
   CommImpl& set_dst_buff(unsigned char* buff, size_t* size);
   CommImpl& set_rate(double rate);
-  double get_rate() { return rate_; }
+  CommImpl& set_mailbox(MailboxImpl* mbox);
+  CommImpl& detach();
+
+  double get_rate() const { return rate_; }
+  MailboxImpl* get_mailbox() const { return mbox_; }
+  bool detached() const { return detached_; }
 
   void copy_data();
 
@@ -42,14 +50,12 @@ public:
   void finish() override;
 
   CommImpl::Type type_;        /* Type of the communication (SIMIX_COMM_SEND or SIMIX_COMM_RECEIVE) */
-  MailboxImpl* mbox = nullptr; /* Rendez-vous where the comm is queued */
 
 #if SIMGRID_HAVE_MC
   MailboxImpl* mbox_cpy = nullptr; /* Copy of the rendez-vous where the comm is queued, MC needs it for DPOR
                                      (comm.mbox set to nullptr when the communication is removed from the mailbox
                                      (used as garbage collector)) */
 #endif
-  bool detached_ = false; /* If detached or not */
 
   void (*clean_fun)(void*) = nullptr; /* Function to clean the detached src_buf if something goes wrong */
   int (*match_fun)(void*, void*, CommImpl*) = nullptr; /* Filter function used by the other side. It is used when
@@ -68,7 +74,6 @@ expectations of the other side, too. See  */
   unsigned char* dst_buff_ = nullptr;
   size_t src_buff_size_    = 0;
   size_t* dst_buff_size_   = nullptr;
-  bool copied              = false; /* whether the data were already copied */
 
   void* src_data_ = nullptr; /* User data associated to the communication */
   void* dst_data_ = nullptr;
index c7a8362..3137c62 100644 (file)
@@ -64,7 +64,7 @@ void MailboxImpl::set_receiver(s4u::ActorPtr actor)
  */
 void MailboxImpl::push(CommImplPtr comm)
 {
-  comm->mbox = this;
+  comm->set_mailbox(this);
   this->comm_queue_.push_back(std::move(comm));
 }
 
@@ -73,9 +73,10 @@ void MailboxImpl::push(CommImplPtr comm)
  */
 void MailboxImpl::remove(const CommImplPtr& comm)
 {
-  xbt_assert(comm->mbox == this, "Comm %p is in mailbox %s, not mailbox %s", comm.get(),
-             (comm->mbox ? comm->mbox->get_cname() : "(null)"), this->get_cname());
-  comm->mbox = nullptr;
+  xbt_assert(comm->get_mailbox() == this, "Comm %p is in mailbox %s, not mailbox %s", comm.get(),
+             (comm->get_mailbox() ? comm->get_mailbox()->get_cname() : "(null)"), this->get_cname());
+
+  comm->set_mailbox(nullptr);
   for (auto it = this->comm_queue_.begin(); it != this->comm_queue_.end(); it++)
     if (*it == comm) {
       this->comm_queue_.erase(it);
@@ -140,9 +141,9 @@ CommImplPtr MailboxImpl::find_matching_comm(CommImpl::Type type, int (*match_fun
         (not comm->match_fun || comm->match_fun(other_user_data, this_user_data, my_synchro.get()))) {
       XBT_DEBUG("Found a matching communication synchro %p", comm.get());
 #if SIMGRID_HAVE_MC
-      comm->mbox_cpy = comm->mbox;
+      comm->mbox_cpy = comm->get_mailbox();
 #endif
-      comm->mbox = nullptr;
+      comm->set_mailbox(nullptr);
       CommImplPtr comm_cpy = comm;
       if (remove_matching)
         comm_queue.erase(it);
index 29b561c..b176c76 100644 (file)
@@ -22,6 +22,9 @@ namespace activity {
 class MailboxImpl {
   static constexpr size_t MAX_MAILBOX_SIZE = 10000000;
 
+  s4u::Mailbox piface_;
+  xbt::string name_;
+
   friend s4u::Mailbox;
   friend s4u::Mailbox* s4u::Mailbox::by_name(const std::string& name);
   friend mc::CommunicationDeterminismChecker;
@@ -43,11 +46,6 @@ public:
   CommImplPtr find_matching_comm(CommImpl::Type type, int (*match_fun)(void*, void*, CommImpl*), void* this_user_data,
                                  const CommImplPtr& my_synchro, bool done, bool remove_matching);
 
-private:
-  s4u::Mailbox piface_;
-  xbt::string name_;
-
-public:
   actor::ActorImplPtr permanent_receiver_; // actor to which the mailbox is attached
   boost::circular_buffer_space_optimized<CommImplPtr> comm_queue_;
   boost::circular_buffer_space_optimized<CommImplPtr> done_comm_queue_; // messages already received in the permanent
index 27a47c1..3abf068 100644 (file)
@@ -15,6 +15,10 @@ namespace kernel {
 namespace activity {
 
 class XBT_PUBLIC MutexImpl {
+  std::atomic_int_fast32_t refcount_{1};
+  s4u::Mutex piface_;
+  bool locked_ = false;
+
 public:
   MutexImpl() : piface_(this) {}
   MutexImpl(MutexImpl const&) = delete;
@@ -23,10 +27,11 @@ public:
   void lock(actor::ActorImpl* issuer);
   bool try_lock(actor::ActorImpl* issuer);
   void unlock(actor::ActorImpl* issuer);
+  bool is_locked() { return locked_; }
 
   MutexImpl* ref();
   void unref();
-  bool locked_             = false;
+
   actor::ActorImpl* owner_ = nullptr;
   // List of sleeping actors:
   actor::SynchroList sleeping_;
@@ -45,10 +50,6 @@ public:
   }
 
   s4u::Mutex& mutex() { return piface_; }
-
-private:
-  std::atomic_int_fast32_t refcount_{1};
-  s4u::Mutex piface_;
 };
 }
 }
index 73faa7b..e6dc57d 100644 (file)
@@ -17,7 +17,12 @@ namespace kernel {
 namespace activity {
 
 class XBT_PUBLIC SemaphoreImpl {
+  std::atomic_int_fast32_t refcount_{1};
+  unsigned int value_;
+
 public:
+  actor::SynchroList sleeping_; /* list of sleeping actors*/
+
   explicit SemaphoreImpl(unsigned int value) : value_(value){};
   ~SemaphoreImpl() = default;
 
@@ -27,6 +32,7 @@ public:
   void acquire(actor::ActorImpl* issuer, double timeout);
   void release();
   bool would_block() { return (value_ == 0); }
+
   unsigned int get_capacity() { return value_; }
 
   friend void intrusive_ptr_add_ref(SemaphoreImpl* sem)
@@ -39,12 +45,6 @@ public:
     if (sem->refcount_.fetch_sub(1) == 1)
       delete sem;
   }
-
-  unsigned int value_;
-  actor::SynchroList sleeping_; /* list of sleeping actors*/
-
-private:
-  std::atomic_int_fast32_t refcount_{1};
 };
 } // namespace activity
 } // namespace kernel
index 153ad68..d08d529 100644 (file)
@@ -188,8 +188,8 @@ void CommunicationDeterminismChecker::get_comm_pattern(smx_simcall_t request, e_
     simgrid::kernel::activity::CommImpl* synchro =
         static_cast<simgrid::kernel::activity::CommImpl*>(temp_synchro.getBuffer());
 
-    char* remote_name = mc_model_checker->process().read<char*>(
-        RemotePtr<char*>((uint64_t)(synchro->mbox ? &synchro->mbox->name_ : &synchro->mbox_cpy->name_)));
+    char* remote_name = mc_model_checker->process().read<char*>(RemotePtr<char*>(
+        (uint64_t)(synchro->get_mailbox() ? &synchro->get_mailbox()->name_ : &synchro->mbox_cpy->name_)));
     pattern->rdv      = mc_model_checker->process().read_string(RemotePtr<char>(remote_name));
     pattern->src_proc =
         mc_model_checker->process().resolveActor(simgrid::mc::remote(synchro->src_actor_.get()))->get_pid();
@@ -236,9 +236,10 @@ void CommunicationDeterminismChecker::get_comm_pattern(smx_simcall_t request, e_
     simgrid::kernel::activity::CommImpl* comm = temp_comm.getBuffer();
 
     char* remote_name;
-    mc_model_checker->process().read(
-        &remote_name, remote(comm->mbox ? &simgrid::xbt::string::to_string_data(comm->mbox->name_).data
-                                        : &simgrid::xbt::string::to_string_data(comm->mbox_cpy->name_).data));
+    mc_model_checker->process().read(&remote_name,
+                                     remote(comm->get_mailbox()
+                                                ? &simgrid::xbt::string::to_string_data(comm->get_mailbox()->name_).data
+                                                : &simgrid::xbt::string::to_string_data(comm->mbox_cpy->name_).data));
     pattern->rdv      = mc_model_checker->process().read_string(RemotePtr<char>(remote_name));
     pattern->dst_proc =
         mc_model_checker->process().resolveActor(simgrid::mc::remote(comm->dst_actor_.get()))->get_pid();
index 64643ea..ff7dbe3 100644 (file)
@@ -97,7 +97,7 @@ 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 &&
+      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_);
index b531d8d..735a629 100644 (file)
@@ -335,7 +335,7 @@ std::string simgrid::mc::request_to_string(smx_simcall_t req, int value, simgrid
         : simcall_mutex_trylock__get__mutex(req)
       ));
     args = bprintf(
-        "locked = %d, owner = %d, sleeping = n/a", mutex.getBuffer()->locked_,
+        "locked = %d, owner = %d, sleeping = n/a", mutex.getBuffer()->is_locked(),
         mutex.getBuffer()->owner_ != nullptr
             ? (int)mc_model_checker->process().resolveActor(simgrid::mc::remote(mutex.getBuffer()->owner_))->get_pid()
             : -1);
index a30a6bb..7f8fa6b 100644 (file)
@@ -119,7 +119,7 @@ static inline smx_simcall_t MC_state_get_request_for_process(simgrid::mc::State*
       if (act->src_actor_.get() && act->dst_actor_.get())
         state->transition.argument = 0;
       else if (act->src_actor_.get() == nullptr && act->type_ == simgrid::kernel::activity::CommImpl::Type::READY &&
-               act->detached_)
+               act->detached())
         state->transition.argument = 0;
       else
         state->transition.argument = -1;
index 15727be..2991121 100644 (file)
@@ -214,7 +214,7 @@ void smpi_comm_copy_buffer_callback(simgrid::kernel::activity::CommImpl* comm, v
   XBT_DEBUG("Copying %zu bytes from %p to %p", buff_size, tmpbuff, comm->dst_buff_);
   memcpy_private(comm->dst_buff_, tmpbuff, private_blocks);
 
-  if (comm->detached_) {
+  if (comm->detached()) {
     // if this is a detached send, the source buffer was duplicated by SMPI
     // sender to make the original buffer available to the application ASAP
     xbt_free(buff);