From f4cccfec3f50668bb96d919db1354598f84739f2 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sat, 6 Feb 2016 01:13:57 +0100 Subject: [PATCH] Fixed windows runner exiting before the death of all wait threads --- src/compat/process.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/compat/process.c b/src/compat/process.c index 27d1170..19278d4 100644 --- a/src/compat/process.c +++ b/src/compat/process.c @@ -111,6 +111,10 @@ struct full_context { static TCHAR g_mapping_name[] = TEXT("WinCriterionWorker_%lu"); static struct full_context local_ctx; + +static CRITICAL_SECTION wait_sync; +static CONDITION_VARIABLE wait_cond; +static LONG volatile wait_threads; #endif #if defined(__unix__) || defined(__APPLE__) @@ -170,6 +174,10 @@ void init_proc_compat(void) { perror(0); exit(1); } +#else + InitializeConditionVariable(&wait_cond); + InitializeCriticalSection(&wait_sync); + wait_threads = 0; #endif } @@ -177,6 +185,13 @@ void free_proc_compat(void) { #ifndef VANILLA_WIN32 child_pump_running = false; pthread_join(child_pump, NULL); +#else + EnterCriticalSection(&wait_sync); + while (wait_threads > 0) + SleepConditionVariableCS(&wait_cond, &wait_sync, INFINITE); + LeaveCriticalSection(&wait_sync); + + DeleteCriticalSection(&wait_sync); #endif } @@ -213,6 +228,9 @@ static void CALLBACK handle_child_terminated(PVOID lpParameter, msg.id.pid = pid; cr_send_to_runner(&msg); + if (InterlockedDecrement(&wait_threads) == 0) + WakeConditionVariable(&wait_cond); + HANDLE whandle = wctx->wait_handle; free(lpParameter); UnregisterWaitEx(whandle, NULL); @@ -386,6 +404,7 @@ s_proc_handle *fork_process() { .proc_handle = info.hProcess, }; + InterlockedIncrement (&wait_threads); RegisterWaitForSingleObject( &wctx->wait_handle, info.hProcess,