perf(templates): optimize the performance of TAtomic::FetchFn()

This commit is contained in:
_Redstone_c_ 2023-01-07 11:10:19 +08:00
parent 4f4a351316
commit b7c3ffd0fb

View File

@ -151,7 +151,8 @@ public:
FORCEINLINE ValueType FetchFn(F&& Func, EMemoryOrder Order = EMemoryOrder::SequentiallyConsistent)
{
ValueType Temp(Load(EMemoryOrder::Relaxed));
while (!CompareExchange(Temp, InvokeResult<ValueType>(Forward<F>(Func), Temp), Order));
// We do a weak read here because we require a loop.
while (!CompareExchange(Temp, InvokeResult<ValueType>(Forward<F>(Func), Temp), Order, true));
return Temp;
}
@ -160,7 +161,8 @@ public:
FORCEINLINE ValueType FetchFn(F&& Func, EMemoryOrder Order = EMemoryOrder::SequentiallyConsistent) volatile
{
ValueType Temp(Load(EMemoryOrder::Relaxed));
while (!CompareExchange(Temp, InvokeResult<ValueType>(Forward<F>(Func), Temp), Order));
// We do a weak read here because we require a loop.
while (!CompareExchange(Temp, InvokeResult<ValueType>(Forward<F>(Func), Temp), Order, true));
return Temp;
}