Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of framagit.org:simgrid/simgrid
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sat, 13 Mar 2021 22:17:28 +0000 (23:17 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Sat, 13 Mar 2021 22:17:28 +0000 (23:17 +0100)
24 files changed:
include/simgrid/forward.h
include/simgrid/s4u/ConditionVariable.hpp
include/simgrid/s4u/Mutex.hpp
include/simgrid/s4u/Semaphore.hpp
include/simgrid/simix.h
src/kernel/activity/ConditionVariableImpl.cpp
src/kernel/activity/MutexImpl.hpp
src/kernel/activity/SemaphoreImpl.cpp
src/kernel/activity/SemaphoreImpl.hpp
src/mc/checker/SimcallObserver.cpp
src/mc/checker/SimcallObserver.hpp
src/mc/mc_base.cpp
src/s4u/s4u_ConditionVariable.cpp
src/s4u/s4u_Mutex.cpp
src/s4u/s4u_Semaphore.cpp
src/simix/libsmx.cpp
src/simix/popping_accessors.hpp
src/simix/popping_bodies.cpp
src/simix/popping_enum.hpp
src/simix/popping_generated.cpp
src/simix/simcalls.in
tools/jenkins/Coverage.sh
tools/jenkins/DynamicAnalysis.sh
tools/jenkins/build.sh

index 72889a3..1eef471 100644 (file)
@@ -86,8 +86,8 @@ class File;
 class Semaphore;
 /** Smart pointer to a simgrid::s4u::Semaphore */
 using SemaphorePtr = boost::intrusive_ptr<Semaphore>;
-XBT_PUBLIC void intrusive_ptr_release(Semaphore* m);
-XBT_PUBLIC void intrusive_ptr_add_ref(Semaphore* m);
+XBT_PUBLIC void intrusive_ptr_release(const Semaphore* m);
+XBT_PUBLIC void intrusive_ptr_add_ref(const Semaphore* m);
 
 class Disk;
 } // namespace s4u
index f4903c0..e18b846 100644 (file)
@@ -26,11 +26,10 @@ namespace s4u {
 class XBT_PUBLIC ConditionVariable {
 private:
   friend kernel::activity::ConditionVariableImpl;
-  kernel::activity::ConditionVariableImpl* const cond_;
+  kernel::activity::ConditionVariableImpl* const pimpl_;
 
-public:
 #ifndef DOXYGEN
-  explicit ConditionVariable(kernel::activity::ConditionVariableImpl* cond) : cond_(cond) {}
+  explicit ConditionVariable(kernel::activity::ConditionVariableImpl* cond) : pimpl_(cond) {}
 
   ConditionVariable(ConditionVariable const&) = delete;
   ConditionVariable& operator=(ConditionVariable const&) = delete;
@@ -39,6 +38,7 @@ public:
   friend XBT_PUBLIC void intrusive_ptr_release(const ConditionVariable* cond);
 #endif
 
+public:
   /** Create a new condition variable and return a smart pointer
    *
    * @beginrst
index 2374795..f97eae8 100644 (file)
@@ -37,14 +37,13 @@ class XBT_PUBLIC Mutex {
   friend XBT_PUBLIC void intrusive_ptr_add_ref(const Mutex* mutex);
   friend XBT_PUBLIC void intrusive_ptr_release(const Mutex* mutex);
 
-public:
   explicit Mutex(kernel::activity::MutexImpl* mutex) : pimpl_(mutex) {}
-  ~Mutex();
 #ifndef DOXYGEN
   Mutex(Mutex const&) = delete;            // No copy constructor; Use MutexPtr instead
   Mutex& operator=(Mutex const&) = delete; // No direct assignment either. Use MutexPtr instead
 #endif
 
+public:
   /** Constructs a new mutex */
   static MutexPtr create();
   void lock();
index f0c8916..b100ba5 100644 (file)
@@ -29,29 +29,28 @@ namespace s4u {
  *
  */
 class XBT_PUBLIC Semaphore {
-  kernel::activity::SemaphoreImpl* const pimpl_;
-  std::atomic_int_fast32_t refcount_{0};
+  friend kernel::activity::SemaphoreImpl;
 
-  friend void intrusive_ptr_add_ref(Semaphore* sem);
-  friend void intrusive_ptr_release(Semaphore* sem);
+  kernel::activity::SemaphoreImpl* const pimpl_;
 
-public:
-  explicit Semaphore(unsigned int initial_capacity);
-  ~Semaphore();
+  friend void intrusive_ptr_add_ref(const Semaphore* sem);
+  friend void intrusive_ptr_release(const Semaphore* sem);
 
+  explicit Semaphore(kernel::activity::SemaphoreImpl* sem) : pimpl_(sem) {}
 #ifndef DOXYGEN
   Semaphore(Semaphore const&) = delete;            // No copy constructor. Use SemaphorePtr instead
   Semaphore& operator=(Semaphore const&) = delete; // No direct assignment either. Use SemaphorePtr instead
 #endif
 
+public:
   /** Constructs a new semaphore */
   static SemaphorePtr create(unsigned int initial_capacity);
 
   void acquire();
-  int acquire_timeout(double timeout);
+  bool acquire_timeout(double timeout);
   void release();
   int get_capacity() const;
-  int would_block() const;
+  bool would_block() const;
 };
 
 } // namespace s4u
index b7efc34..ab286fd 100644 (file)
@@ -204,10 +204,11 @@ XBT_ATTRIB_DEPRECATED_v331("Please use sg_mutex_try_lock()") XBT_PUBLIC int simc
 XBT_ATTRIB_DEPRECATED_v331("Please use sg_mutex_unlock()") XBT_PUBLIC void simcall_mutex_unlock(smx_mutex_t mutex);
 
 XBT_ATTRIB_DEPRECATED_v330("Please use sg_cond_init()") XBT_PUBLIC smx_cond_t simcall_cond_init();
-XBT_PUBLIC void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex);
+XBT_ATTRIB_DEPRECATED_v331("Please use sg_cond_wait()") XBT_PUBLIC
+    void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex);
 XBT_PUBLIC int simcall_cond_wait_timeout(smx_cond_t cond, smx_mutex_t mutex, double max_duration);
 
-XBT_PUBLIC void simcall_sem_acquire(smx_sem_t sem);
+XBT_ATTRIB_DEPRECATED_v331("Please use sg_sem_acquire()") XBT_PUBLIC void simcall_sem_acquire(smx_sem_t sem);
 XBT_PUBLIC int simcall_sem_acquire_timeout(smx_sem_t sem, double max_duration);
 SG_END_DECL
 
index 12ef6d0..bb15f64 100644 (file)
@@ -7,17 +7,12 @@
 #include "simgrid/Exception.hpp"
 #include "src/kernel/activity/MutexImpl.hpp"
 #include "src/kernel/activity/SynchroRaw.hpp"
+#include "src/mc/checker/SimcallObserver.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_condition, simix_synchro, "Condition variables");
 
 /********************************* Condition **********************************/
 
-/** @brief Handle a condition waiting simcall without timeouts */
-void simcall_HANDLER_cond_wait(smx_simcall_t simcall, smx_cond_t cond, smx_mutex_t mutex)
-{
-  cond->wait(mutex, -1, simcall->issuer_);
-}
-
 /** @brief Handle a condition waiting simcall with timeouts */
 void simcall_HANDLER_cond_wait_timeout(smx_simcall_t simcall, smx_cond_t cond, smx_mutex_t mutex, double timeout)
 {
@@ -51,10 +46,14 @@ void ConditionVariableImpl::signal()
     /* Now transform the cond wait simcall into a mutex lock one */
     smx_simcall_t simcall = &proc.simcall_;
     MutexImpl* simcall_mutex;
-    if (simcall->call_ == simix::Simcall::COND_WAIT)
-      simcall_mutex = simcall_cond_wait__get__mutex(simcall);
-    else
+    if (simcall->call_ == simix::Simcall::COND_WAIT_TIMEOUT)
       simcall_mutex = simcall_cond_wait_timeout__get__mutex(simcall);
+    else {
+      // FIXME? using here the MC observer to solve a problem not related to MC
+      auto* observer = dynamic_cast<mc::ConditionWaitSimcall*>(simcall->observer_);
+      xbt_assert(observer != nullptr);
+      simcall_mutex = observer->get_mutex();
+    }
     simcall->call_ = simix::Simcall::RUN_BLOCKING;
 
     simcall_mutex->lock(simcall->issuer_);
index fa291d3..f03555d 100644 (file)
@@ -6,7 +6,7 @@
 #ifndef SIMGRID_KERNEL_ACTIVITY_MUTEX_HPP
 #define SIMGRID_KERNEL_ACTIVITY_MUTEX_HPP
 
-#include "simgrid/s4u/ConditionVariable.hpp"
+#include "simgrid/s4u/Mutex.hpp"
 #include "src/kernel/actor/ActorImpl.hpp"
 #include <boost/intrusive/list.hpp>
 
index 98d38be..ec75b82 100644 (file)
@@ -43,19 +43,24 @@ void SemaphoreImpl::release()
   }
 }
 
+/** Increase the refcount for this semaphore */
+SemaphoreImpl* SemaphoreImpl::ref()
+{
+  intrusive_ptr_add_ref(this);
+  return this;
+}
+
+/** Decrease the refcount for this mutex */
+void SemaphoreImpl::unref()
+{
+  intrusive_ptr_release(this);
+}
+
 } // namespace activity
 } // namespace kernel
 } // namespace simgrid
 
 // Simcall handlers:
-/**
- * @brief Handles a sem acquire simcall without timeout.
- */
-void simcall_HANDLER_sem_acquire(smx_simcall_t simcall, smx_sem_t sem)
-{
-  sem->acquire(simcall->issuer_, -1);
-}
-
 /**
  * @brief Handles a sem acquire simcall with timeout.
  */
index 3be684e..33793ce 100644 (file)
@@ -18,11 +18,12 @@ namespace activity {
 
 class XBT_PUBLIC SemaphoreImpl {
   std::atomic_int_fast32_t refcount_{1};
+  s4u::Semaphore piface_;
   unsigned int value_;
   actor::SynchroList sleeping_; /* list of sleeping actors*/
 
 public:
-  explicit SemaphoreImpl(unsigned int value) : value_(value){};
+  explicit SemaphoreImpl(unsigned int value) : piface_(this), value_(value){};
 
   SemaphoreImpl(SemaphoreImpl const&) = delete;
   SemaphoreImpl& operator=(SemaphoreImpl const&) = delete;
@@ -35,6 +36,9 @@ public:
   unsigned int get_capacity() const { return value_; }
   bool is_used() const { return not sleeping_.empty(); }
 
+  SemaphoreImpl* ref();
+  void unref();
+
   friend void intrusive_ptr_add_ref(SemaphoreImpl* sem)
   {
     XBT_ATTRIB_UNUSED auto previous = sem->refcount_.fetch_add(1);
@@ -42,9 +46,13 @@ public:
   }
   friend void intrusive_ptr_release(SemaphoreImpl* sem)
   {
-    if (sem->refcount_.fetch_sub(1) == 1)
+    if (sem->refcount_.fetch_sub(1) == 1) {
+      xbt_assert(not sem->is_used(), "Cannot destroy semaphore since someone is still using it");
       delete sem;
+    }
   }
+
+  s4u::Semaphore& sem() { return piface_; }
 };
 } // namespace activity
 } // namespace kernel
index 3b7854c..e4ec65d 100644 (file)
@@ -75,5 +75,49 @@ bool MutexLockSimcall::is_enabled() const
 {
   return not blocking_ || mutex_->get_owner() == nullptr || mutex_->get_owner() == get_issuer();
 }
+
+std::string ConditionWaitSimcall::to_string(int time_considered) const
+{
+  std::string res = SimcallObserver::to_string(time_considered) + "Condition WAIT";
+  res += "(" + (timeout_ == -1.0 ? "" : std::to_string(timeout_)) + ")";
+  return res;
+}
+
+std::string ConditionWaitSimcall::dot_label() const
+{
+  return SimcallObserver::dot_label() + "Condition WAIT";
+}
+
+bool ConditionWaitSimcall::is_enabled() const
+{
+  static bool warned = false;
+  if (not warned) {
+    XBT_INFO("Using condition variables in model-checked code is still experimental. Use at your own risk");
+    warned = true;
+  }
+  return true;
+}
+
+std::string SemAcquireSimcall::to_string(int time_considered) const
+{
+  std::string res = SimcallObserver::to_string(time_considered) + "Sem ACQUIRE";
+  res += "(" + (timeout_ == -1.0 ? "" : std::to_string(timeout_)) + ")";
+  return res;
+}
+
+std::string SemAcquireSimcall::dot_label() const
+{
+  return SimcallObserver::dot_label() + "Sem ACQUIRE";
+}
+
+bool SemAcquireSimcall::is_enabled() const
+{
+  static bool warned = false;
+  if (not warned) {
+    XBT_INFO("Using semaphore in model-checked code is still experimental. Use at your own risk");
+    warned = true;
+  }
+  return true;
+}
 } // namespace mc
 } // namespace simgrid
index eee2c76..578edd8 100644 (file)
@@ -14,7 +14,7 @@ namespace simgrid {
 namespace mc {
 
 class SimcallObserver {
-  kernel::actor::ActorImpl* issuer_;
+  kernel::actor::ActorImpl* const issuer_;
 
 public:
   explicit SimcallObserver(kernel::actor::ActorImpl* issuer) : issuer_(issuer) {}
@@ -53,8 +53,8 @@ public:
 };
 
 class RandomSimcall : public SimcallObserver {
-  int min_;
-  int max_;
+  const int min_;
+  const int max_;
   int next_value_ = 0;
 
 public:
@@ -75,8 +75,8 @@ public:
 };
 
 class MutexLockSimcall : public SimcallObserver {
-  kernel::activity::MutexImpl* mutex_;
-  bool blocking_;
+  kernel::activity::MutexImpl* const mutex_;
+  const bool blocking_;
 
 public:
   MutexLockSimcall(smx_actor_t actor, kernel::activity::MutexImpl* mutex, bool blocking = true)
@@ -88,6 +88,43 @@ public:
   std::string dot_label() const override;
   kernel::activity::MutexImpl* get_mutex() const { return mutex_; }
 };
+
+class ConditionWaitSimcall : public SimcallObserver {
+  kernel::activity::ConditionVariableImpl* const cond_;
+  kernel::activity::MutexImpl* const mutex_;
+  const double timeout_;
+
+public:
+  ConditionWaitSimcall(smx_actor_t actor, kernel::activity::ConditionVariableImpl* cond,
+                       kernel::activity::MutexImpl* mutex, double timeout = -1.0)
+      : SimcallObserver(actor), cond_(cond), mutex_(mutex), timeout_(timeout)
+  {
+  }
+  bool is_enabled() const override;
+  bool is_visible() const override { return false; }
+  std::string to_string(int times_considered) const override;
+  std::string dot_label() const override;
+  kernel::activity::ConditionVariableImpl* get_cond() const { return cond_; }
+  kernel::activity::MutexImpl* get_mutex() const { return mutex_; }
+  double get_timeout() const { return timeout_; }
+};
+
+class SemAcquireSimcall : public SimcallObserver {
+  kernel::activity::SemaphoreImpl* const sem_;
+  const double timeout_;
+
+public:
+  SemAcquireSimcall(smx_actor_t actor, kernel::activity::SemaphoreImpl* sem, double timeout = -1.0)
+      : SimcallObserver(actor), sem_(sem), timeout_(timeout)
+  {
+  }
+  bool is_enabled() const override;
+  bool is_visible() const override { return false; }
+  std::string to_string(int times_considered) const override;
+  std::string dot_label() const override;
+  kernel::activity::SemaphoreImpl* get_sem() const { return sem_; }
+  double get_timeout() const { return timeout_; }
+};
 } // namespace mc
 } // namespace simgrid
 
index d678be4..21c2e8c 100644 (file)
@@ -125,22 +125,6 @@ bool actor_is_enabled(smx_actor_t actor)
       return false;
     }
 
-    case Simcall::SEM_ACQUIRE: {
-      static bool warned = false;
-      if (not warned)
-        XBT_INFO("Using semaphore in model-checked code is still experimental. Use at your own risk");
-      warned = true;
-      return true;
-    }
-
-    case Simcall::COND_WAIT: {
-      static bool warned = false;
-      if (not warned)
-        XBT_INFO("Using condition variables in model-checked code is still experimental. Use at your own risk");
-      warned = true;
-      return true;
-    }
-
     default:
       /* The rest of the requests are always enabled */
       return true;
index d1ffcb2..e43d0e9 100644 (file)
@@ -8,6 +8,7 @@
 #include "simgrid/s4u/ConditionVariable.hpp"
 #include "simgrid/simix.h"
 #include "src/kernel/activity/ConditionVariableImpl.hpp"
+#include "src/mc/checker/SimcallObserver.hpp"
 #include "xbt/log.hpp"
 
 #include <exception>
@@ -28,12 +29,18 @@ ConditionVariablePtr ConditionVariable::create()
  */
 void ConditionVariable::wait(MutexPtr lock)
 {
-  simcall_cond_wait(cond_, lock->pimpl_);
+  kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
+  mc::ConditionWaitSimcall observer{issuer, pimpl_, lock->pimpl_};
+  kernel::actor::simcall_blocking<void>(
+      [&observer] { observer.get_cond()->wait(observer.get_mutex(), -1.0, observer.get_issuer()); }, &observer);
 }
 
 void ConditionVariable::wait(const std::unique_lock<Mutex>& lock)
 {
-  simcall_cond_wait(cond_, lock.mutex()->pimpl_);
+  kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
+  mc::ConditionWaitSimcall observer{issuer, pimpl_, lock.mutex()->pimpl_};
+  kernel::actor::simcall_blocking<void>(
+      [&observer] { observer.get_cond()->wait(observer.get_mutex(), -1.0, observer.get_issuer()); }, &observer);
 }
 
 std::cv_status s4u::ConditionVariable::wait_for(const std::unique_lock<Mutex>& lock, double timeout)
@@ -42,7 +49,7 @@ std::cv_status s4u::ConditionVariable::wait_for(const std::unique_lock<Mutex>& l
   if (timeout < 0)
     timeout = 0.0;
 
-  if (simcall_cond_wait_timeout(cond_, lock.mutex()->pimpl_, timeout)) {
+  if (simcall_cond_wait_timeout(pimpl_, lock.mutex()->pimpl_, timeout)) {
     // If we reached the timeout, we have to take the lock again:
     lock.mutex()->lock();
     return std::cv_status::timeout;
@@ -67,22 +74,22 @@ std::cv_status ConditionVariable::wait_until(const std::unique_lock<Mutex>& lock
  */
 void ConditionVariable::notify_one()
 {
-  simgrid::kernel::actor::simcall([this]() { cond_->signal(); });
+  simgrid::kernel::actor::simcall([this]() { pimpl_->signal(); });
 }
 
 void ConditionVariable::notify_all()
 {
-  simgrid::kernel::actor::simcall([this]() { cond_->broadcast(); });
+  simgrid::kernel::actor::simcall([this]() { pimpl_->broadcast(); });
 }
 
 void intrusive_ptr_add_ref(const ConditionVariable* cond)
 {
-  intrusive_ptr_add_ref(cond->cond_);
+  intrusive_ptr_add_ref(cond->pimpl_);
 }
 
 void intrusive_ptr_release(const ConditionVariable* cond)
 {
-  intrusive_ptr_release(cond->cond_);
+  intrusive_ptr_release(cond->pimpl_);
 }
 
 } // namespace s4u
@@ -91,10 +98,7 @@ void intrusive_ptr_release(const ConditionVariable* cond)
 /* **************************** Public C interface *************************** */
 sg_cond_t sg_cond_init()
 {
-  simgrid::kernel::activity::ConditionVariableImpl* cond =
-      simgrid::kernel::actor::simcall([] { return new simgrid::kernel::activity::ConditionVariableImpl(); });
-
-  return new simgrid::s4u::ConditionVariable(cond);
+  return simgrid::s4u::ConditionVariable::create().detach();
 }
 
 void sg_cond_wait(sg_cond_t cond, sg_mutex_t mutex)
@@ -120,5 +124,5 @@ void sg_cond_notify_all(sg_cond_t cond)
 
 void sg_cond_destroy(const_sg_cond_t cond)
 {
-  delete cond;
+  intrusive_ptr_release(cond);
 }
index e855283..dfcd612 100644 (file)
 namespace simgrid {
 namespace s4u {
 
-Mutex::~Mutex()
-{
-  if (pimpl_ != nullptr)
-    pimpl_->unref();
-}
-
 /** @brief Blocks the calling actor until the mutex can be obtained */
 void Mutex::lock()
 {
@@ -60,14 +54,12 @@ MutexPtr Mutex::create()
 void intrusive_ptr_add_ref(const Mutex* mutex)
 {
   xbt_assert(mutex);
-  if (mutex->pimpl_)
-    mutex->pimpl_->ref();
+  mutex->pimpl_->ref();
 }
 void intrusive_ptr_release(const Mutex* mutex)
 {
   xbt_assert(mutex);
-  if (mutex->pimpl_)
-    mutex->pimpl_->unref();
+  mutex->pimpl_->unref();
 }
 
 } // namespace s4u
@@ -76,10 +68,7 @@ void intrusive_ptr_release(const Mutex* mutex)
 /* **************************** Public C interface *************************** */
 sg_mutex_t sg_mutex_init()
 {
-  simgrid::kernel::activity::MutexImpl* mutex =
-      simgrid::kernel::actor::simcall([] { return new simgrid::kernel::activity::MutexImpl(); });
-
-  return new simgrid::s4u::Mutex(mutex);
+  return simgrid::s4u::Mutex::create().detach();
 }
 
 void sg_mutex_lock(sg_mutex_t mutex)
@@ -99,5 +88,5 @@ int sg_mutex_try_lock(sg_mutex_t mutex)
 
 void sg_mutex_destroy(const_sg_mutex_t mutex)
 {
-  delete mutex;
+  intrusive_ptr_release(mutex);
 }
index d16abce..908378c 100644 (file)
@@ -9,29 +9,26 @@
 #include "simgrid/forward.h"
 #include "simgrid/s4u/Semaphore.hpp"
 #include "src/kernel/activity/SemaphoreImpl.hpp"
+#include "src/mc/checker/SimcallObserver.hpp"
 
 namespace simgrid {
 namespace s4u {
 
-Semaphore::Semaphore(unsigned int initial_capacity) : pimpl_(new kernel::activity::SemaphoreImpl(initial_capacity)) {}
-
-Semaphore::~Semaphore()
-{
-  xbt_assert(not pimpl_->is_used(), "Cannot destroy semaphore since someone is still using it");
-  delete pimpl_;
-}
-
 SemaphorePtr Semaphore::create(unsigned int initial_capacity)
 {
-  return SemaphorePtr(new Semaphore(initial_capacity));
+  auto* sem = new kernel::activity::SemaphoreImpl(initial_capacity);
+  return SemaphorePtr(&sem->sem(), false);
 }
 
 void Semaphore::acquire()
 {
-  simcall_sem_acquire(pimpl_);
+  kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
+  mc::SemAcquireSimcall observer{issuer, pimpl_};
+  kernel::actor::simcall_blocking<void>([&observer] { observer.get_sem()->acquire(observer.get_issuer(), -1.0); },
+                                        &observer);
 }
 
-int Semaphore::acquire_timeout(double timeout)
+bool Semaphore::acquire_timeout(double timeout)
 {
   return simcall_sem_acquire_timeout(pimpl_, timeout);
 }
@@ -46,24 +43,22 @@ int Semaphore::get_capacity() const
   return kernel::actor::simcall([this] { return pimpl_->get_capacity(); });
 }
 
-int Semaphore::would_block() const
+bool Semaphore::would_block() const
 {
   return kernel::actor::simcall([this] { return pimpl_->would_block(); });
 }
 
-void intrusive_ptr_add_ref(Semaphore* sem)
+/* refcounting of the intrusive_ptr is delegated to the implementation object */
+void intrusive_ptr_add_ref(const Semaphore* sem)
 {
   xbt_assert(sem);
-  sem->refcount_.fetch_add(1, std::memory_order_relaxed);
+  sem->pimpl_->ref();
 }
 
-void intrusive_ptr_release(Semaphore* sem)
+void intrusive_ptr_release(const Semaphore* sem)
 {
   xbt_assert(sem);
-  if (sem->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
-    std::atomic_thread_fence(std::memory_order_acquire);
-    delete sem;
-  }
+  sem->pimpl_->unref();
 }
 
 } // namespace s4u
@@ -73,7 +68,7 @@ void intrusive_ptr_release(Semaphore* sem)
 /** @brief creates a semaphore object of the given initial capacity */
 sg_sem_t sg_sem_init(int initial_value)
 {
-  return new simgrid::s4u::Semaphore(initial_value);
+  return simgrid::s4u::Semaphore::create(initial_value).detach();
 }
 
 /** @brief locks on a semaphore object */
@@ -101,7 +96,7 @@ int sg_sem_get_capacity(const_sg_sem_t sem)
 
 void sg_sem_destroy(const_sg_sem_t sem)
 {
-  delete sem;
+  intrusive_ptr_release(sem);
 }
 
 /** @brief returns a boolean indicating if this semaphore would block at this very specific time
index 2e8c87d..b203c72 100644 (file)
@@ -18,6 +18,7 @@
 #include "src/kernel/activity/IoImpl.hpp"
 #include "src/kernel/activity/MailboxImpl.hpp"
 #include "src/kernel/activity/MutexImpl.hpp"
+#include "src/kernel/activity/SemaphoreImpl.hpp"
 #include "src/mc/checker/SimcallObserver.hpp"
 #include "src/mc/mc_replay.hpp"
 #include "src/plugins/vm/VirtualMachineImpl.hpp"
@@ -291,9 +292,9 @@ smx_cond_t simcall_cond_init() // XBT_ATTRIB_DEPRECATED_v330
  * @ingroup simix_synchro_management
  *
  */
-void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
+void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex) // XBT_ATTRIB_DEPRECATED_v331
 {
-  simcall_BODY_cond_wait(cond, mutex);
+  cond->get_iface()->wait(std::unique_lock<simgrid::s4u::Mutex>(mutex->mutex()));
 }
 
 /**
@@ -310,9 +311,9 @@ int simcall_cond_wait_timeout(smx_cond_t cond, smx_mutex_t mutex, double timeout
  * @ingroup simix_synchro_management
  *
  */
-void simcall_sem_acquire(smx_sem_t sem)
+void simcall_sem_acquire(smx_sem_t sem) // XBT_ATTRIB_DEPRECATD_v331
 {
-  simcall_BODY_sem_acquire(sem);
+  return sem->sem().acquire();
 }
 
 /**
index 62c1c52..2f18af5 100644 (file)
@@ -684,31 +684,6 @@ static inline void simcall_comm_wait__set__timeout(smx_simcall_t simcall, double
   simgrid::simix::marshal<double>(simcall->args_[1], arg);
 }
 
-static inline smx_cond_t simcall_cond_wait__get__cond(smx_simcall_t simcall)
-{
-  return simgrid::simix::unmarshal<smx_cond_t>(simcall->args_[0]);
-}
-static inline smx_cond_t simcall_cond_wait__getraw__cond(smx_simcall_t simcall)
-{
-  return simgrid::simix::unmarshal_raw<smx_cond_t>(simcall->args_[0]);
-}
-static inline void simcall_cond_wait__set__cond(smx_simcall_t simcall, smx_cond_t arg)
-{
-  simgrid::simix::marshal<smx_cond_t>(simcall->args_[0], arg);
-}
-static inline smx_mutex_t simcall_cond_wait__get__mutex(smx_simcall_t simcall)
-{
-  return simgrid::simix::unmarshal<smx_mutex_t>(simcall->args_[1]);
-}
-static inline smx_mutex_t simcall_cond_wait__getraw__mutex(smx_simcall_t simcall)
-{
-  return simgrid::simix::unmarshal_raw<smx_mutex_t>(simcall->args_[1]);
-}
-static inline void simcall_cond_wait__set__mutex(smx_simcall_t simcall, smx_mutex_t arg)
-{
-  simgrid::simix::marshal<smx_mutex_t>(simcall->args_[1], arg);
-}
-
 static inline smx_cond_t simcall_cond_wait_timeout__get__cond(smx_simcall_t simcall)
 {
   return simgrid::simix::unmarshal<smx_cond_t>(simcall->args_[0]);
@@ -758,19 +733,6 @@ static inline void simcall_cond_wait_timeout__set__result(smx_simcall_t simcall,
   simgrid::simix::marshal<int>(simcall->result_, result);
 }
 
-static inline smx_sem_t simcall_sem_acquire__get__sem(smx_simcall_t simcall)
-{
-  return simgrid::simix::unmarshal<smx_sem_t>(simcall->args_[0]);
-}
-static inline smx_sem_t simcall_sem_acquire__getraw__sem(smx_simcall_t simcall)
-{
-  return simgrid::simix::unmarshal_raw<smx_sem_t>(simcall->args_[0]);
-}
-static inline void simcall_sem_acquire__set__sem(smx_simcall_t simcall, smx_sem_t arg)
-{
-  simgrid::simix::marshal<smx_sem_t>(simcall->args_[0], arg);
-}
-
 static inline smx_sem_t simcall_sem_acquire_timeout__get__sem(smx_simcall_t simcall)
 {
   return simgrid::simix::unmarshal<smx_sem_t>(simcall->args_[0]);
@@ -845,7 +807,5 @@ XBT_PRIVATE void simcall_HANDLER_comm_test(smx_simcall_t simcall, simgrid::kerne
 XBT_PRIVATE void simcall_HANDLER_comm_testany(smx_simcall_t simcall, simgrid::kernel::activity::CommImpl** comms, size_t count);
 XBT_PRIVATE void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, simgrid::kernel::activity::CommImpl** comms, size_t count, double timeout);
 XBT_PRIVATE void simcall_HANDLER_comm_wait(smx_simcall_t simcall, simgrid::kernel::activity::CommImpl* comm, double timeout);
-XBT_PRIVATE void simcall_HANDLER_cond_wait(smx_simcall_t simcall, smx_cond_t cond, smx_mutex_t mutex);
 XBT_PRIVATE void simcall_HANDLER_cond_wait_timeout(smx_simcall_t simcall, smx_cond_t cond, smx_mutex_t mutex, double timeout);
-XBT_PRIVATE void simcall_HANDLER_sem_acquire(smx_simcall_t simcall, smx_sem_t sem);
 XBT_PRIVATE void simcall_HANDLER_sem_acquire_timeout(smx_simcall_t simcall, smx_sem_t sem, double timeout);
index ea1fa58..6e818e8 100644 (file)
@@ -104,13 +104,6 @@ inline static void simcall_BODY_comm_wait(simgrid::kernel::activity::CommImpl* c
   return simcall<void, simgrid::kernel::activity::CommImpl*, double>(Simcall::COMM_WAIT, comm, timeout);
 }
 
-inline static void simcall_BODY_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
-{
-  if (false) /* Go to that function to follow the code flow through the simcall barrier */
-    simcall_HANDLER_cond_wait(&SIMIX_process_self()->simcall_, cond, mutex);
-  return simcall<void, smx_cond_t, smx_mutex_t>(Simcall::COND_WAIT, cond, mutex);
-}
-
 inline static int simcall_BODY_cond_wait_timeout(smx_cond_t cond, smx_mutex_t mutex, double timeout)
 {
   if (false) /* Go to that function to follow the code flow through the simcall barrier */
@@ -118,13 +111,6 @@ inline static int simcall_BODY_cond_wait_timeout(smx_cond_t cond, smx_mutex_t mu
   return simcall<int, smx_cond_t, smx_mutex_t, double>(Simcall::COND_WAIT_TIMEOUT, cond, mutex, timeout);
 }
 
-inline static void simcall_BODY_sem_acquire(smx_sem_t sem)
-{
-  if (false) /* Go to that function to follow the code flow through the simcall barrier */
-    simcall_HANDLER_sem_acquire(&SIMIX_process_self()->simcall_, sem);
-  return simcall<void, smx_sem_t>(Simcall::SEM_ACQUIRE, sem);
-}
-
 inline static int simcall_BODY_sem_acquire_timeout(smx_sem_t sem, double timeout)
 {
   if (false) /* Go to that function to follow the code flow through the simcall barrier */
index 903a7f5..44ddc0a 100644 (file)
@@ -30,14 +30,12 @@ enum class Simcall {
   COMM_TESTANY,
   COMM_WAITANY,
   COMM_WAIT,
-  COND_WAIT,
   COND_WAIT_TIMEOUT,
-  SEM_ACQUIRE,
   SEM_ACQUIRE_TIMEOUT,
   RUN_KERNEL,
   RUN_BLOCKING,
 };
 
-constexpr int NUM_SIMCALLS = 16;
+constexpr int NUM_SIMCALLS = 14;
 } // namespace simix
 } // namespace simgrid
index b6d0c2b..cd7b155 100644 (file)
@@ -38,9 +38,7 @@ constexpr std::array<const char*, simgrid::simix::NUM_SIMCALLS> simcall_names{{
     "Simcall::COMM_TESTANY",
     "Simcall::COMM_WAITANY",
     "Simcall::COMM_WAIT",
-    "Simcall::COND_WAIT",
     "Simcall::COND_WAIT_TIMEOUT",
-    "Simcall::SEM_ACQUIRE",
     "Simcall::SEM_ACQUIRE_TIMEOUT",
     "Simcall::RUN_KERNEL",
     "Simcall::RUN_BLOCKING",
@@ -98,18 +96,10 @@ void simgrid::kernel::actor::ActorImpl::simcall_handle(int times_considered_)
       simcall_HANDLER_comm_wait(&simcall_, simgrid::simix::unmarshal<simgrid::kernel::activity::CommImpl*>(simcall_.args_[0]), simgrid::simix::unmarshal<double>(simcall_.args_[1]));
       break;
 
-    case Simcall::COND_WAIT:
-      simcall_HANDLER_cond_wait(&simcall_, simgrid::simix::unmarshal<smx_cond_t>(simcall_.args_[0]), simgrid::simix::unmarshal<smx_mutex_t>(simcall_.args_[1]));
-      break;
-
     case Simcall::COND_WAIT_TIMEOUT:
       simcall_HANDLER_cond_wait_timeout(&simcall_, simgrid::simix::unmarshal<smx_cond_t>(simcall_.args_[0]), simgrid::simix::unmarshal<smx_mutex_t>(simcall_.args_[1]), simgrid::simix::unmarshal<double>(simcall_.args_[2]));
       break;
 
-    case Simcall::SEM_ACQUIRE:
-      simcall_HANDLER_sem_acquire(&simcall_, simgrid::simix::unmarshal<smx_sem_t>(simcall_.args_[0]));
-      break;
-
     case Simcall::SEM_ACQUIRE_TIMEOUT:
       simcall_HANDLER_sem_acquire_timeout(&simcall_, simgrid::simix::unmarshal<smx_sem_t>(simcall_.args_[0]), simgrid::simix::unmarshal<double>(simcall_.args_[1]));
       break;
index 48d8d24..cf83ac8 100644 (file)
@@ -46,10 +46,8 @@ int            comm_testany(simgrid::kernel::activity::CommImpl** comms, size_t
 int            comm_waitany(simgrid::kernel::activity::CommImpl** comms, size_t count, double timeout) [[block]];
 void           comm_wait(simgrid::kernel::activity::CommImpl* comm, double timeout) [[block]];
 
-void       cond_wait(smx_cond_t cond, smx_mutex_t mutex) [[block]];
 int        cond_wait_timeout(smx_cond_t cond, smx_mutex_t mutex, double timeout) [[block]];
 
-void      sem_acquire(smx_sem_t sem) [[block]];
 int       sem_acquire_timeout(smx_sem_t sem, double timeout) [[block]];
 
 void       run_kernel(std::function<void()> const* code) [[nohandler]];
index aeab276..c87bd31 100755 (executable)
@@ -1,14 +1,28 @@
 #!/usr/bin/env sh
 
-set -e
-
-BUILDFOLDER=$WORKSPACE/build
-
 die() {
     echo "$@"
     exit 1
 }
 
+[ -n "$WORKSPACE" ] || die "No WORKSPACE"
+[ -d "$WORKSPACE" ] || die "WORKSPACE ($WORKSPACE) does not exist"
+
+echo "XXXX Cleanup previous attempts. Remaining content of /tmp:"
+rm -f /tmp/cc*
+rm -f /tmp/*.so
+rm -rf /tmp/simgrid-java*
+rm -rf /var/tmp/simgrid-java*
+rm -rf /tmp/jvm-*
+find "$WORKSPACE" -name "hs_err_pid*.log" -exec rm -f {} +
+ls /tmp
+df -h
+echo "XXXX Let's go"
+
+set -e
+
+BUILDFOLDER=$WORKSPACE/build
+
 ### Check the node installation
 
 pkg_check() {
@@ -27,9 +41,6 @@ pkg_check xsltproc gcovr ant cover2cover.py
 
 ### Cleanup previous runs
 
-[ -n "$WORKSPACE" ] || die "No WORKSPACE"
-[ -d "$WORKSPACE" ] || die "WORKSPACE ($WORKSPACE) does not exist"
-
 do_cleanup() {
   for d
   do
index f3e2930..8b32358 100755 (executable)
@@ -1,12 +1,26 @@
 #!/usr/bin/env sh
 
-set -e
-
 die() {
     echo "$@"
     exit 1
 }
 
+[ -n "$WORKSPACE" ] || die "No WORKSPACE"
+[ -d "$WORKSPACE" ] || die "WORKSPACE ($WORKSPACE) does not exist"
+
+echo "XXXX Cleanup previous attempts. Remaining content of /tmp:"
+rm -f /tmp/cc*
+rm -f /tmp/*.so
+rm -rf /tmp/simgrid-java*
+rm -rf /var/tmp/simgrid-java*
+rm -rf /tmp/jvm-*
+find "$WORKSPACE" -name "hs_err_pid*.log" -exec rm -f {} +
+ls /tmp
+df -h
+echo "XXXX Let's go"
+
+set -e
+
 ### Check the node installation
 
 pkg_check() {
@@ -25,9 +39,6 @@ pkg_check valgrind pcregrep
 
 ### Cleanup previous runs
 
-[ -n "$WORKSPACE" ] || die "No WORKSPACE"
-[ -d "$WORKSPACE" ] || die "WORKSPACE ($WORKSPACE) does not exist"
-
 do_cleanup() {
   for d
   do
index 53ec813..b10c887 100755 (executable)
@@ -190,7 +190,7 @@ else
   MAY_DISABLE_SOURCE_CHANGE="-DCMAKE_DISABLE_SOURCE_CHANGES=ON"
 fi
 
-if [ "$os" = "CentOS" ] && [ "$(ld -v | cut -d\  -f4)" = "2.30-90.el8" ]; then
+if [ "$os" = "CentOS" ] && [ "$(ld -v | cut -d\  -f4 | cut -c1-4)" = "2.30" ]; then
   echo "Temporary disable LTO, believed to be broken on this system."
   MAY_DISABLE_LTO=-Denable_lto=OFF
 else