From c472e67b7f9a0bde62d27645d72bd83b7b09c29e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Wed, 30 Jan 2019 14:01:23 +0000 Subject: [PATCH] Rework CLR reboot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - CLR_RT_ExecutionEngine instance is now always deleted on clean-up. - Add memset to clear all major strucst on clean-up. - Remove c_NoShutdown option from Monitor_Reboot. - Remove call to Abort threads and add developer notes about what is happening in ExecutionEngine_Cleanup. Signed-off-by: José Simões --- src/CLR/Core/Execution.cpp | 12 +++++++++--- src/CLR/Include/nanoCLR_Debugging.h | 1 - targets/CMSIS-OS/ChibiOS/nanoCLR/CLRStartup.cpp | 14 +++++++++----- .../FreeRTOS/ESP32_DevKitC/nanoCLR/CLRStartup.cpp | 14 +++++++++----- targets/os/win32/nanoCLR/CLRStartup.cpp | 9 +-------- 5 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/CLR/Core/Execution.cpp b/src/CLR/Core/Execution.cpp index 2ae6d42c59..27af92a988 100644 --- a/src/CLR/Core/Execution.cpp +++ b/src/CLR/Core/Execution.cpp @@ -203,6 +203,15 @@ HRESULT CLR_RT_ExecutionEngine::DeleteInstance() void CLR_RT_ExecutionEngine::ExecutionEngine_Cleanup() { + ///////////////////////////////////////////////////////////////////////////////////////////////// + // developer notes: + // Most of the following calls are just for pure ceremony and gracefully terminating stuff, + // cleaning collections and such. + // In particular the previous existing calls to Abort threads were completely irrelevant + // because the execution engine wasn't running anymore so whatever code that is on those threads + // there to be executed wouldn't never be executed anyways. + ///////////////////////////////////////////////////////////////////////////////////////////////// + NATIVE_PROFILE_CLR_CORE(); m_fShuttingDown = true; @@ -228,9 +237,6 @@ void CLR_RT_ExecutionEngine::ExecutionEngine_Cleanup() m_timerThread = NULL; - AbortAllThreads ( m_threadsReady ); - AbortAllThreads ( m_threadsWaiting ); - ReleaseAllThreads( m_threadsReady ); ReleaseAllThreads( m_threadsWaiting ); ReleaseAllThreads( m_threadsZombie ); diff --git a/src/CLR/Include/nanoCLR_Debugging.h b/src/CLR/Include/nanoCLR_Debugging.h index a4f9c8590d..d6e5c912a5 100644 --- a/src/CLR/Include/nanoCLR_Debugging.h +++ b/src/CLR/Include/nanoCLR_Debugging.h @@ -73,7 +73,6 @@ struct CLR_DBG_Commands static const unsigned int c_EnterBootloader = 1; static const unsigned int c_ClrOnly = 2; static const unsigned int c_WaitForDebugger = 4; - static const unsigned int c_NoShutdown = 8; unsigned int m_flags; }; diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/CLRStartup.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/CLRStartup.cpp index a9691e7ce1..cd10e7508d 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/CLRStartup.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/CLRStartup.cpp @@ -246,11 +246,15 @@ struct Settings void Cleanup() { - if(!CLR_EE_REBOOT_IS(NoShutdown)) - { - // OK to delete execution engine - CLR_RT_ExecutionEngine::DeleteInstance(); - } + CLR_RT_ExecutionEngine::DeleteInstance(); + + memset( &g_CLR_RT_ExecutionEngine, 0, sizeof(g_CLR_RT_ExecutionEngine)); + memset( &g_CLR_RT_WellKnownTypes, 0, sizeof(g_CLR_RT_WellKnownTypes)); + memset( &g_CLR_RT_WellKnownMethods, 0, sizeof(g_CLR_RT_WellKnownMethods)); + memset( &g_CLR_RT_TypeSystem, 0, sizeof(g_CLR_RT_TypeSystem)); + memset( &g_CLR_RT_EventCache, 0, sizeof(g_CLR_RT_EventCache)); + memset( &g_CLR_RT_GarbageCollector, 0, sizeof(g_CLR_RT_GarbageCollector)); + memset( &g_CLR_HW_Hardware, 0, sizeof(g_CLR_HW_Hardware)); m_fInitialized = false; } diff --git a/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/CLRStartup.cpp b/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/CLRStartup.cpp index 53f0692d4e..b8834cf476 100644 --- a/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/CLRStartup.cpp +++ b/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/CLRStartup.cpp @@ -242,11 +242,15 @@ struct Settings void Cleanup() { - if(!CLR_EE_REBOOT_IS(NoShutdown)) - { - // OK to delete execution engine - CLR_RT_ExecutionEngine::DeleteInstance(); - } + CLR_RT_ExecutionEngine::DeleteInstance(); + + memset( &g_CLR_RT_ExecutionEngine, 0, sizeof(g_CLR_RT_ExecutionEngine)); + memset( &g_CLR_RT_WellKnownTypes, 0, sizeof(g_CLR_RT_WellKnownTypes)); + memset( &g_CLR_RT_WellKnownMethods, 0, sizeof(g_CLR_RT_WellKnownMethods)); + memset( &g_CLR_RT_TypeSystem, 0, sizeof(g_CLR_RT_TypeSystem)); + memset( &g_CLR_RT_EventCache, 0, sizeof(g_CLR_RT_EventCache)); + memset( &g_CLR_RT_GarbageCollector, 0, sizeof(g_CLR_RT_GarbageCollector)); + memset( &g_CLR_HW_Hardware, 0, sizeof(g_CLR_HW_Hardware)); m_fInitialized = false; } diff --git a/targets/os/win32/nanoCLR/CLRStartup.cpp b/targets/os/win32/nanoCLR/CLRStartup.cpp index 66177a99fb..7051e527ac 100644 --- a/targets/os/win32/nanoCLR/CLRStartup.cpp +++ b/targets/os/win32/nanoCLR/CLRStartup.cpp @@ -394,22 +394,15 @@ struct Settings void Cleanup() { - if(!CLR_EE_REBOOT_IS(NoShutdown)) - { - // OK to delete execution engine - CLR_RT_ExecutionEngine::DeleteInstance(); - } + CLR_RT_ExecutionEngine::DeleteInstance(); -#if defined(_WIN32) memset( &g_CLR_RT_ExecutionEngine, 0, sizeof(g_CLR_RT_ExecutionEngine)); memset( &g_CLR_RT_WellKnownTypes, 0, sizeof(g_CLR_RT_WellKnownTypes)); - memset( &g_CLR_RT_WellKnownMethods, 0, sizeof(g_CLR_RT_WellKnownMethods)); memset( &g_CLR_RT_TypeSystem, 0, sizeof(g_CLR_RT_TypeSystem)); memset( &g_CLR_RT_EventCache, 0, sizeof(g_CLR_RT_EventCache)); memset( &g_CLR_RT_GarbageCollector, 0, sizeof(g_CLR_RT_GarbageCollector)); memset( &g_CLR_HW_Hardware, 0, sizeof(g_CLR_HW_Hardware)); -#endif m_fInitialized = false; }