13#include <shared_mutex>
22using std::shared_mutex;
25using std::shared_lock;
26using std::unique_lock;
28#ifdef JPH_PLATFORM_BLUE
36 JPH_PLATFORM_BLUE_MUTEX_INIT(mMutex);
41 JPH_PLATFORM_BLUE_MUTEX_DESTROY(mMutex);
44 inline bool try_lock()
46 return JPH_PLATFORM_BLUE_MUTEX_TRYLOCK(mMutex);
51 JPH_PLATFORM_BLUE_MUTEX_LOCK(mMutex);
56 JPH_PLATFORM_BLUE_MUTEX_UNLOCK(mMutex);
60 JPH_PLATFORM_BLUE_MUTEX mMutex;
69 JPH_PLATFORM_BLUE_RWLOCK_INIT(mRWLock);
74 JPH_PLATFORM_BLUE_RWLOCK_DESTROY(mRWLock);
77 inline bool try_lock()
79 return JPH_PLATFORM_BLUE_RWLOCK_TRYWLOCK(mRWLock);
82 inline bool try_lock_shared()
84 return JPH_PLATFORM_BLUE_RWLOCK_TRYRLOCK(mRWLock);
89 JPH_PLATFORM_BLUE_RWLOCK_WLOCK(mRWLock);
94 JPH_PLATFORM_BLUE_RWLOCK_WUNLOCK(mRWLock);
97 inline void lock_shared()
99 JPH_PLATFORM_BLUE_RWLOCK_RLOCK(mRWLock);
102 inline void unlock_shared()
104 JPH_PLATFORM_BLUE_RWLOCK_RUNLOCK(mRWLock);
108 JPH_PLATFORM_BLUE_RWLOCK mRWLock;
119#if defined(JPH_ENABLE_ASSERTS) || defined(JPH_PROFILE_ENABLED) || defined(JPH_EXTERNAL_PROFILE)
128 JPH_ASSERT(mLockedThreadID.load(std::memory_order_relaxed) != std::this_thread::get_id());
129 if (MutexBase::try_lock())
149 JPH_ASSERT(mLockedThreadID.load(std::memory_order_relaxed) == std::this_thread::get_id());
154#ifdef JPH_ENABLE_ASSERTS
155 inline bool is_locked()
157 return mLockedThreadID.load(std::memory_order_relaxed) != thread::id();
172 JPH_ASSERT(mLockedThreadID.load(std::memory_order_relaxed) != std::this_thread::get_id());
173 if (SharedMutexBase::try_lock())
186 SharedMutexBase::lock();
193 JPH_ASSERT(mLockedThreadID.load(std::memory_order_relaxed) == std::this_thread::get_id());
195 SharedMutexBase::unlock();
198#ifdef JPH_ENABLE_ASSERTS
199 inline bool is_locked()
201 return mLockedThreadID.load(std::memory_order_relaxed) != thread::id();
207 if (!try_lock_shared())
210 SharedMutexBase::lock_shared();
#define JPH_SUPPRESS_WARNINGS_STD_BEGIN
Definition Core.h:492
#define JPH_SUPPRESS_WARNINGS_STD_END
Definition Core.h:506
#define JPH_NAMESPACE_END
Definition Core.h:487
#define JPH_NAMESPACE_BEGIN
Definition Core.h:481
#define JPH_IF_ENABLE_ASSERTS(...)
Definition IssueReporting.h:30
#define JPH_ASSERT(...)
Definition IssueReporting.h:28
shared_mutex SharedMutexBase
Definition Mutex.h:115
mutex MutexBase
Definition Mutex.h:114
#define JPH_PROFILE(...)
Definition Profiler.h:267
void unlock()
Definition Mutex.h:147
bool try_lock()
Definition Mutex.h:126
void lock()
Definition Mutex.h:137
Class that makes another class non-copyable. Usage: Inherit from NonCopyable.
Definition NonCopyable.h:11
void lock_shared()
Definition Mutex.h:205
void unlock()
Definition Mutex.h:191
void lock()
Definition Mutex.h:181
bool try_lock()
Definition Mutex.h:170