X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/96cedde3cdbc0b8ffc3f096a1b65d021b0226f99..59d583b361923a665cac4daa80565eb2224e9d25:/src/kernel/activity/MutexImpl.hpp diff --git a/src/kernel/activity/MutexImpl.hpp b/src/kernel/activity/MutexImpl.hpp index 613d799477..f372ea76d5 100644 --- a/src/kernel/activity/MutexImpl.hpp +++ b/src/kernel/activity/MutexImpl.hpp @@ -3,11 +3,11 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#ifndef SIMIX_MUTEXIMPL_HPP -#define SIMIX_MUTEXIMPL_HPP +#ifndef SIMGRID_KERNEL_ACTIVITY_MUTEX_HPP +#define SIMGRID_KERNEL_ACTIVITY_MUTEX_HPP #include "simgrid/s4u/ConditionVariable.hpp" -#include "src/simix/ActorImpl.hpp" +#include "src/kernel/actor/ActorImpl.hpp" #include namespace simgrid { @@ -15,20 +15,26 @@ namespace kernel { namespace activity { class XBT_PUBLIC MutexImpl { + std::atomic_int_fast32_t refcount_{1}; + s4u::Mutex piface_; + bool locked_ = false; + public: - MutexImpl(); - ~MutexImpl(); + MutexImpl() : piface_(this) {} 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); + 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; - smx_actor_t owner = nullptr; - // List of sleeping processes: - simgrid::kernel::actor::SynchroList sleeping; + actor::ActorImpl* owner_ = nullptr; + // List of sleeping actors: + actor::SynchroList sleeping_; // boost::intrusive_ptr support: friend void intrusive_ptr_add_ref(MutexImpl* mutex) @@ -36,19 +42,16 @@ public: XBT_ATTRIB_UNUSED auto previous = mutex->refcount_.fetch_add(1); xbt_assert(previous != 0); } + friend void intrusive_ptr_release(MutexImpl* mutex) { if (mutex->refcount_.fetch_sub(1) == 1) delete mutex; } - simgrid::s4u::Mutex& mutex() { return piface_; } - -private: - std::atomic_int_fast32_t refcount_{1}; - simgrid::s4u::Mutex piface_; + s4u::Mutex& mutex() { return piface_; } }; -} -} -} -#endif /* SIMIX_MUTEXIMPL_HPP */ +} // namespace activity +} // namespace kernel +} // namespace simgrid +#endif