MCPcopy Create free account
hub / github.com/ConorWilliams/libfork / next_stacklet

Method next_stacklet

include/libfork/core/impl/stack.hpp:138–167  ·  view source on GitHub ↗

* @brief Allocate a new stacklet with a stack of size of at least`size` and attach it to the given * stacklet chain. * * Requires that `prev` must be the top stacklet in a chain or `nullptr`. This will round size up to */

Source from the content-addressed store, hash-verified

136 * Requires that `prev` must be the top stacklet in a chain or `nullptr`. This will round size up to
137 */
138 [[nodiscard]] LF_NOINLINE static auto next_stacklet(std::size_t size, stacklet *prev) -> stacklet * {
139
140 LF_LOG("allocating a new stacklet");
141
142 LF_ASSERT(prev == nullptr || prev->is_top());
143
144 std::size_t request = impl::round_up_to_page_size(size + sizeof(stacklet));
145
146 LF_ASSERT(request >= sizeof(stacklet) + size);
147
148 stacklet *next = static_cast<stacklet *>(std::malloc(request)); // NOLINT
149
150 if (next == nullptr) {
151 LF_THROW(std::bad_alloc());
152 }
153
154 if (prev != nullptr) {
155 // Set next tidies up other next.
156 prev->set_next(next);
157 }
158
159 next->m_lo = impl::byte_cast(next) + sizeof(stacklet);
160 next->m_sp = next->m_lo;
161 next->m_hi = impl::byte_cast(next) + request;
162
163 next->m_prev = prev;
164 next->m_next = nullptr;
165
166 return next;
167 }
168
169 /**
170 * @brief Allocate an initial stacklet.

Callers

nothing calls this directly

Calls 3

round_up_to_page_sizeFunction · 0.70
is_topMethod · 0.45
set_nextMethod · 0.45

Tested by

no test coverage detected