[+] AuAtomicUnset

[+] AuAtomicAdd
This commit is contained in:
Reece Wilson 2023-03-22 21:21:47 +00:00
parent 9274c30834
commit 387e9c231e

View File

@ -25,6 +25,14 @@ struct AuAtomicUtils
*/
static T Or(T *in, T orValue);
/**
* @brief
* @param in
* @param andValue
* @return original value
*/
static T And(T *in, T andValue);
/**
* @brief Adds addend to in
* @return updated value
@ -226,6 +234,59 @@ inline auline T AuAtomicUtils<T>::Set(T *in, AuUInt8 offset)
return AuAtomicUtils<T>::Or(in, T(1) << offset);
}
#if !defined(AURORA_IS_32BIT)
template <>
inline auline AuUInt64 AuAtomicUtils<AuUInt64>::And(AuUInt64 *in, AuUInt64 AndValue)
{
return _InterlockedAnd64(reinterpret_cast<long long volatile *>(in), AndValue);
}
#endif
template <>
inline auline AuUInt32 AuAtomicUtils<AuUInt32>::And(AuUInt32 *in, AuUInt32 AndValue)
{
return _InterlockedAnd(reinterpret_cast<long volatile *>(in), AndValue);
}
template <>
inline auline AuUInt16 AuAtomicUtils<AuUInt16>::And(AuUInt16 *in, AuUInt16 AndValue)
{
return _InterlockedAnd16(reinterpret_cast<short volatile *>(in), AndValue);
}
#if !defined(AURORA_IS_32BIT)
template <>
inline auline AuInt64 AuAtomicUtils<AuInt64>::And(AuInt64 *in, AuInt64 AndValue)
{
return _InterlockedAnd64(reinterpret_cast<long long volatile *>(in), AndValue);
}
#endif
template <>
inline auline AuInt32 AuAtomicUtils<AuInt32>::And(AuInt32 *in, AuInt32 AndValue)
{
return _InterlockedAnd(reinterpret_cast<long volatile *>(in), AndValue);
}
template <>
inline auline long AuAtomicUtils<long>::And(long *in, long AndValue)
{
return _InterlockedAnd(reinterpret_cast<long volatile *>(in), AndValue);
}
template <>
inline auline unsigned long AuAtomicUtils<unsigned long>::And(unsigned long *in, unsigned long AndValue)
{
return _InterlockedAnd(reinterpret_cast<long volatile *>(in), AndValue);
}
template <>
inline auline AuInt16 AuAtomicUtils<AuInt16>::And(AuInt16 *in, AuInt16 AndValue)
{
return _InterlockedAnd16(reinterpret_cast<short volatile *>(in), AndValue);
}
#elif defined(AURORA_COMPILER_CLANG) || defined(AURORA_COMPILER_GCC)
template <class T>
@ -258,6 +319,12 @@ inline auline T AuAtomicUtils<T>::Or(T *in, T value)
return __sync_fetch_and_or(in, value);
}
template <class T>
inline auline T AuAtomicUtils<T>::And(T *in, T value)
{
return __sync_fetch_and_and(in, value);
}
#endif
template <class T>
@ -315,6 +382,13 @@ T AuAtomicSet(T *in, AuUInt8 offset)
return AuAtomicUtils<T>::Set(in, offset);
}
template <class T>
auline
bool AuAtomicUnset(T *in, AuUInt8 offset)
{
return AuAtomicUtils<T>::And(in, ~(1u << AuUInt32(offset))) != 0;
}
template <class T>
auline
T AuAtomicOr(T *in, T value)
@ -322,6 +396,13 @@ T AuAtomicOr(T *in, T value)
return AuAtomicUtils<T>::Or(in, value);
}
template <class T>
auline
T AuAtomicAnd(T *in, T value)
{
return AuAtomicUtils<T>::And(in, value);
}
template <class T>
auline
T AuAtomicAdd(T *in, T addend)