mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
Fix build when pthread_getname_np is not available
On Android _setname_ is always available but _getname_ is available only with API level >= 26. https://bugzilla.gnome.org/show_bug.cgi?id=795406
This commit is contained in:
parent
d123717947
commit
01e8396301
@ -340,6 +340,9 @@
|
||||
/* Have function pthread_setname_np with TID as argument */
|
||||
#mesondefine HAVE_PTHREAD_SETNAME_NP_WITH_TID
|
||||
|
||||
/* Have function pthread_getname_np */
|
||||
#mesondefine HAVE_PTHREAD_GETNAME_NP
|
||||
|
||||
/* Define to 1 if the system has the type `ptrdiff_t'. */
|
||||
#mesondefine HAVE_PTRDIFF_T
|
||||
|
||||
|
@ -2245,6 +2245,15 @@ AS_IF([ test x"$have_threads" = xposix], [
|
||||
AC_DEFINE(HAVE_PTHREAD_SETNAME_NP_WITH_TID,1,
|
||||
[Have function pthread_setname_np(pthread_t, const char*)])],
|
||||
[AC_MSG_RESULT(no)])
|
||||
AC_MSG_CHECKING(for pthread_getname_np(pthread_t, name, len))
|
||||
AC_LINK_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[#include <pthread.h>],
|
||||
[[char name[16]; pthread_getname_np(pthread_self(), name, 16);]])],
|
||||
[AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(HAVE_PTHREAD_GETNAME_NP,1,
|
||||
[Have function pthread_getname_np(pthread_t, name, len)])],
|
||||
[AC_MSG_RESULT(no)])
|
||||
CPPFLAGS="$glib_save_CPPFLAGS"
|
||||
])
|
||||
|
||||
|
@ -174,7 +174,7 @@ test_thread5 (void)
|
||||
static gpointer
|
||||
thread6_func (gpointer data)
|
||||
{
|
||||
#ifdef HAVE_PTHREAD_SETNAME_NP_WITH_TID
|
||||
#if defined (HAVE_PTHREAD_SETNAME_NP_WITH_TID) && defined (HAVE_PTHREAD_GETNAME_NP)
|
||||
char name[16];
|
||||
|
||||
pthread_getname_np (pthread_self(), name, 16);
|
||||
|
18
meson.build
18
meson.build
@ -1477,6 +1477,11 @@ if host_system == 'windows'
|
||||
glibconfig_conf.set('g_threads_impl_def', 'WIN32')
|
||||
glib_conf.set('THREADS_WIN32', 1)
|
||||
else
|
||||
pthread_prefix = '''
|
||||
#ifndef _GNU_SOURCE
|
||||
# define _GNU_SOURCE
|
||||
#endif
|
||||
#include <pthread.h>'''
|
||||
glibconfig_conf.set('g_threads_impl_def', 'POSIX')
|
||||
glib_conf.set('THREADS_POSIX', 1)
|
||||
if cc.has_header_symbol('pthread.h', 'pthread_attr_setstacksize')
|
||||
@ -1488,11 +1493,11 @@ else
|
||||
if cc.has_header_symbol('pthread.h', 'pthread_cond_timedwait_relative_np')
|
||||
glib_conf.set('HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP', 1)
|
||||
endif
|
||||
if cc.has_header_symbol('pthread.h', 'pthread_getname_np', prefix : pthread_prefix)
|
||||
glib_conf.set('HAVE_PTHREAD_GETNAME_NP', 1)
|
||||
endif
|
||||
# Assume that pthread_setname_np is available in some form; same as configure
|
||||
if cc.links('''#ifndef _GNU_SOURCE
|
||||
# define _GNU_SOURCE
|
||||
#endif
|
||||
#include <pthread.h>
|
||||
if cc.links(pthread_prefix + '''
|
||||
int main() {
|
||||
pthread_setname_np("example");
|
||||
}''',
|
||||
@ -1500,10 +1505,7 @@ else
|
||||
dependencies : thread_dep)
|
||||
# macOS and iOS
|
||||
glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
|
||||
elif cc.links('''#ifndef _GNU_SOURCE
|
||||
# define _GNU_SOURCE
|
||||
#endif
|
||||
#include <pthread.h>
|
||||
elif cc.links(pthread_prefix + '''
|
||||
int main() {
|
||||
pthread_setname_np(pthread_self(), "example");
|
||||
}''',
|
||||
|
Loading…
Reference in New Issue
Block a user