# HG changeset patch # User Edouard Tisserant # Date 1695987996 -7200 # Node ID 722846bd6680cc07799ccca144453e97e9077b63 # Parent c3f4e114af38df3e2314731b1b78cdf4bc994ee1 Win32 rutime: fix PLC Stop freezing diff -r c3f4e114af38 -r 722846bd6680 targets/Win32/plc_Win32_main.c --- a/targets/Win32/plc_Win32_main.c Fri Sep 29 13:45:50 2023 +0200 +++ b/targets/Win32/plc_Win32_main.c Fri Sep 29 13:46:36 2023 +0200 @@ -35,12 +35,6 @@ (*CURRENT_TIME).tv_nsec = timetmp.millitm * 1000000; } -void PLC_timer_notify() -{ - PLC_GetTime(&__CURRENT_TIME); - __run(); -} - HANDLE PLC_timer = NULL; void PLC_SetTimer(unsigned long long next, unsigned long long period) { @@ -65,9 +59,12 @@ { PLC_shutdown = 0; while(!PLC_shutdown) { - if (WaitForSingleObject(PLC_timer, INFINITE) != WAIT_OBJECT_0) + if (WaitForSingleObject(PLC_timer, INFINITE) != WAIT_OBJECT_0){ PLC_shutdown = 1; - PLC_timer_notify(); + break; + } + PLC_GetTime(&__CURRENT_TIME); + __run(); } } @@ -172,9 +169,16 @@ int stopPLC() { + + PLC_shutdown = 1; + // force last wakeup of PLC thread + SetWaitableTimer(PLC_timer, 0, 0, NULL, NULL, 0); + // wait end of PLC thread + WaitForSingleObject(PLC_thread, INFINITE); + + __cleanup(); + CloseHandle(PLC_timer); - WaitForSingleObject(PLC_thread, INFINITE); - __cleanup(); CloseHandle(debug_wait_sem); CloseHandle(debug_sem); CloseHandle(python_wait_sem);