11#ifdef JPH_ENABLE_ASSERTS
14enum class EPhysicsLockTypes
19 BroadPhaseUpdate = 1 << 3,
20 ConstraintsList = 1 << 4,
21 ActiveBodiesList = 1 << 5,
35#ifdef JPH_ENABLE_ASSERTS
37 static inline void sCheckLock(PhysicsLockContext inContext, EPhysicsLockTypes inType)
39 uint32 &mutexes = sGetLockedMutexes(inContext);
40 JPH_ASSERT(
uint32(inType) > mutexes,
"A lock of same or higher priority was already taken, this can create a deadlock!");
41 mutexes = mutexes |
uint32(inType);
45 static inline void sCheckUnlock(PhysicsLockContext inContext, EPhysicsLockTypes inType)
47 uint32 &mutexes = sGetLockedMutexes(inContext);
49 mutexes = mutexes &
~uint32(inType);
53 template <
class LockType>
60 template <
class LockType>
67 template <
class LockType>
71 inMutex.lock_shared();
74 template <
class LockType>
78 inMutex.unlock_shared();
81#ifdef JPH_ENABLE_ASSERTS
86 PhysicsLockContext mContext =
nullptr;
90 static uint32 & sGetLockedMutexes(PhysicsLockContext inContext)
92 static thread_local LockData sLocks[4];
95 for (LockData &l : sLocks)
96 if (l.mContext == inContext)
97 return l.mLockedMutexes;
100 for (LockData &l : sLocks)
101 if (l.mLockedMutexes == 0)
103 l.mContext = inContext;
104 return l.mLockedMutexes;
107 JPH_ASSERT(
false,
"Too many physics systems locked at the same time!");
108 return sLocks[0].mLockedMutexes;
114template <
class LockType>
120#ifdef JPH_ENABLE_ASSERTS
121 , mContext(inContext),
135#ifdef JPH_ENABLE_ASSERTS
136 PhysicsLockContext mContext;
137 EPhysicsLockTypes mType;
142template <
class LockType>
148#ifdef JPH_ENABLE_ASSERTS
149 , mContext(inContext)
163#ifdef JPH_ENABLE_ASSERTS
164 PhysicsLockContext mContext;
165 EPhysicsLockTypes mType;
#define JPH_EXPORT
Definition Core.h:236
#define JPH_NAMESPACE_END
Definition Core.h:379
std::uint32_t uint32
Definition Core.h:449
#define JPH_NAMESPACE_BEGIN
Definition Core.h:373
#define JPH_IF_ENABLE_ASSERTS(...)
Definition IssueReporting.h:35
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
Class that contains all bodies.
Definition BodyManager.h:44
Definition BroadPhaseQuery.h:29
Class that makes another class non-copyable. Usage: Inherit from NonCopyable.
Definition NonCopyable.h:11
Definition PhysicsLock.h:33
static void sLockShared(LockType &inMutex JPH_IF_ENABLE_ASSERTS(, PhysicsLockContext inContext, EPhysicsLockTypes inType))
Definition PhysicsLock.h:68
static void sUnlock(LockType &inMutex JPH_IF_ENABLE_ASSERTS(, PhysicsLockContext inContext, EPhysicsLockTypes inType))
Definition PhysicsLock.h:61
static void sUnlockShared(LockType &inMutex JPH_IF_ENABLE_ASSERTS(, PhysicsLockContext inContext, EPhysicsLockTypes inType))
Definition PhysicsLock.h:75
static void sLock(LockType &inMutex JPH_IF_ENABLE_ASSERTS(, PhysicsLockContext inContext, EPhysicsLockTypes inType))
Definition PhysicsLock.h:54
Helper class that is similar to std::shared_lock.
Definition PhysicsLock.h:144
SharedLock(LockType &inLock JPH_IF_ENABLE_ASSERTS(, PhysicsLockContext inContext, EPhysicsLockTypes inType))
Definition PhysicsLock.h:146
~SharedLock()
Definition PhysicsLock.h:156
Helper class that is similar to std::unique_lock.
Definition PhysicsLock.h:116
UniqueLock(LockType &inLock JPH_IF_ENABLE_ASSERTS(, PhysicsLockContext inContext, EPhysicsLockTypes inType))
Definition PhysicsLock.h:118
~UniqueLock()
Definition PhysicsLock.h:128