+namespace simgrid {
+namespace simix {
+
+class XBT_PUBLIC() MutexImpl {
+public:
+ MutexImpl();
+ ~MutexImpl();
+ MutexImpl(MutexImpl const&) = delete;
+ MutexImpl& operator=(MutexImpl const&) = delete;
+
+ void lock(smx_actor_t issuer);
+ bool try_lock(smx_actor_t issuer);
+ void unlock(smx_actor_t issuer);
+
+ bool locked = false;
+ smx_actor_t owner = nullptr;
+ // List of sleeping processes:
+ xbt_swag_t sleeping = nullptr;
+
+ // boost::intrusive_ptr<Mutex> support:
+ friend void intrusive_ptr_add_ref(MutexImpl* mutex)
+ {
+ // Atomic operation! Do not split in two instructions!
+ XBT_ATTRIB_UNUSED auto previous = (mutex->refcount_)++;
+ xbt_assert(previous != 0);
+ }
+ friend void intrusive_ptr_release(MutexImpl* mutex)
+ {
+ // Atomic operation! Do not split in two instructions!
+ auto count = --(mutex->refcount_);
+ if (count == 0)
+ delete mutex;
+ }
+
+ simgrid::s4u::Mutex& mutex() { return mutex_; }
+
+private:
+ std::atomic_int_fast32_t refcount_ { 1 };
+ simgrid::s4u::Mutex mutex_;
+};
+
+}
+}