From 151b4e4e5eff4f0704a6dcf7ec9835c6a5fb1381 Mon Sep 17 00:00:00 2001 From: Tomasz Wlostowski Date: Wed, 22 Jul 2020 15:39:04 +0200 Subject: [PATCH] libcontext: clean up own's shit when coroutine call is over (MSVC only) --- include/tool/coroutine.h | 11 ++++++++++ thirdparty/libcontext/libcontext.cpp | 33 ++++++++++++++++++++++++++++ thirdparty/libcontext/libcontext.h | 1 + 3 files changed, 45 insertions(+) diff --git a/include/tool/coroutine.h b/include/tool/coroutine.h index 2fc124d819..50f46535c4 100644 --- a/include/tool/coroutine.h +++ b/include/tool/coroutine.h @@ -92,6 +92,13 @@ private: { } + ~CALL_CONTEXT() + { + if ( m_mainStackContext ) + libcontext::release_fcontext( *m_mainStackContext ); + } + + void SetMainStack( CONTEXT_T* aStack ) { m_mainStackContext = aStack; @@ -161,6 +168,10 @@ public: #ifdef KICAD_USE_VALGRIND VALGRIND_STACK_DEREGISTER( valgrind_stack ); #endif + if(m_caller) + libcontext::release_fcontext( m_caller ); + if(m_callee) + libcontext::release_fcontext( m_callee ); } public: diff --git a/thirdparty/libcontext/libcontext.cpp b/thirdparty/libcontext/libcontext.cpp index bdbec3270e..9699c77117 100644 --- a/thirdparty/libcontext/libcontext.cpp +++ b/thirdparty/libcontext/libcontext.cpp @@ -1305,10 +1305,43 @@ intptr_t LIBCONTEXT_CALL_CONVENTION jump_fcontext(fcontext_t* ofc, fcontext_t nf return fiberParams[*ofc].outValue; } + +void LIBCONTEXT_CALL_CONVENTION release_fcontext( fcontext_t ctx ) +{ + if( fiberParams.find( ctx ) != fiberParams.end() ) + { + fiberParams.erase( ctx ); + } +} + + }; // namespace libcontext #ifdef __cplusplus }; #endif +#else // defined(LIBCONTEXT_PLATFORM_msvc_x86_64) || defined(LIBCONTEXT_PLATFORM_msvc_i386) + +#warning nowindows + +#ifdef __cplusplus +extern "C" { #endif + +namespace libcontext +{ + +void LIBCONTEXT_CALL_CONVENTION release_fcontext( fcontext_t ctx ) +{ + // do nothing... +} + +}; // namespace libcontext + +#ifdef __cplusplus +}; +#endif // defined(LIBCONTEXT_PLATFORM_msvc_x86_64) || defined(LIBCONTEXT_PLATFORM_msvc_i386) + +#endif + diff --git a/thirdparty/libcontext/libcontext.h b/thirdparty/libcontext/libcontext.h index 2154f84a2e..e2a903ce18 100644 --- a/thirdparty/libcontext/libcontext.h +++ b/thirdparty/libcontext/libcontext.h @@ -102,6 +102,7 @@ typedef void* fcontext_t; extern "C" { #endif +void LIBCONTEXT_CALL_CONVENTION release_fcontext( fcontext_t ctx ); intptr_t LIBCONTEXT_CALL_CONVENTION jump_fcontext( fcontext_t* ofc, fcontext_t nfc, intptr_t vp, bool preserve_fpu = true );