From 55f7411ba92d318fe6e4677e7da517dc26908f0d Mon Sep 17 00:00:00 2001 From: janwas Date: Mon, 21 Jun 2004 14:22:07 +0000 Subject: [PATCH] improved thread start code This was SVN commit r581. --- source/lib/sysdep/win/wposix.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/source/lib/sysdep/win/wposix.cpp b/source/lib/sysdep/win/wposix.cpp index 3926200632..db8d1a60f8 100755 --- a/source/lib/sysdep/win/wposix.cpp +++ b/source/lib/sysdep/win/wposix.cpp @@ -304,10 +304,29 @@ int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param } -int pthread_create(pthread_t* /* thread */, const void* /* attr */, void*(*func)(void*), void* arg) +struct ThreadParam { - /* can't use asm 'cause _beginthread might be a func ptr (with libc) */ - return (int)_beginthread((void(*)(void*))func, 0, arg); + void*(*func)(void*); + void* user_arg; +}; + +static unsigned __stdcall thread_start(void* arg) +{ + const ThreadParam* param = (const ThreadParam*)arg; + + param->func(param->user_arg); + return 0; +} + + +int pthread_create(pthread_t* thread, const void* attr, void*(*func)(void*), void* user_arg) +{ + UNUSED(attr); + + // can't use asm - _beginthreadex might be a func ptr (with DLL CRT) + const ThreadParam param = { func, user_arg }; + *thread = (pthread_t)_beginthreadex(0, 0, thread_start, (void*)¶m, 0, 0); + return 0; }