diff --git a/Include/auROXTL/auAtomic.hpp b/Include/auROXTL/auAtomic.hpp index 3d5b8ad..440b6c1 100644 --- a/Include/auROXTL/auAtomic.hpp +++ b/Include/auROXTL/auAtomic.hpp @@ -17,6 +17,14 @@ struct AuAtomicUtils */ static T Set(T *in, AuUInt8 offset); + /** + * @brief + * @param in + * @param orValue + * @return original value + */ + static T Or(T *in, T orValue); + /** * @brief Adds addend to in * @return updated value @@ -150,54 +158,60 @@ inline auline AuUInt16 AuAtomicUtils::Sub(AuUInt16 *in, AuUInt16 minue #if !defined(AURORA_IS_32BIT) template <> -inline auline AuUInt64 AuAtomicUtils::Set(AuUInt64 *in, AuUInt8 offset) +inline auline AuUInt64 AuAtomicUtils::Or(AuUInt64 *in, AuUInt64 orValue) { - return _InterlockedOr64(reinterpret_cast(in), AuUInt64(1) << offset); + return _InterlockedOr64(reinterpret_cast(in), orValue); } #endif template <> -inline auline AuUInt32 AuAtomicUtils::Set(AuUInt32 *in, AuUInt8 offset) +inline auline AuUInt32 AuAtomicUtils::Or(AuUInt32 *in, AuUInt32 orValue) { - return _InterlockedOr(reinterpret_cast(in), 1 << offset); + return _InterlockedOr(reinterpret_cast(in), orValue); } template <> -inline auline AuUInt16 AuAtomicUtils::Set(AuUInt16 *in, AuUInt8 offset) +inline auline AuUInt16 AuAtomicUtils::Or(AuUInt16 *in, AuUInt16 orValue) { - return _InterlockedOr16(reinterpret_cast(in), 1 << offset); + return _InterlockedOr16(reinterpret_cast(in), orValue); } #if !defined(AURORA_IS_32BIT) template <> -inline auline AuInt64 AuAtomicUtils::Set(AuInt64 *in, AuUInt8 offset) +inline auline AuInt64 AuAtomicUtils::Or(AuInt64 *in, AuInt64 orValue) { - return _InterlockedOr64(reinterpret_cast(in), AuUInt64(1) << offset); + return _InterlockedOr64(reinterpret_cast(in), orValue); } #endif template <> -inline auline AuInt32 AuAtomicUtils::Set(AuInt32 *in, AuUInt8 offset) +inline auline AuInt32 AuAtomicUtils::Or(AuInt32 *in, AuInt32 orValue) { - return _InterlockedOr(reinterpret_cast(in), 1 << offset); + return _InterlockedOr(reinterpret_cast(in), orValue); } template <> -inline auline long AuAtomicUtils::Set(long *in, AuUInt8 offset) +inline auline long AuAtomicUtils::Or(long *in, long orValue) { - return _InterlockedOr(reinterpret_cast(in), 1 << offset); + return _InterlockedOr(reinterpret_cast(in), orValue); } template <> -inline auline unsigned long AuAtomicUtils::Set(unsigned long *in, AuUInt8 offset) +inline auline unsigned long AuAtomicUtils::Or(unsigned long *in, unsigned long orValue) { - return _InterlockedOr(reinterpret_cast(in), 1 << offset); + return _InterlockedOr(reinterpret_cast(in), orValue); } template <> -inline auline AuInt16 AuAtomicUtils::Set(AuInt16 *in, AuUInt8 offset) +inline auline AuInt16 AuAtomicUtils::Or(AuInt16 *in, AuInt16 orValue) { - return _InterlockedOr16(reinterpret_cast(in), 1 << offset); + return _InterlockedOr16(reinterpret_cast(in), orValue); +} + +template +inline auline T AuAtomicUtils::Set(T *in, AuUInt8 offset) +{ + return AuAtomicUtils::Or(in, T(1) << offset); } #elif defined(AURORA_COMPILER_CLANG) || defined(AURORA_COMPILER_GCC) @@ -226,6 +240,12 @@ inline auline T AuAtomicUtils::Set(T *in, AuUInt8 offset) return __sync_fetch_and_or(in, T(1) << offset); } +template +inline auline T AuAtomicUtils::Or(T *in, T value) +{ + return __sync_fetch_and_or(in, value); +} + #endif template @@ -277,36 +297,43 @@ inline auline bool AuAtomicUtils::TestAndSet(AuInt64 *in, const AuUInt8 #endif template -auline +auline T AuAtomicSet(T *in, AuUInt8 offset) { - return AuAtomicUtils::Set(in, offset); + return AuAtomicUtils>::Set(in, offset); +} + +template +auline +T AuAtomicOr(T *in, T value) +{ + return AuAtomicUtils>::Or(in, value); } template auline T AuAtomicAdd(T *in, T addend) { - return AuAtomicUtils::Add(in, addend); + return AuAtomicUtils>::Add(in, addend); } template auline T AuAtomicSub(T *in, T minuend) { - return AuAtomicUtils::Sub(in, minuend); + return AuAtomicUtils>::Sub(in, minuend); } template auline T AuAtomicCompareExchange(T *in, T replace, T compare) { - return AuAtomicUtils::CompareExchange(in, replace, compare); + return AuAtomicUtils>::CompareExchange(in, replace, compare); } template auline bool AuAtomicTestAndSet(T *in, AuUInt8 offset) { - return AuAtomicUtils::TestAndSet(in, offset); + return AuAtomicUtils>::TestAndSet(in, offset); } \ No newline at end of file diff --git a/Include/auROXTL/auTemplateMeta.hpp b/Include/auROXTL/auTemplateMeta.hpp index eaef747..1bcd682 100644 --- a/Include/auROXTL/auTemplateMeta.hpp +++ b/Include/auROXTL/auTemplateMeta.hpp @@ -200,6 +200,21 @@ struct AuRemoveConst template using AuRemoveConst_t = typename AuRemoveConst::type; +template +struct AuRemoveVolatile +{ + typedef T type; +}; + +template +struct AuRemoveVolatile +{ + typedef T type; +}; + +template +using AuRemoveVolatile_t = typename AuRemoveVolatile::type; + template struct AuEnableIf {};