1 /* Copyright (c) 2012-2019. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef SIMIX_MUTEXIMPL_HPP
7 #define SIMIX_MUTEXIMPL_HPP
9 #include "simgrid/s4u/ConditionVariable.hpp"
10 #include "src/kernel/actor/ActorImpl.hpp"
11 #include <boost/intrusive/list.hpp>
17 class XBT_PUBLIC MutexImpl {
21 MutexImpl(MutexImpl const&) = delete;
22 MutexImpl& operator=(MutexImpl const&) = delete;
24 void lock(actor::ActorImpl* issuer);
25 bool try_lock(actor::ActorImpl* issuer);
26 void unlock(actor::ActorImpl* issuer);
31 actor::ActorImpl* owner_ = nullptr;
32 // List of sleeping actors:
33 actor::SynchroList sleeping_;
35 // boost::intrusive_ptr<Mutex> support:
36 friend void intrusive_ptr_add_ref(MutexImpl* mutex)
38 XBT_ATTRIB_UNUSED auto previous = mutex->refcount_.fetch_add(1);
39 xbt_assert(previous != 0);
42 friend void intrusive_ptr_release(MutexImpl* mutex)
44 if (mutex->refcount_.fetch_sub(1) == 1)
48 s4u::Mutex& mutex() { return piface_; }
51 std::atomic_int_fast32_t refcount_{1};
57 #endif /* SIMIX_MUTEXIMPL_HPP */