ECSTASY
All in the name
Loading...
Searching...
No Matches
SharedRecursiveMutex.hpp
Go to the documentation of this file.
1
11
12#ifndef ECSTASY_THREAD_SHAREDRECURSIVEMUTEX_HPP_
13#define ECSTASY_THREAD_SHAREDRECURSIVEMUTEX_HPP_
14
15#include <atomic>
16#include <thread>
17#include <shared_mutex>
18#include <unordered_map>
19
20namespace ecstasy::thread
21{
29 public:
37
45
59 void lock();
60
72 void lock_shared() const;
73
75 void lock() const
76 {
78 }
79
90 void unlock();
91
100 void unlock_shared() const;
101
103 void unlock() const
104 {
106 }
107
116 [[nodiscard]] constexpr const std::shared_mutex &get_shared_mutex(void) noexcept
117 {
118 return _shared_mutex;
119 }
120
132 [[nodiscard]] constexpr int get_lock_count(void) const noexcept
133 {
134 return _lock_count;
135 }
136
153 [[nodiscard]] int get_shared_lock_count(void) const noexcept;
154
166 [[nodiscard]] constexpr const std::atomic<std::thread::id> &get_owner(void) const noexcept
167 {
168 return _owner;
169 }
170
171 private:
180 [[nodiscard]] bool has_shared_lock(void) const noexcept;
181
190 };
191
192} // namespace ecstasy::thread
193
194#endif // !ECSTASY_THREAD_SHAREDRECURSIVEMUTEX_HPP_
Wrapper for std::shared_mutex allowing recursive locking by the same thread.
void unlock() const
Unlock the mutex locked with shared access.
void unlock()
Unlock the mutex locked with exclusive access.
void lock() const
Lock the mutex with shared access.
~SharedRecursiveMutex()=default
Destroy the Shared Recursive Mutex.
std::shared_mutex _shared_mutex
Internal shared mutex.
std::unordered_map< std::thread::id, int > _shared_locks
Shared lock count.
void lock_shared() const
Lock the mutex with shared access.
constexpr int get_lock_count(void) const noexcept
Get the number of recursive locks held by the current thread.
void lock()
Lock the mutex with exclusive access.
std::atomic< std::thread::id > _owner
Owner of the mutex.
void unlock_shared() const
Unlock the mutex locked with shared access.
SharedRecursiveMutex()=default
Construct a new Shared Recursive Mutex.
int get_shared_lock_count(void) const noexcept
Get the number of recursive shared locks held by the current thread.
constexpr const std::atomic< std::thread::id > & get_owner(void) const noexcept
Get the owner of the mutex.
constexpr const std::shared_mutex & get_shared_mutex(void) noexcept
Get the internal mutex.
Namespace regrouping the thread safe ecstasy symbols.
Definition include.hpp:26