Skip to content
Snippets Groups Projects
Commit dc302393 authored by Florian Schmaus's avatar Florian Schmaus
Browse files

Ensure that the current fiber is recycled in discardAndResume()

parent 1a0ced03
No related branches found
No related tags found
No related merge requests found
...@@ -64,5 +64,17 @@ void ContextManager::discardAndResume(Context* context) { ...@@ -64,5 +64,17 @@ void ContextManager::discardAndResume(Context* context) {
LOGD("Freeing context " << contextToFree); LOGD("Freeing context " << contextToFree);
putFreeContext(contextToFree); putFreeContext(contextToFree);
}); });
// Since we are going to discard this context, it will never reach
// the end of its dispatch loop, and hence we need to ensure that
// the fiber is recycled.
const Fiber* currentFiber = Dispatcher::currentFiber;
if (currentFiber) {
Dispatcher::recycle(currentFiber);
// Set currentFiber to nullptr to avoid double frees here.
Dispatcher::currentFiber = nullptr;
}
contextToFree->discardAndResume(context); contextToFree->discardAndResume(context);
} }
#pragma once #pragma once
#include "Common.hpp" #include "Common.hpp"
#include "Dispatcher.hpp"
#include "WsClQueue.hpp" #include "WsClQueue.hpp"
#include "Runtime.hpp" #include "Runtime.hpp"
#include "Context.hpp" #include "Context.hpp"
...@@ -17,6 +18,8 @@ private: ...@@ -17,6 +18,8 @@ private:
friend Context; friend Context;
friend Dispatcher;
public: public:
ContextManager(Runtime& runtime); ContextManager(Runtime& runtime);
......
...@@ -35,7 +35,7 @@ protected: ...@@ -35,7 +35,7 @@ protected:
return fiber->doAtomicDecrRefCount(); return fiber->doAtomicDecrRefCount();
} }
inline void recycle(const Fiber* fiber) { static inline void recycle(const Fiber* fiber) {
delete fiber; delete fiber;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment