summaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/actor/temp_tls_vector.h
diff options
context:
space:
mode:
authorDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/messagebus/actor/temp_tls_vector.h
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/messagebus/actor/temp_tls_vector.h')
-rw-r--r--library/cpp/messagebus/actor/temp_tls_vector.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/library/cpp/messagebus/actor/temp_tls_vector.h b/library/cpp/messagebus/actor/temp_tls_vector.h
new file mode 100644
index 00000000000..675d92f5b0b
--- /dev/null
+++ b/library/cpp/messagebus/actor/temp_tls_vector.h
@@ -0,0 +1,40 @@
+#pragma once
+
+#include "thread_extra.h"
+
+#include <util/generic/vector.h>
+#include <util/system/yassert.h>
+
+template <typename T, typename TTag = void, template <typename, class> class TVectorType = TVector>
+class TTempTlsVector {
+private:
+ struct TTagForTls {};
+
+ TVectorType<T, std::allocator<T>>* Vector;
+
+public:
+ TVectorType<T, std::allocator<T>>* GetVector() {
+ return Vector;
+ }
+
+ TTempTlsVector() {
+ Vector = FastTlsSingletonWithTag<TVectorType<T, std::allocator<T>>, TTagForTls>();
+ Y_ASSERT(Vector->empty());
+ }
+
+ ~TTempTlsVector() {
+ Clear();
+ }
+
+ void Clear() {
+ Vector->clear();
+ }
+
+ size_t Capacity() const noexcept {
+ return Vector->capacity();
+ }
+
+ void Shrink() {
+ Vector->shrink_to_fit();
+ }
+};