10#ifndef MCRL2_UTILITIES_DETAIL_SHARED_MUTEX_H
11#define MCRL2_UTILITIES_DETAIL_SHARED_MUTEX_H
91 std::vector<shared_mutex*>
other;
100 std::lock_guard guard(
mutex);
107 std::lock_guard guard(
mutex);
109 assert(it !=
other.end());
190 mutex->set_forbidden(
true);
199 mutex->wait_for_busy();
240 mutex->set_forbidden(
false);
281 m_busy_flag.store(
false, std::memory_order_release);
An exclusive lock guard for the shared_mutex.
void unlock()
Unlocks the acquired shared guard explicitly. Otherwise, performed in destructor.
lock_guard(shared_mutex &mutex)
This is simply an exclusive lock based on the standard library with the ability to perform no locks w...
Inherit from this class to prevent it from being copyable.
A shared lock guard for the shared_mutex.
void lock_shared()
Locks the guard again explicitly.
shared_guard(shared_mutex &mutex)
void unlock_shared()
Unlocks the acquired shared guard explicitly. Otherwise, performed in destructor.
bool is_shared_locked() const
std::atomic< bool > m_forbidden_flag
std::atomic< bool > m_busy_flag
A boolean flag indicating whether this thread is working inside the global aterm pool.
shared_mutex(shared_mutex &&other)
void wait_for_busy() const
Waits for the busy flag to become false.
shared_mutex(const shared_mutex &other)
The copy/move constructor/assignment should not be called while any lock_guard or shared_guard is ali...
friend class shared_mutex_pool
friend class shared_guard
std::size_t m_lock_depth
It can happen that un/lock_shared calls are nested, so keep track of the nesting depth and only actua...
std::shared_ptr< shared_mutex_data > m_shared
shared_guard lock_shared()
shared_mutex & operator=(const shared_mutex &other)
shared_mutex & operator=(shared_mutex &&other)
void set_forbidden(bool value)
static constexpr bool GlobalThreadSafe
Enables thread safety for the whole toolset.
std::mutex mutex
Mutex for adding/removing shared_guards.
void unregister_mutex(shared_mutex *shared_mutex)
void register_mutex(shared_mutex *shared_mutex)
Adds a shared mutex to the data.
std::vector< shared_mutex * > other
The list of other mutexes.