diff options
author | nga <nga@yandex-team.ru> | 2022-02-10 16:48:09 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:09 +0300 |
commit | c2a1af049e9deca890e9923abe64fe6c59060348 (patch) | |
tree | b222e5ac2e2e98872661c51ccceee5da0d291e13 /library/cpp/messagebus/misc/atomic_box.h | |
parent | 1f553f46fb4f3c5eec631352cdd900a0709016af (diff) | |
download | ydb-c2a1af049e9deca890e9923abe64fe6c59060348.tar.gz |
Restoring authorship annotation for <nga@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/messagebus/misc/atomic_box.h')
-rw-r--r-- | library/cpp/messagebus/misc/atomic_box.h | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/library/cpp/messagebus/misc/atomic_box.h b/library/cpp/messagebus/misc/atomic_box.h index a7e83b70ab..401621f933 100644 --- a/library/cpp/messagebus/misc/atomic_box.h +++ b/library/cpp/messagebus/misc/atomic_box.h @@ -1,34 +1,34 @@ -#pragma once - +#pragma once + #include <util/system/atomic.h> -// TAtomic with human interface -template <typename T> -class TAtomicBox { -private: - union { - TAtomic Value; - // when T is enum, it is convenient to inspect its content in gdb - T ValueForDebugger; - }; - +// TAtomic with human interface +template <typename T> +class TAtomicBox { +private: + union { + TAtomic Value; + // when T is enum, it is convenient to inspect its content in gdb + T ValueForDebugger; + }; + static_assert(sizeof(T) <= sizeof(TAtomic), "expect sizeof(T) <= sizeof(TAtomic)"); -public: +public: TAtomicBox(T value = T()) : Value(value) { } - - void Set(T value) { + + void Set(T value) { AtomicSet(Value, (TAtomic)value); - } - - T Get() const { + } + + T Get() const { return (T)AtomicGet(Value); - } - - bool CompareAndSet(T expected, T set) { + } + + bool CompareAndSet(T expected, T set) { return AtomicCas(&Value, (TAtomicBase)set, (TAtomicBase)expected); - } -}; + } +}; |