diff options
author | lukyan <lukyan@yandex-team.com> | 2023-11-07 15:55:00 +0300 |
---|---|---|
committer | lukyan <lukyan@yandex-team.com> | 2023-11-07 16:22:41 +0300 |
commit | d519b0904939506b9881fb2a5cfb1d2ec3b5e6eb (patch) | |
tree | 60d3d7aec7a065dcda1e57a3b85281aa04513673 /library | |
parent | 03ffc7e5fc8734ac44705fc1d4fbdc74a5b7accd (diff) | |
download | ydb-d519b0904939506b9881fb2a5cfb1d2ec3b5e6eb.tar.gz |
Make thread local variables fiber friendly
Diffstat (limited to 'library')
-rw-r--r-- | library/cpp/yt/misc/tls-inl.h | 18 | ||||
-rw-r--r-- | library/cpp/yt/misc/tls.h | 22 |
2 files changed, 40 insertions, 0 deletions
diff --git a/library/cpp/yt/misc/tls-inl.h b/library/cpp/yt/misc/tls-inl.h new file mode 100644 index 0000000000..51ef91517f --- /dev/null +++ b/library/cpp/yt/misc/tls-inl.h @@ -0,0 +1,18 @@ +#ifndef TLS_INL_H_ +#error "Direct inclusion of this file is not allowed, include tls.h" +// For the sake of sane code completion. +#include "tls.h" +#endif + +namespace NYT { + +//////////////////////////////////////////////////////////////////////////////// + +template <class T> +T& GetTlsRef(volatile T& arg) +{ + return const_cast<T&>(arg); +} +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT diff --git a/library/cpp/yt/misc/tls.h b/library/cpp/yt/misc/tls.h new file mode 100644 index 0000000000..d1bda8ac68 --- /dev/null +++ b/library/cpp/yt/misc/tls.h @@ -0,0 +1,22 @@ +#pragma once + +#include <util/system/compiler.h> + +// Workaround for fiber (un)friendly TLS. +// Volatile qualifier prevents caching access to thread local variables. +#define YT_THREAD_LOCAL(...) thread_local __VA_ARGS__ volatile + +namespace NYT { + +//////////////////////////////////////////////////////////////////////////////// + +template <class T> +Y_FORCE_INLINE T& GetTlsRef(volatile T& arg); + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT + +#define TLS_INL_H_ +#include "tls-inl.h" +#undef TLS_INL_H_ |