Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[s4u] Activity ought not to be copied
[simgrid.git] / include / simgrid / s4u / mutex.hpp
index 52accd1..5b0f7f5 100644 (file)
@@ -6,31 +6,53 @@
 #ifndef SIMGRID_S4U_MUTEX_HPP
 #define SIMGRID_S4U_MUTEX_HPP
 
+#include <mutex>
+#include <utility>
+
+#include <boost/intrusive_ptr.hpp>
+
 #include <xbt/base.h>
 #include "simgrid/simix.h"
 
-
 namespace simgrid {
 namespace s4u {
 
-XBT_PUBLIC_CLASS Mutex {
+class ConditionVariable;
 
+XBT_PUBLIC_CLASS Mutex {
+friend ConditionVariable;
+private:
+  friend simgrid::simix::Mutex;
+  simgrid::simix::Mutex* mutex_;
+  Mutex(simgrid::simix::Mutex* mutex) : mutex_(mutex) {}
 public:
-  Mutex();
-  ~Mutex() {};
 
-protected:
+  friend void intrusive_ptr_add_ref(Mutex* mutex)
+  {
+    xbt_assert(mutex);
+    SIMIX_mutex_ref(mutex->mutex_);
+  }
+  friend void intrusive_ptr_release(Mutex* mutex)
+  {
+    xbt_assert(mutex);
+    SIMIX_mutex_unref(mutex->mutex_);
+  }
+  using Ptr = boost::intrusive_ptr<Mutex>;
 
-public:
+  // No copy:
+  Mutex(Mutex const&) = delete;
+  Mutex& operatori(Mutex const&) = delete;
+
+  static Ptr createMutex();
 
+public:
   void lock();
   void unlock();
   bool try_lock();
+};
 
-private:
-  std::shared_ptr<simgrid::simix::Mutex> _mutex;
+using MutexPtr = Mutex::Ptr;
 
-};
 }} // namespace simgrid::s4u
 
 #endif /* SIMGRID_S4U_MUTEX_HPP */