diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bde630d..7080f5a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -84,7 +84,13 @@ build-x86_64-tsd-meson: extends: - .build-check-meson variables: - CONFIGURE_OPTIONS: -Dtls=disabled + CONFIGURE_OPTIONS: -Dtls=false + +build-x86_64-tsd-tls-meson: + extends: + - .build-check-meson + variables: + CONFIGURE_OPTIONS: -Ddispatch-tls=false build-i386-tsd: extends: @@ -96,7 +102,13 @@ build-i386-tsd-meson: extends: - .build-check-meson variables: - CONFIGURE_OPTIONS: -Dtls=disabled --cross-file .gitlab-ci/i686-linux-gnu + CONFIGURE_OPTIONS: -Dtls=false --cross-file .gitlab-ci/i686-linux-gnu + +build-i386-tsd-tls-meson: + extends: + - .build-check-meson + variables: + CONFIGURE_OPTIONS: -Ddispatch-tls=false --cross-file .gitlab-ci/i686-linux-gnu build-pure-c-tls: extends: @@ -120,4 +132,4 @@ build-pure-c-tld-meson: extends: - .build-check-meson variables: - CONFIGURE_OPTIONS: -Dasm=disabled -Dtls=disabled + CONFIGURE_OPTIONS: -Dasm=disabled -Dtls=false diff --git a/meson.build b/meson.build index cbe2ec4..c248f9a 100644 --- a/meson.build +++ b/meson.build @@ -110,14 +110,17 @@ if cc.compiles('typeof(int *);', name : 'typeof') endif with_tls = get_option('tls') -if with_tls.auto() +if with_tls + # Use a __thread variable if possible, even if we can't use the TLS assembly + # stubs, because it's still faster than calling pthread_getspecific. have_tls = cc.compiles( '__thread int foo;', name : '__thread', ) else - have_tls = with_tls.enabled() + have_tls = false endif +message('Using TLS variable for dispatch table: @0@'.format(have_tls)) if have_tls add_project_arguments('-DGLDISPATCH_USE_TLS', language : ['c']) @@ -129,7 +132,15 @@ if use_asm # FreeBSD and glibc). on other platforms we use TSD stubs to allow calling # extension functions unknown at compile time. # https://gitlab.freedesktop.org/glvnd/libglvnd/-/merge_requests/249 - thread_type = have_tls and (host_machine.system() == 'freebsd' or cc.has_header_symbol('features.h', '__GLIBC__')) ? 'tls' : 'tsd' + thread_type = 'tsd' + if get_option('dispatch-tls') + if have_tls + if host_machine.system() == 'freebsd' or cc.has_header_symbol('features.h', '__GLIBC__') + thread_type = 'tls' + endif + endif + endif + if host_machine.cpu_family().startswith('x86') gl_dispatch_type = '@0@_@1@'.format( host_machine.cpu_family(), diff --git a/meson_options.txt b/meson_options.txt index 117d7d4..43198f6 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -56,8 +56,15 @@ option( ) option( 'tls', - type : 'feature', - description : 'Use Thread Local Storage.' + type : 'boolean', + value : true, + description : 'Use Thread Local Storage (if supported).' +) +option( + 'dispatch-tls', + type : 'boolean', + value : true, + description : 'Use TLS-based stubs in libGLdispatch (if supported).' ) option( 'dispatch-page-size',