YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
stack.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <cstddef>
6
7namespace yaclib::detail::fiber {
8
9/**
10 * Manages stack memory
11 */
12class Stack final {
13 public:
14 explicit Stack(IStackAllocator& allocator) : _allocation{allocator.Allocate()}, _allocator{&allocator} {
15 }
16
17 Stack(Stack&& that) noexcept = default;
18
19 Stack& operator=(Stack&& other) noexcept {
21 _allocator->Release(_allocation);
22 _allocation = other.GetAllocation();
23 _allocator = &other.GetAllocator();
24 new_allocation.size = 0;
25 new_allocation.start = nullptr;
26 return *this;
27 }
28
30 return _allocation;
31 }
32
34 return *_allocator;
35 }
36
38 _allocator->Release(_allocation);
39 }
40
41 private:
42 Allocation _allocation;
43 IStackAllocator* _allocator;
44};
45
46} // namespace yaclib::detail::fiber
Passed to coroutine/fiber constructor, specifies the way in which memory for Stack is Allocated and R...
virtual void Release(Allocation)=0
Manages stack memory.
Definition stack.hpp:12
IStackAllocator & GetAllocator() const noexcept
Definition stack.hpp:33
Stack & operator=(Stack &&other) noexcept
Definition stack.hpp:19
Stack(Stack &&that) noexcept=default
Stack(IStackAllocator &allocator)
Definition stack.hpp:14
Allocation & GetAllocation() noexcept
Definition stack.hpp:29
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25