aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/threading/atomic
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/threading/atomic
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/threading/atomic')
-rw-r--r--library/cpp/threading/atomic/bool.cpp1
-rw-r--r--library/cpp/threading/atomic/bool.h36
-rw-r--r--library/cpp/threading/atomic/bool_ut.cpp31
-rw-r--r--library/cpp/threading/atomic/ut/ya.make9
-rw-r--r--library/cpp/threading/atomic/ya.make9
5 files changed, 86 insertions, 0 deletions
diff --git a/library/cpp/threading/atomic/bool.cpp b/library/cpp/threading/atomic/bool.cpp
new file mode 100644
index 0000000000..37917e01f1
--- /dev/null
+++ b/library/cpp/threading/atomic/bool.cpp
@@ -0,0 +1 @@
+#include "bool.h"
diff --git a/library/cpp/threading/atomic/bool.h b/library/cpp/threading/atomic/bool.h
new file mode 100644
index 0000000000..d52544e762
--- /dev/null
+++ b/library/cpp/threading/atomic/bool.h
@@ -0,0 +1,36 @@
+#pragma once
+
+#include <util/system/atomic.h>
+
+namespace NAtomic {
+ class TBool {
+ public:
+ TBool() noexcept = default;
+
+ TBool(bool val) noexcept
+ : Val_(val)
+ {
+ }
+
+ TBool(const TBool& src) noexcept {
+ AtomicSet(Val_, AtomicGet(src.Val_));
+ }
+
+ operator bool() const noexcept {
+ return AtomicGet(Val_);
+ }
+
+ const TBool& operator=(bool val) noexcept {
+ AtomicSet(Val_, val);
+ return *this;
+ }
+
+ const TBool& operator=(const TBool& src) noexcept {
+ AtomicSet(Val_, AtomicGet(src.Val_));
+ return *this;
+ }
+
+ private:
+ TAtomic Val_ = 0;
+ };
+}
diff --git a/library/cpp/threading/atomic/bool_ut.cpp b/library/cpp/threading/atomic/bool_ut.cpp
new file mode 100644
index 0000000000..9481f41d8d
--- /dev/null
+++ b/library/cpp/threading/atomic/bool_ut.cpp
@@ -0,0 +1,31 @@
+#include "bool.h"
+
+#include <library/cpp/testing/unittest/registar.h>
+
+Y_UNIT_TEST_SUITE(AtomicBool) {
+ Y_UNIT_TEST(ReadWrite) {
+ NAtomic::TBool v;
+
+ UNIT_ASSERT_VALUES_EQUAL((bool)v, false);
+
+ v = true;
+
+ UNIT_ASSERT_VALUES_EQUAL((bool)v, true);
+
+ v = false;
+
+ UNIT_ASSERT_VALUES_EQUAL((bool)v, false);
+
+ NAtomic::TBool v2;
+
+ UNIT_ASSERT(v == v2);
+
+ v2 = true;
+
+ UNIT_ASSERT(v != v2);
+
+ v = v2;
+
+ UNIT_ASSERT(v == v2);
+ }
+}
diff --git a/library/cpp/threading/atomic/ut/ya.make b/library/cpp/threading/atomic/ut/ya.make
new file mode 100644
index 0000000000..3c555685df
--- /dev/null
+++ b/library/cpp/threading/atomic/ut/ya.make
@@ -0,0 +1,9 @@
+UNITTEST_FOR(library/cpp/threading/atomic)
+
+OWNER(vmordovin)
+
+SRCS(
+ bool_ut.cpp
+)
+
+END()
diff --git a/library/cpp/threading/atomic/ya.make b/library/cpp/threading/atomic/ya.make
new file mode 100644
index 0000000000..c3a3ef8a76
--- /dev/null
+++ b/library/cpp/threading/atomic/ya.make
@@ -0,0 +1,9 @@
+LIBRARY()
+
+OWNER(vmordovin)
+
+SRCS(
+ bool.cpp
+)
+
+END()