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:
Xavier Claessens
2018-04-23 10:33:44 -04:00
parent d123717947
commit 01e8396301
4 changed files with 23 additions and 9 deletions

View File

@@ -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");
}''',