aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/atomic_ops.h
diff options
context:
space:
mode:
authorvskipin <vskipin@yandex-team.ru>2022-02-10 16:46:00 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:00 +0300
commit4d8b546b89b5afc08cf3667e176271c7ba935f33 (patch)
tree1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /util/system/atomic_ops.h
parent4e4b78bd7b67e2533da4dbb9696374a6d6068e32 (diff)
downloadydb-4d8b546b89b5afc08cf3667e176271c7ba935f33.tar.gz
Restoring authorship annotation for <vskipin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/system/atomic_ops.h')
-rw-r--r--util/system/atomic_ops.h168
1 files changed, 84 insertions, 84 deletions
diff --git a/util/system/atomic_ops.h b/util/system/atomic_ops.h
index 46a4a3a4ab..76766b4a0a 100644
--- a/util/system/atomic_ops.h
+++ b/util/system/atomic_ops.h
@@ -1,20 +1,20 @@
#pragma once
-#include <util/generic/typetraits.h>
-
-template <typename T>
-inline TAtomic* AsAtomicPtr(T volatile* target) {
- return reinterpret_cast<TAtomic*>(target);
-}
-
-template <typename T>
-inline const TAtomic* AsAtomicPtr(T const volatile* target) {
- return reinterpret_cast<const TAtomic*>(target);
-}
-
-// integral types
-
-template <typename T>
+#include <util/generic/typetraits.h>
+
+template <typename T>
+inline TAtomic* AsAtomicPtr(T volatile* target) {
+ return reinterpret_cast<TAtomic*>(target);
+}
+
+template <typename T>
+inline const TAtomic* AsAtomicPtr(T const volatile* target) {
+ return reinterpret_cast<const TAtomic*>(target);
+}
+
+// integral types
+
+template <typename T>
struct TAtomicTraits {
enum {
Castable = std::is_integral<T>::value && sizeof(T) == sizeof(TAtomicBase) && !std::is_const<T>::value,
@@ -25,18 +25,18 @@ template <typename T, typename TT>
using TEnableIfCastable = std::enable_if_t<TAtomicTraits<T>::Castable, TT>;
template <typename T>
-inline TEnableIfCastable<T, T> AtomicGet(T const volatile& target) {
- return static_cast<T>(AtomicGet(*AsAtomicPtr(&target)));
+inline TEnableIfCastable<T, T> AtomicGet(T const volatile& target) {
+ return static_cast<T>(AtomicGet(*AsAtomicPtr(&target)));
}
template <typename T>
-inline TEnableIfCastable<T, void> AtomicSet(T volatile& target, TAtomicBase value) {
- AtomicSet(*AsAtomicPtr(&target), value);
+inline TEnableIfCastable<T, void> AtomicSet(T volatile& target, TAtomicBase value) {
+ AtomicSet(*AsAtomicPtr(&target), value);
}
template <typename T>
-inline TEnableIfCastable<T, T> AtomicIncrement(T volatile& target) {
- return static_cast<T>(AtomicIncrement(*AsAtomicPtr(&target)));
+inline TEnableIfCastable<T, T> AtomicIncrement(T volatile& target) {
+ return static_cast<T>(AtomicIncrement(*AsAtomicPtr(&target)));
}
template <typename T>
@@ -45,8 +45,8 @@ inline TEnableIfCastable<T, T> AtomicGetAndIncrement(T volatile& target) {
}
template <typename T>
-inline TEnableIfCastable<T, T> AtomicDecrement(T volatile& target) {
- return static_cast<T>(AtomicDecrement(*AsAtomicPtr(&target)));
+inline TEnableIfCastable<T, T> AtomicDecrement(T volatile& target) {
+ return static_cast<T>(AtomicDecrement(*AsAtomicPtr(&target)));
}
template <typename T>
@@ -55,8 +55,8 @@ inline TEnableIfCastable<T, T> AtomicGetAndDecrement(T volatile& target) {
}
template <typename T>
-inline TEnableIfCastable<T, T> AtomicAdd(T volatile& target, TAtomicBase value) {
- return static_cast<T>(AtomicAdd(*AsAtomicPtr(&target), value));
+inline TEnableIfCastable<T, T> AtomicAdd(T volatile& target, TAtomicBase value) {
+ return static_cast<T>(AtomicAdd(*AsAtomicPtr(&target), value));
}
template <typename T>
@@ -65,8 +65,8 @@ inline TEnableIfCastable<T, T> AtomicGetAndAdd(T volatile& target, TAtomicBase v
}
template <typename T>
-inline TEnableIfCastable<T, T> AtomicSub(T volatile& target, TAtomicBase value) {
- return static_cast<T>(AtomicSub(*AsAtomicPtr(&target), value));
+inline TEnableIfCastable<T, T> AtomicSub(T volatile& target, TAtomicBase value) {
+ return static_cast<T>(AtomicSub(*AsAtomicPtr(&target), value));
}
template <typename T>
@@ -75,12 +75,12 @@ inline TEnableIfCastable<T, T> AtomicGetAndSub(T volatile& target, TAtomicBase v
}
template <typename T>
-inline TEnableIfCastable<T, T> AtomicSwap(T volatile* target, TAtomicBase exchange) {
- return static_cast<T>(AtomicSwap(AsAtomicPtr(target), exchange));
+inline TEnableIfCastable<T, T> AtomicSwap(T volatile* target, TAtomicBase exchange) {
+ return static_cast<T>(AtomicSwap(AsAtomicPtr(target), exchange));
}
template <typename T>
-inline TEnableIfCastable<T, bool> AtomicCas(T volatile* target, TAtomicBase exchange, TAtomicBase compare) {
+inline TEnableIfCastable<T, bool> AtomicCas(T volatile* target, TAtomicBase exchange, TAtomicBase compare) {
return AtomicCas(AsAtomicPtr(target), exchange, compare);
}
@@ -90,12 +90,12 @@ inline TEnableIfCastable<T, T> AtomicGetAndCas(T volatile* target, TAtomicBase e
}
template <typename T>
-inline TEnableIfCastable<T, bool> AtomicTryLock(T volatile* target) {
+inline TEnableIfCastable<T, bool> AtomicTryLock(T volatile* target) {
return AtomicTryLock(AsAtomicPtr(target));
}
template <typename T>
-inline TEnableIfCastable<T, bool> AtomicTryAndTryLock(T volatile* target) {
+inline TEnableIfCastable<T, bool> AtomicTryAndTryLock(T volatile* target) {
return AtomicTryAndTryLock(AsAtomicPtr(target));
}
@@ -103,85 +103,85 @@ template <typename T>
inline TEnableIfCastable<T, void> AtomicUnlock(T volatile* target) {
AtomicUnlock(AsAtomicPtr(target));
}
-
-template <typename T>
-inline TEnableIfCastable<T, T> AtomicOr(T volatile& target, TAtomicBase value) {
- return static_cast<T>(AtomicOr(*AsAtomicPtr(&target), value));
-}
-
-template <typename T>
-inline TEnableIfCastable<T, T> AtomicAnd(T volatile& target, TAtomicBase value) {
- return static_cast<T>(AtomicAnd(*AsAtomicPtr(&target), value));
-}
-
+
+template <typename T>
+inline TEnableIfCastable<T, T> AtomicOr(T volatile& target, TAtomicBase value) {
+ return static_cast<T>(AtomicOr(*AsAtomicPtr(&target), value));
+}
+
+template <typename T>
+inline TEnableIfCastable<T, T> AtomicAnd(T volatile& target, TAtomicBase value) {
+ return static_cast<T>(AtomicAnd(*AsAtomicPtr(&target), value));
+}
+
template <typename T>
inline TEnableIfCastable<T, T> AtomicXor(T volatile& target, TAtomicBase value) {
return static_cast<T>(AtomicXor(*AsAtomicPtr(&target), value));
}
-// pointer types
-
-template <typename T>
-inline T* AtomicGet(T* const volatile& target) {
- return reinterpret_cast<T*>(AtomicGet(*AsAtomicPtr(&target)));
-}
-
-template <typename T>
-inline void AtomicSet(T* volatile& target, T* value) {
- AtomicSet(*AsAtomicPtr(&target), reinterpret_cast<TAtomicBase>(value));
-}
-
+// pointer types
+
+template <typename T>
+inline T* AtomicGet(T* const volatile& target) {
+ return reinterpret_cast<T*>(AtomicGet(*AsAtomicPtr(&target)));
+}
+
+template <typename T>
+inline void AtomicSet(T* volatile& target, T* value) {
+ AtomicSet(*AsAtomicPtr(&target), reinterpret_cast<TAtomicBase>(value));
+}
+
using TNullPtr = decltype(nullptr);
-template <typename T>
+template <typename T>
inline void AtomicSet(T* volatile& target, TNullPtr) {
- AtomicSet(*AsAtomicPtr(&target), 0);
-}
-
-template <typename T>
-inline T* AtomicSwap(T* volatile* target, T* exchange) {
- return reinterpret_cast<T*>(AtomicSwap(AsAtomicPtr(target), reinterpret_cast<TAtomicBase>(exchange)));
-}
-
-template <typename T>
+ AtomicSet(*AsAtomicPtr(&target), 0);
+}
+
+template <typename T>
+inline T* AtomicSwap(T* volatile* target, T* exchange) {
+ return reinterpret_cast<T*>(AtomicSwap(AsAtomicPtr(target), reinterpret_cast<TAtomicBase>(exchange)));
+}
+
+template <typename T>
inline T* AtomicSwap(T* volatile* target, TNullPtr) {
- return reinterpret_cast<T*>(AtomicSwap(AsAtomicPtr(target), 0));
-}
-
-template <typename T>
-inline bool AtomicCas(T* volatile* target, T* exchange, T* compare) {
- return AtomicCas(AsAtomicPtr(target), reinterpret_cast<TAtomicBase>(exchange), reinterpret_cast<TAtomicBase>(compare));
-}
-
-template <typename T>
+ return reinterpret_cast<T*>(AtomicSwap(AsAtomicPtr(target), 0));
+}
+
+template <typename T>
+inline bool AtomicCas(T* volatile* target, T* exchange, T* compare) {
+ return AtomicCas(AsAtomicPtr(target), reinterpret_cast<TAtomicBase>(exchange), reinterpret_cast<TAtomicBase>(compare));
+}
+
+template <typename T>
inline T* AtomicGetAndCas(T* volatile* target, T* exchange, T* compare) {
return reinterpret_cast<T*>(AtomicGetAndCas(AsAtomicPtr(target), reinterpret_cast<TAtomicBase>(exchange), reinterpret_cast<TAtomicBase>(compare)));
}
template <typename T>
inline bool AtomicCas(T* volatile* target, T* exchange, TNullPtr) {
- return AtomicCas(AsAtomicPtr(target), reinterpret_cast<TAtomicBase>(exchange), 0);
-}
-
-template <typename T>
+ return AtomicCas(AsAtomicPtr(target), reinterpret_cast<TAtomicBase>(exchange), 0);
+}
+
+template <typename T>
inline T* AtomicGetAndCas(T* volatile* target, T* exchange, TNullPtr) {
return reinterpret_cast<T*>(AtomicGetAndCas(AsAtomicPtr(target), reinterpret_cast<TAtomicBase>(exchange), 0));
}
template <typename T>
inline bool AtomicCas(T* volatile* target, TNullPtr, T* compare) {
- return AtomicCas(AsAtomicPtr(target), 0, reinterpret_cast<TAtomicBase>(compare));
-}
-
-template <typename T>
+ return AtomicCas(AsAtomicPtr(target), 0, reinterpret_cast<TAtomicBase>(compare));
+}
+
+template <typename T>
inline T* AtomicGetAndCas(T* volatile* target, TNullPtr, T* compare) {
return reinterpret_cast<T*>(AtomicGetAndCas(AsAtomicPtr(target), 0, reinterpret_cast<TAtomicBase>(compare)));
}
template <typename T>
inline bool AtomicCas(T* volatile* target, TNullPtr, TNullPtr) {
- return AtomicCas(AsAtomicPtr(target), 0, 0);
-}
+ return AtomicCas(AsAtomicPtr(target), 0, 0);
+}
template <typename T>
inline T* AtomicGetAndCas(T* volatile* target, TNullPtr, TNullPtr) {