diff --git a/emper/Context.hpp b/emper/Context.hpp index ec4bb37f3f09ff512555719c9302f272a58321d1..890413b07b6870ce7f4414bcba825f2996fd64be 100644 --- a/emper/Context.hpp +++ b/emper/Context.hpp @@ -106,6 +106,14 @@ class EMPER_CONTEXT_ALIGNAS Context : Logger<LogSubsystem::C> { static auto calcBos(char* context) -> void*; auto calcBos() -> void*; + /* + * Used by ContextManager to re-initialize a cached unused context. + */ + inline void reinit() { + currentFiber = nullptr; + savedStackpointer = const_cast<void*>(alphaFunctionIpLocation); + } + public: Context(func_t mainFunction); diff --git a/emper/ContextManager.cpp b/emper/ContextManager.cpp index 7d99c1aac323436be172dea05237b517cebdc56c..49bb1b06892d50850de18cbfca86c33d35d32282 100644 --- a/emper/ContextManager.cpp +++ b/emper/ContextManager.cpp @@ -31,6 +31,7 @@ auto ContextManager::getFreeContext() -> Context* { } auto* context = static_cast<Context*>(memory); + context->reinit(); if constexpr (emper::STATS_STACK_USAGE == emper::StatsStackUsage::accurate) { // If we want accurate stack-usage stats, then we need to re-mark // the stack if we got the memory from the memory manager but if