diff --git a/common/advanced_config.cpp b/common/advanced_config.cpp index f928c814f9..0d9d746c1e 100644 --- a/common/advanced_config.cpp +++ b/common/advanced_config.cpp @@ -39,6 +39,18 @@ */ static const wxChar AdvancedConfigMask[] = wxT( "KICAD_ADVANCED_CONFIG" ); +/** + * Limits and default settings for the coroutine stack size allowed. + * Warning! Setting the stack size below the default may lead to unexplained crashes + * This configuration setting is intended for developers only. + */ +namespace AC_STACK +{ + static constexpr int min_stack = 32 * 4096; + static constexpr int default_stack = 256 * 4096; + static constexpr int max_stack = 4096 * 4096; +} + /** * List of known keys for advanced configuration options. * @@ -72,6 +84,12 @@ static const wxChar RealtimeConnectivity[] = wxT( "RealtimeConnectivity" ); */ static const wxChar AllowLegacyCanvasInGtk3[] = wxT( "AllowLegacyCanvasInGtk3" ); +/** + * Configure the coroutine stack size in bytes. This should be allocated in multiples of + * the system page size (n*4096 is generally safe) + */ +static const wxChar CoroutineStackSize[] = wxT( "CoroutineStackSize" ); + /** * Draw zones in pcbnew with the stroked outline. */ @@ -158,6 +176,7 @@ ADVANCED_CFG::ADVANCED_CFG() m_allowLegacyCanvasInGtk3 = false; m_realTimeConnectivity = true; m_forceThickOutlinesInZones = true; + m_coroutineStackSize = AC_STACK::default_stack; loadFromConfigFile(); } @@ -200,6 +219,10 @@ void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg ) configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::RealtimeConnectivity, &m_realTimeConnectivity, false ) ); + configParams.push_back( + new PARAM_CFG_INT( true, AC_KEYS::CoroutineStackSize, &m_coroutineStackSize, + AC_STACK::default_stack, AC_STACK::min_stack, AC_STACK::max_stack ) ); + configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::ForceThickZones, &m_forceThickOutlinesInZones, true ) ); diff --git a/include/advanced_config.h b/include/advanced_config.h index 75160b7d22..824e9b0539 100644 --- a/include/advanced_config.h +++ b/include/advanced_config.h @@ -84,6 +84,11 @@ public: */ bool m_forceThickOutlinesInZones; + /** + * Set the stack size for coroutines + */ + int m_coroutineStackSize; + /** * Helper to determine if legacy canvas is allowed (according to platform * and config) diff --git a/include/tool/coroutine.h b/include/tool/coroutine.h index ed7ab07680..7cd0450176 100644 --- a/include/tool/coroutine.h +++ b/include/tool/coroutine.h @@ -28,13 +28,13 @@ #include #include - #include #ifdef KICAD_USE_VALGRIND #include #endif +#include #include #include @@ -148,6 +148,7 @@ public: ,valgrind_stack( 0 ) #endif { + m_stacksize = ADVANCED_CFG::GetCfg().m_coroutineStackSize; } ~COROUTINE() @@ -304,7 +305,7 @@ private: assert( m_stack == nullptr ); - size_t stackSize = c_defaultStackSize; + size_t stackSize = m_stacksize; void* sp = nullptr; #ifndef LIBCONTEXT_HAS_OWN_STACK @@ -380,11 +381,11 @@ private: } } - static constexpr int c_defaultStackSize = 2000000; // fixme: make configurable - ///< coroutine stack std::unique_ptr m_stack; + int m_stacksize; + std::function m_func; bool m_running;