aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/deprecated/atomic/atomic.h
diff options
context:
space:
mode:
authoreeight <eeight@yandex-team.ru>2022-06-15 23:20:13 +0300
committereeight <eeight@yandex-team.ru>2022-06-15 23:20:13 +0300
commit9321bf2b0be068375c8771de6edebbde8a0b41c4 (patch)
tree6b5853712f5cec51b1bb5b90b3046db5a2ae5e75 /library/cpp/deprecated/atomic/atomic.h
parent816bd0a9d59c9bdffcc2ca7fc652b016486eac2d (diff)
downloadydb-9321bf2b0be068375c8771de6edebbde8a0b41c4.tar.gz
IGNIETFERRO-1922 Move atomics from util to library/cpp/deprecated
ref:0c3b0edd3284567c45ec77e57166274f3cfed8c7
Diffstat (limited to 'library/cpp/deprecated/atomic/atomic.h')
-rw-r--r--library/cpp/deprecated/atomic/atomic.h50
1 files changed, 49 insertions, 1 deletions
diff --git a/library/cpp/deprecated/atomic/atomic.h b/library/cpp/deprecated/atomic/atomic.h
index d104ff834d..b376f34efa 100644
--- a/library/cpp/deprecated/atomic/atomic.h
+++ b/library/cpp/deprecated/atomic/atomic.h
@@ -1,3 +1,51 @@
#pragma once
-#include <util/system/atomic.h>
+#include <util/system/defaults.h>
+
+using TAtomicBase = intptr_t;
+using TAtomic = volatile TAtomicBase;
+
+#if defined(__GNUC__)
+ #include "atomic_gcc.h"
+#elif defined(_MSC_VER)
+ #include "atomic_win.h"
+#else
+ #error unsupported platform
+#endif
+
+#if !defined(ATOMIC_COMPILER_BARRIER)
+ #define ATOMIC_COMPILER_BARRIER()
+#endif
+
+static inline TAtomicBase AtomicSub(TAtomic& a, TAtomicBase v) {
+ return AtomicAdd(a, -v);
+}
+
+static inline TAtomicBase AtomicGetAndSub(TAtomic& a, TAtomicBase v) {
+ return AtomicGetAndAdd(a, -v);
+}
+
+#if defined(USE_GENERIC_SETGET)
+static inline TAtomicBase AtomicGet(const TAtomic& a) {
+ return a;
+}
+
+static inline void AtomicSet(TAtomic& a, TAtomicBase v) {
+ a = v;
+}
+#endif
+
+static inline bool AtomicTryLock(TAtomic* a) {
+ return AtomicCas(a, 1, 0);
+}
+
+static inline bool AtomicTryAndTryLock(TAtomic* a) {
+ return (AtomicGet(*a) == 0) && AtomicTryLock(a);
+}
+
+static inline void AtomicUnlock(TAtomic* a) {
+ ATOMIC_COMPILER_BARRIER();
+ AtomicSet(*a, 0);
+}
+
+#include "atomic_ops.h"