From 3296761693251905c2b1eceb193705987d35dda6 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Thu, 7 Oct 2021 23:14:16 -0600 Subject: [PATCH] threads: fix calling convention error (affecting my win32 VS build) --- common/threads.cc | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/common/threads.cc b/common/threads.cc index b6b384a0..59acc257 100644 --- a/common/threads.cc +++ b/common/threads.cc @@ -112,6 +112,20 @@ ThreadUnlock(void) LeaveCriticalSection(&crit); } +using functype = void *(*)(void *); + +struct threadInfo { + functype func; + void *arg; +}; + +// necessary for calling convention reasons +DWORD WINAPI ThreadWrapper(LPVOID lpParam) { + threadInfo* info = (threadInfo*)lpParam; + info->func(info->arg); + return 0; +} + /* * ============= * RunThreadsOn @@ -134,14 +148,18 @@ RunThreadsOn(int start, int workcnt, void *(func)(void *), void *arg) if (!threadid || !threadhandle) Error("Failed to allocate memory for threads"); + threadInfo info; + info.func = func; + info.arg = arg; + /* run threads in parallel */ InitializeCriticalSection(&crit); threads_active = true; for (i = 0; i < numthreads; i++) { threadhandle[i] = CreateThread(NULL, 0, - (LPTHREAD_START_ROUTINE)func, - (LPVOID)arg, + ThreadWrapper, + (LPVOID)&info, 0, &threadid[i]); }