31 return !!(State.load(std::memory_order_relaxed) & IsLockedFlag);
36 uint32 Expected = State.load(std::memory_order_relaxed);
37 return !(Expected & (IsLockedFlag | SharedLockCountMask)) &&
38 State.compare_exchange_strong(Expected, Expected | IsLockedFlag,
39 std::memory_order_acquire, std::memory_order_relaxed);
45 if (
LIKELY(State.compare_exchange_weak(Expected, IsLockedFlag, std::memory_order_acquire, std::memory_order_relaxed)))
55 uint32 LastState = State.fetch_sub(IsLockedFlag, std::memory_order_release);
57 if (
LIKELY(!(
LastState & (MayHaveWaitingLockFlag | MayHaveWaitingSharedLockFlag))))
66 return !!(State.load(std::memory_order_relaxed) & SharedLockCountMask);
71 uint32 Expected = State.load(std::memory_order_relaxed);
72 while (
LIKELY(!(Expected & (IsLockedFlag | MayHaveWaitingLockFlag))))
74 if (
LIKELY(State.compare_exchange_weak(Expected, Expected + (1 << SharedLockCountShift),
75 std::memory_order_acquire, std::memory_order_relaxed)))
85 uint32 Expected = State.load(std::memory_order_relaxed);
86 if (
LIKELY(!(Expected & (IsLockedFlag | MayHaveWaitingLockFlag)) &&
87 State.compare_exchange_weak(Expected, Expected + (1 << SharedLockCountShift),
88 std::memory_order_acquire, std::memory_order_relaxed)))
98 const uint32 LastState = State.fetch_sub(1 << SharedLockCountShift, std::memory_order_release);
100 constexpr uint32 WakeState = MayHaveWaitingLockFlag | (1 << SharedLockCountShift);
110 UE_API void LockSharedSlow();
111 UE_API void WakeWaitingThread();
114 const void* GetSharedLockAddress()
const;
118 static constexpr uint32 IsLockedFlag = 1 << 0;
119 static constexpr uint32 MayHaveWaitingLockFlag = 1 << 1;
120 static constexpr uint32 MayHaveWaitingSharedLockFlag = 1 << 2;
121 static constexpr uint32 SharedLockCountShift = 3;
122 static constexpr uint32 SharedLockCountMask = 0xffff'fff8;
124 std::atomic<uint32> State = 0;
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define LIKELY(x)
Definition CityHash.cpp:107
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UE_API
Definition SColorGradingComponentViewer.h:12
Definition SharedMutex.h:22
bool IsLockShared() const
Definition SharedMutex.h:64
void LockShared()
Definition SharedMutex.h:83
bool TryLock()
Definition SharedMutex.h:34
bool IsLocked() const
Definition SharedMutex.h:29
FSharedMutex(const FSharedMutex &)=delete
void Lock()
Definition SharedMutex.h:42
void Unlock()
Definition SharedMutex.h:52
constexpr FSharedMutex()=default
void UnlockShared()
Definition SharedMutex.h:95
bool TryLockShared()
Definition SharedMutex.h:69
FSharedMutex & operator=(const FSharedMutex &)=delete
Definition AdvancedWidgetsModule.cpp:13