[glib] Meson: add 'force_posix_threads' option



commit 2477c7b05faa26d62bd151f82c8087c471f62292
Author: Xavier Claessens <xavier claessens collabora com>
Date:   Tue May 15 14:05:50 2018 -0400

    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

 glib/meson.build  |  4 ++--
 meson.build       | 11 ++++++-----
 meson_options.txt |  5 +++++
 3 files changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/glib/meson.build b/glib/meson.build
index a97d11f6c..1010f5d92 100644
--- a/glib/meson.build
+++ b/glib/meson.build
@@ -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')
diff --git a/meson.build b/meson.build
index 511b0393d..4ccb312cb 100644
--- a/meson.build
+++ b/meson.build
@@ -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
diff --git a/meson_options.txt b/meson_options.txt
index 60a541d92..3d816d365 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -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)')


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]