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 | 1f553f46fb4f3c5eec631352cdd900a0709016af (patch) | |
tree | a231fba2c03b440becaea6c86a2702d0bfb0336e /library/cpp/messagebus/misc/atomic_box.h | |
parent | c4de7efdedc25b49cbea74bd589eecb61b55b60a (diff) | |
download | ydb-1f553f46fb4f3c5eec631352cdd900a0709016af.tar.gz |
Restoring authorship annotation for <nga@yandex-team.ru>. Commit 1 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 401621f933..a7e83b70ab 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); - } -}; + } +}; |