From 6f38b6ab6e8708d502791fb1e37659046e5bb039 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Sat, 14 Jan 2017 19:11:07 +0000 Subject: Fix thread creation on Windows llvm-svn: 292022 --- libcxx/include/__threading_support | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'libcxx/include/__threading_support') diff --git a/libcxx/include/__threading_support b/libcxx/include/__threading_support index c8ce331cdc0..57decce4f45 100644 --- a/libcxx/include/__threading_support +++ b/libcxx/include/__threading_support @@ -495,25 +495,31 @@ struct __libcpp_beginthreadex_thunk_data void *__arg; }; -static inline _LIBCPP_ALWAYS_INLINE unsigned int WINAPI -__libcpp_beginthreadex_thunk(void *__data) +static inline _LIBCPP_ALWAYS_INLINE DWORD WINAPI +__libcpp_beginthreadex_thunk(void *__raw_data) { - __libcpp_beginthreadex_thunk_data data = - *reinterpret_cast<__libcpp_beginthreadex_thunk_data *>(__data); - delete reinterpret_cast<__libcpp_beginthreadex_thunk_data *>(__data); - return reinterpret_cast(data.__func(data.__arg)); + auto *__data = + static_cast<__libcpp_beginthreadex_thunk_data *>(__raw_data); + auto *__func = __data->__func; + void *__arg = __data->__arg; + delete __data; + return static_cast(reinterpret_cast(__func(__arg))); } int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *), void *__arg) { - auto *data = new __libcpp_beginthreadex_thunk_data; - data->__func = __func; - data->__arg = __arg; - - *__t = reinterpret_cast(_beginthreadex(NULL, 0, - __libcpp_beginthreadex_thunk, - data, 0, NULL)); + auto *__data = new __libcpp_beginthreadex_thunk_data; + __data->__func = __func; + __data->__arg = __arg; + + *__t = CreateThread( + nullptr, // default security attributes + 0, // default stack size + __libcpp_beginthreadex_thunk, __data, + 0, // default creation flags + nullptr // output for thread ID + ); if (*__t) return 0; return GetLastError(); -- cgit v1.2.3