From f97ba1f95d5f5cb3ab1cd0aa22e383e9d77aabde Mon Sep 17 00:00:00 2001 From: Yonggang Luo Date: Sat, 13 Aug 2022 12:29:29 +0800 Subject: [PATCH] c11: #include when the os/platform provide it Closes #6964 CC: mesa-stable Signed-off-by: Yonggang Luo Reviewed-by: Jesse Natalie Part-of: --- meson.build | 9 +++++++++ src/c11/impl/meson.build | 4 +++- src/c11/threads.h | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index f5383757acc..ca80357172e 100644 --- a/meson.build +++ b/meson.build @@ -1449,6 +1449,15 @@ if cc.has_header_symbol('time.h', 'struct timespec') pre_args += '-DHAVE_STRUCT_TIMESPEC' endif +with_c11_threads = false +if cc.has_function('thrd_create', prefix: '#include ') + if with_platform_android + # Current only Android's c11 are verified + pre_args += '-DHAVE_THRD_CREATE' + with_c11_threads = true + endif +endif + if cc.has_header_symbol('errno.h', 'program_invocation_name', args : '-D_GNU_SOURCE') pre_args += '-DHAVE_PROGRAM_INVOCATION_NAME' diff --git a/src/c11/impl/meson.build b/src/c11/impl/meson.build index c12f0e9eff9..11ef6cf764b 100644 --- a/src/c11/impl/meson.build +++ b/src/c11/impl/meson.build @@ -22,7 +22,9 @@ files_mesa_util_c11 = files( 'time.c', ) -if host_machine.system() == 'windows' +if with_c11_threads + # no need implement c11 threads +elif host_machine.system() == 'windows' files_mesa_util_c11 += 'threads_win32.c' files_mesa_util_c11 += 'threads_win32_tls_callback.cpp' else diff --git a/src/c11/threads.h b/src/c11/threads.h index c091d22b5bc..146b7f5c174 100644 --- a/src/c11/threads.h +++ b/src/c11/threads.h @@ -47,6 +47,20 @@ # error Not supported on this platform. #endif +#if defined(HAVE_THRD_CREATE) +#include + +#if defined(ANDROID) +/* Currently, only Android are verified that it's thrd_t are typedef of pthread_t + * So we can define _MTX_INITIALIZER_NP to PTHREAD_MUTEX_INITIALIZER + * FIXME: temporary non-standard hack to ease transition + */ +# define _MTX_INITIALIZER_NP PTHREAD_MUTEX_INITIALIZER +#else +#error Can not define _MTX_INITIALIZER_NP properly for this platform +#endif +#else + /*---------------------------- macros ---------------------------*/ #ifndef _Thread_local @@ -185,4 +199,6 @@ int tss_set(tss_t, void *); } #endif +#endif /* HAVE_THRD_CREATE */ + #endif /* C11_THREADS_H_INCLUDED_ */