mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 07:26:15 +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 */
|
/* Have function pthread_setname_np with TID as argument */
|
||||||
#mesondefine HAVE_PTHREAD_SETNAME_NP_WITH_TID
|
#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'. */
|
/* Define to 1 if the system has the type `ptrdiff_t'. */
|
||||||
#mesondefine HAVE_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,
|
AC_DEFINE(HAVE_PTHREAD_SETNAME_NP_WITH_TID,1,
|
||||||
[Have function pthread_setname_np(pthread_t, const char*)])],
|
[Have function pthread_setname_np(pthread_t, const char*)])],
|
||||||
[AC_MSG_RESULT(no)])
|
[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"
|
CPPFLAGS="$glib_save_CPPFLAGS"
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ test_thread5 (void)
|
|||||||
static gpointer
|
static gpointer
|
||||||
thread6_func (gpointer data)
|
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];
|
char name[16];
|
||||||
|
|
||||||
pthread_getname_np (pthread_self(), 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')
|
glibconfig_conf.set('g_threads_impl_def', 'WIN32')
|
||||||
glib_conf.set('THREADS_WIN32', 1)
|
glib_conf.set('THREADS_WIN32', 1)
|
||||||
else
|
else
|
||||||
|
pthread_prefix = '''
|
||||||
|
#ifndef _GNU_SOURCE
|
||||||
|
# define _GNU_SOURCE
|
||||||
|
#endif
|
||||||
|
#include <pthread.h>'''
|
||||||
glibconfig_conf.set('g_threads_impl_def', 'POSIX')
|
glibconfig_conf.set('g_threads_impl_def', 'POSIX')
|
||||||
glib_conf.set('THREADS_POSIX', 1)
|
glib_conf.set('THREADS_POSIX', 1)
|
||||||
if cc.has_header_symbol('pthread.h', 'pthread_attr_setstacksize')
|
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')
|
if cc.has_header_symbol('pthread.h', 'pthread_cond_timedwait_relative_np')
|
||||||
glib_conf.set('HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP', 1)
|
glib_conf.set('HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP', 1)
|
||||||
endif
|
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
|
# Assume that pthread_setname_np is available in some form; same as configure
|
||||||
if cc.links('''#ifndef _GNU_SOURCE
|
if cc.links(pthread_prefix + '''
|
||||||
# define _GNU_SOURCE
|
|
||||||
#endif
|
|
||||||
#include <pthread.h>
|
|
||||||
int main() {
|
int main() {
|
||||||
pthread_setname_np("example");
|
pthread_setname_np("example");
|
||||||
}''',
|
}''',
|
||||||
@ -1500,10 +1505,7 @@ else
|
|||||||
dependencies : thread_dep)
|
dependencies : thread_dep)
|
||||||
# macOS and iOS
|
# macOS and iOS
|
||||||
glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
|
glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
|
||||||
elif cc.links('''#ifndef _GNU_SOURCE
|
elif cc.links(pthread_prefix + '''
|
||||||
# define _GNU_SOURCE
|
|
||||||
#endif
|
|
||||||
#include <pthread.h>
|
|
||||||
int main() {
|
int main() {
|
||||||
pthread_setname_np(pthread_self(), "example");
|
pthread_setname_np(pthread_self(), "example");
|
||||||
}''',
|
}''',
|
||||||
|
Loading…
Reference in New Issue
Block a user