aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/futex_like.h
diff options
context:
space:
mode:
authornga <nga@yandex-team.ru>2022-02-10 16:48:09 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:09 +0300
commit1f553f46fb4f3c5eec631352cdd900a0709016af (patch)
treea231fba2c03b440becaea6c86a2702d0bfb0336e /library/cpp/messagebus/futex_like.h
parentc4de7efdedc25b49cbea74bd589eecb61b55b60a (diff)
downloadydb-1f553f46fb4f3c5eec631352cdd900a0709016af.tar.gz
Restoring authorship annotation for <nga@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/messagebus/futex_like.h')
-rw-r--r--library/cpp/messagebus/futex_like.h162
1 files changed, 81 insertions, 81 deletions
diff --git a/library/cpp/messagebus/futex_like.h b/library/cpp/messagebus/futex_like.h
index 31d60c60f1..d4ac486caf 100644
--- a/library/cpp/messagebus/futex_like.h
+++ b/library/cpp/messagebus/futex_like.h
@@ -1,86 +1,86 @@
-#pragma once
-
+#pragma once
+
#include <util/system/condvar.h>
#include <util/system/mutex.h>
-#include <util/system/platform.h>
-
-class TFutexLike {
-private:
-#ifdef _linux_
- int Value;
-#else
- TAtomic Value;
- TMutex Mutex;
- TCondVar CondVar;
-#endif
-
-public:
- TFutexLike()
- : Value(0)
+#include <util/system/platform.h>
+
+class TFutexLike {
+private:
+#ifdef _linux_
+ int Value;
+#else
+ TAtomic Value;
+ TMutex Mutex;
+ TCondVar CondVar;
+#endif
+
+public:
+ TFutexLike()
+ : Value(0)
{
}
-
- int AddAndGet(int add) {
-#ifdef _linux_
- //return __atomic_add_fetch(&Value, add, __ATOMIC_SEQ_CST);
- return __sync_add_and_fetch(&Value, add);
-#else
- return AtomicAdd(Value, add);
-#endif
- }
-
- int GetAndAdd(int add) {
- return AddAndGet(add) - add;
- }
-
-// until we have modern GCC
-#if 0
- int GetAndSet(int newValue) {
-#ifdef _linux_
- return __atomic_exchange_n(&Value, newValue, __ATOMIC_SEQ_CST);
-#else
+
+ int AddAndGet(int add) {
+#ifdef _linux_
+ //return __atomic_add_fetch(&Value, add, __ATOMIC_SEQ_CST);
+ return __sync_add_and_fetch(&Value, add);
+#else
+ return AtomicAdd(Value, add);
+#endif
+ }
+
+ int GetAndAdd(int add) {
+ return AddAndGet(add) - add;
+ }
+
+// until we have modern GCC
+#if 0
+ int GetAndSet(int newValue) {
+#ifdef _linux_
+ return __atomic_exchange_n(&Value, newValue, __ATOMIC_SEQ_CST);
+#else
return AtomicSwap(&Value, newValue);
-#endif
- }
-#endif
-
- int Get() {
-#ifdef _linux_
- //return __atomic_load_n(&Value, __ATOMIC_SEQ_CST);
- __sync_synchronize();
- return Value;
-#else
- return AtomicGet(Value);
-#endif
- }
-
- void Set(int newValue) {
-#ifdef _linux_
- //__atomic_store_n(&Value, newValue, __ATOMIC_SEQ_CST);
- Value = newValue;
- __sync_synchronize();
-#else
- AtomicSet(Value, newValue);
-#endif
- }
-
- int GetAndIncrement() {
- return AddAndGet(1) - 1;
- }
-
- int IncrementAndGet() {
- return AddAndGet(1);
- }
-
- int GetAndDecrement() {
- return AddAndGet(-1) + 1;
- }
-
- int DecrementAndGet() {
- return AddAndGet(-1);
- }
-
- void Wake(size_t count = Max<size_t>());
-
- void Wait(int expected);
-};
+#endif
+ }
+#endif
+
+ int Get() {
+#ifdef _linux_
+ //return __atomic_load_n(&Value, __ATOMIC_SEQ_CST);
+ __sync_synchronize();
+ return Value;
+#else
+ return AtomicGet(Value);
+#endif
+ }
+
+ void Set(int newValue) {
+#ifdef _linux_
+ //__atomic_store_n(&Value, newValue, __ATOMIC_SEQ_CST);
+ Value = newValue;
+ __sync_synchronize();
+#else
+ AtomicSet(Value, newValue);
+#endif
+ }
+
+ int GetAndIncrement() {
+ return AddAndGet(1) - 1;
+ }
+
+ int IncrementAndGet() {
+ return AddAndGet(1);
+ }
+
+ int GetAndDecrement() {
+ return AddAndGet(-1) + 1;
+ }
+
+ int DecrementAndGet() {
+ return AddAndGet(-1);
+ }
+
+ void Wake(size_t count = Max<size_t>());
+
+ void Wait(int expected);
+};