aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/coroutine/engine/stack/stack.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/coroutine/engine/stack/stack.cpp
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/coroutine/engine/stack/stack.cpp')
-rw-r--r--library/cpp/coroutine/engine/stack/stack.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/library/cpp/coroutine/engine/stack/stack.cpp b/library/cpp/coroutine/engine/stack/stack.cpp
new file mode 100644
index 0000000000..e29450261d
--- /dev/null
+++ b/library/cpp/coroutine/engine/stack/stack.cpp
@@ -0,0 +1,67 @@
+#include "stack.h"
+
+#include "stack_allocator.h"
+#include "stack_guards.h"
+
+
+namespace NCoro::NStack {
+
+namespace NDetails {
+
+ TStack::TStack(void* rawMemory, void* alignedMemory, uint64_t alignedSize, const char* /*name*/)
+ : RawMemory_((char*)rawMemory)
+ , AlignedMemory_((char*)alignedMemory)
+ , Size_(alignedSize)
+ {
+ Y_ASSERT(AlignedMemory_ && RawMemory_ && Size_);
+ Y_ASSERT(!(Size_ & PageSizeMask));
+ Y_ASSERT(!((uint64_t)AlignedMemory_ & PageSizeMask));
+ }
+
+ TStack::TStack(TStack&& rhs) noexcept
+ : RawMemory_(rhs.RawMemory_)
+ , AlignedMemory_(rhs.AlignedMemory_)
+ , Size_(rhs.Size_)
+ {
+ rhs.Reset();
+ }
+
+ TStack& TStack::operator=(TStack&& rhs) noexcept {
+ std::swap(*this, rhs);
+ rhs.Reset();
+ return *this;
+ }
+
+ void TStack::Reset() noexcept {
+ Y_ASSERT(AlignedMemory_ && RawMemory_ && Size_);
+
+ RawMemory_ = nullptr;
+ AlignedMemory_ = nullptr;
+ Size_ = 0;
+ }
+
+} // namespace NDetails
+
+
+ TStackHolder::TStackHolder(NStack::IAllocator& allocator, uint32_t size, const char* name) noexcept
+ : Allocator_(allocator)
+ , Stack_(Allocator_.AllocStack(size, name))
+ {}
+
+ TStackHolder::~TStackHolder() {
+ Allocator_.FreeStack(Stack_);
+ }
+
+ TArrayRef<char> TStackHolder::Get() noexcept {
+ return Allocator_.GetStackWorkspace(Stack_.GetAlignedMemory(), Stack_.GetSize());
+ }
+
+ bool TStackHolder::LowerCanaryOk() const noexcept {
+ return Allocator_.CheckStackOverflow(Stack_.GetAlignedMemory());
+ }
+
+ bool TStackHolder::UpperCanaryOk() const noexcept {
+ return Allocator_.CheckStackOverride(Stack_.GetAlignedMemory(), Stack_.GetSize());
+ }
+
+}