c11: Getting the macro guard of HAVE_PTHREAD in c11/threads.h to be consistence with util/u_uthread.h

The macro guard of #if defined(_WIN32) && !defined(__CYGWIN__) is comes from yohhoy's implementation
and that's not consistence with util/u_uthread.h, this caused it's hard to understand.
Now we change the behavior that's always rely on how meson detecting HAVE_PTHREAD.

So we always disable detecting of threads on Win32 as it's always included in the kernel32 library to
avoid detecting pthreads in mingw.

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18425>
This commit is contained in:
Yonggang Luo 2022-09-15 22:53:03 +08:00 committed by Marge Bot
parent 54beddb5d2
commit 399dc71a30
4 changed files with 15 additions and 8 deletions

View File

@ -1598,8 +1598,15 @@ elif with_shader_cache
error('Shader Cache requires compression')
endif
dep_thread = dependency('threads')
if dep_thread.found() and host_machine.system() != 'windows'
if host_machine.system() == 'windows'
# For MSVC and MinGW we aren't using pthreads, and dependency('threads') will add linkage
# to pthread for MinGW, so leave the dependency null_dep for Windows. For Windows linking to
# kernel32 is enough for c11/threads.h and it's already linked by meson by default
dep_thread = null_dep
else
dep_thread = dependency('threads')
endif
if dep_thread.found()
pre_args += '-DHAVE_PTHREAD'
if host_machine.system() != 'netbsd' and cc.has_function(
'pthread_setaffinity_np',

View File

@ -32,7 +32,7 @@
#ifndef HAVE_TIMESPEC_GET
#if defined(_WIN32) && !defined(__CYGWIN__)
#if defined(_WIN32) && !defined(HAVE_PTHREAD)
#include <windows.h>

View File

@ -37,7 +37,7 @@
#include <limits.h>
#include <stdlib.h>
#if defined(_WIN32) && !defined(__CYGWIN__)
#if defined(_WIN32) && !defined(HAVE_PTHREAD)
# include <io.h> /* close */
# include <process.h> /* _exit */
#elif defined(HAVE_PTHREAD)
@ -97,7 +97,7 @@ extern "C" {
typedef void (*tss_dtor_t)(void *);
typedef int (*thrd_start_t)(void *);
#if defined(_WIN32) && !defined(__CYGWIN__)
#if defined(_WIN32) && !defined(HAVE_PTHREAD)
typedef struct
{
void *Ptr;

View File

@ -49,7 +49,7 @@
#if DETECT_OS_LINUX && !defined(ANDROID)
#include <sched.h>
#elif defined(_WIN32) && !defined(__CYGWIN__)
#elif defined(_WIN32) && !defined(HAVE_PTHREAD)
#include <windows.h>
#endif
@ -93,7 +93,7 @@ util_get_current_cpu(void)
#if DETECT_OS_LINUX && !defined(ANDROID)
return sched_getcpu();
#elif defined(_WIN32) && !defined(__CYGWIN__)
#elif defined(_WIN32) && !defined(HAVE_PTHREAD)
return GetCurrentProcessorNumber();
#else
@ -188,7 +188,7 @@ util_set_thread_affinity(thrd_t thread,
}
return pthread_setaffinity_np(thread, sizeof(cpuset), &cpuset) == 0;
#elif defined(_WIN32) && !defined(__CYGWIN__)
#elif defined(_WIN32) && !defined(HAVE_PTHREAD)
DWORD_PTR m = mask[0];
if (sizeof(m) > 4 && num_mask_bits > 32)