Meson: add 'force_posix_threads' option

This allows building with posix threads on Windows. It is generally
better to use win32 threads implementation on Windows, but this option
can be used in case it causes issues, or for performance comparison for
example.

https://bugzilla.gnome.org/show_bug.cgi?id=784995
This commit is contained in:
Xavier Claessens 2018-05-15 14:05:50 -04:00
parent 4b82738f0a
commit 2477c7b05f
3 changed files with 13 additions and 7 deletions

View File

@ -204,15 +204,15 @@ if host_system == 'windows'
)
glib_win_res = windows.compile_resources(glib_win_rc)
glib_sources += [glib_win_res]
glib_sources += files('gthread-win32.c')
glib_sources += files('gwin32.c', 'gspawn-win32.c', 'giowin32.c')
platform_deps = [winsock2, cc.find_library('winmm')]
else
glib_sources += files('gthread-posix.c')
glib_sources += files('glib-unix.c', 'gspawn.c', 'giounix.c')
platform_deps = []
endif
glib_sources += files('gthread-@0@.c'.format(threads_implementation))
if enable_dtrace
glib_dtrace_obj = dtrace_obj_gen.process('glib_probes.d')
glib_dtrace_hdr = dtrace_hdr_gen.process('glib_probes.d')

View File

@ -1476,15 +1476,16 @@ endif
# === Threads ===
# Let meson figure out all this business and whether -pthread or whatnot is needed
# FIXME: probably needs more tweaking in meson for things like -D_REENTRANT etc.
thread_dep = dependency('threads')
# Determination of thread implementation
if host_system == 'windows'
if host_system == 'windows' and not get_option('force_posix_threads')
thread_dep = []
threads_implementation = 'win32'
glibconfig_conf.set('g_threads_impl_def', 'WIN32')
glib_conf.set('THREADS_WIN32', 1)
else
# FIXME: probably needs more tweaking in meson for things like -D_REENTRANT etc.
thread_dep = dependency('threads')
threads_implementation = 'posix'
pthread_prefix = '''
#ifndef _GNU_SOURCE
# define _GNU_SOURCE

View File

@ -68,3 +68,8 @@ option('bsymbolic_functions',
type : 'boolean',
value : true,
description : 'link with -Bsymbolic-functions if supported')
option('force_posix_threads',
type : 'boolean',
value : false,
description : 'Also use posix threads in case the platform defaults to another implementation (on Windows for example)')