diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/coroutine/engine/stack/stack_pool.h | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/coroutine/engine/stack/stack_pool.h')
-rw-r--r-- | library/cpp/coroutine/engine/stack/stack_pool.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/library/cpp/coroutine/engine/stack/stack_pool.h b/library/cpp/coroutine/engine/stack/stack_pool.h new file mode 100644 index 0000000000..27a8e9394b --- /dev/null +++ b/library/cpp/coroutine/engine/stack/stack_pool.h @@ -0,0 +1,54 @@ +#pragma once + +#include "stack.h" +#include "stack_common.h" + +#include <util/generic/noncopyable.h> +#include <util/generic/ptr.h> +#include <util/generic/vector.h> + + +namespace NCoro::NStack { + + class IGuard; + class TStorage; + struct TPoolAllocatorSettings; + + template<typename TGuard> + class TPool final : private TMoveOnly { + struct TMemory { + char* Raw = nullptr; + char* Aligned = nullptr; // points to aligned memory, which includes space for first page guard + }; + public: + TPool(uint64_t stackSize, const TPoolAllocatorSettings& settings, const TGuard& guard); + TPool(TPool&& other) noexcept; + ~TPool(); + + NDetails::TStack AllocStack(const char* name); + void FreeStack(NDetails::TStack& stack); + + uint64_t GetReleasedSize() const noexcept; + uint64_t GetFullSize() const noexcept; + uint64_t GetNumOfAllocated() const noexcept { return NumOfAllocated_; } + + private: + void AllocNewMemoryChunk(); + bool IsSmallStack() const noexcept; + bool IsStackFromThisPool(const NDetails::TStack& stack) const noexcept; + NDetails::TStack AllocNewStack(const char* name); + + private: + const uint64_t StackSize_ = 0; + uint64_t RssPagesToKeep_ = 0; + const TGuard& Guard_; + TVector<TMemory> Memory_; // memory chunks + THolder<TStorage> Storage_; + char* NextToAlloc_ = nullptr; // points to next available stack in the last memory chunk + const uint64_t ChunkSize_ = 0; + uint64_t NumOfAllocated_ = 0; + }; + +} + +#include "stack_pool.inl" |