[glib: 1/2] Check for SYS_sched_getattr before using it unconditionally



commit 8b1f24f6588be8abafe35de9aba4d69b73a583ae
Author: Sebastian Dröge <sebastian centricular com>
Date:   Thu Jan 16 16:02:39 2020 +0200

    Check for SYS_sched_getattr before using it unconditionally
    
    Really old versions of Linux don't have yet. In that case fall back to
    the fallback code.
    
    See https://gitlab.gnome.org/GNOME/glib/commit/8aeca4fa647bfd0f35c4a86b1e6ca6e955519ca5#note_686823

 glib/gthread-posix.c  | 8 ++++----
 glib/gthreadprivate.h | 5 ++++-
 meson.build           | 5 +++++
 3 files changed, 13 insertions(+), 5 deletions(-)
---
diff --git a/glib/gthread-posix.c b/glib/gthread-posix.c
index e1aa969fc..2f26e5831 100644
--- a/glib/gthread-posix.c
+++ b/glib/gthread-posix.c
@@ -68,7 +68,7 @@
 #include <windows.h>
 #endif
 
-#if defined(__linux__)
+#if defined(HAVE_SYS_SCHED_GETATTR)
 #include <sys/syscall.h>
 #endif
 
@@ -1167,7 +1167,7 @@ g_system_thread_get_scheduler_settings (GThreadSchedulerSettings *scheduler_sett
 {
   /* FIXME: Implement the same for macOS and the BSDs so it doesn't go through
    * the fallback code using an additional thread. */
-#if defined(__linux__)
+#if defined(HAVE_SYS_SCHED_GETATTR)
   pid_t tid;
   int res;
   /* FIXME: The struct definition does not seem to be possible to pull in
@@ -1210,7 +1210,7 @@ g_system_thread_get_scheduler_settings (GThreadSchedulerSettings *scheduler_sett
 #endif
 }
 
-#if defined(__linux__)
+#if defined(HAVE_SYS_SCHED_GETATTR)
 static void *
 linux_pthread_proxy (void *data)
 {
@@ -1284,7 +1284,7 @@ g_system_thread_new (GThreadFunc proxy,
     }
 #endif /* HAVE_PTHREAD_ATTR_SETINHERITSCHED */
 
-#if defined(__linux__)
+#if defined(HAVE_SYS_SCHED_GETATTR)
   ret = pthread_create (&thread->system_thread, &attr, linux_pthread_proxy, thread);
 #else
   ret = pthread_create (&thread->system_thread, &attr, (void* (*)(void*))proxy, thread);
diff --git a/glib/gthreadprivate.h b/glib/gthreadprivate.h
index 823c71689..4842a1e9f 100644
--- a/glib/gthreadprivate.h
+++ b/glib/gthreadprivate.h
@@ -21,6 +21,8 @@
 #ifndef __G_THREADPRIVATE_H__
 #define __G_THREADPRIVATE_H__
 
+#include "config.h"
+
 #include "deprecated/gthread.h"
 
 typedef struct _GRealThread GRealThread;
@@ -40,7 +42,8 @@ struct  _GRealThread
 typedef struct _GThreadSchedulerSettings GThreadSchedulerSettings;
 
 /* TODO: Add the same for macOS and the BSDs */
-#if defined(__linux__)
+#if defined(HAVE_SYS_SCHED_GETATTR)
+/* This is for modern Linux */
 struct _GThreadSchedulerSettings
 {
   struct sched_attr *attr;
diff --git a/meson.build b/meson.build
index dd73d5480..23f218f94 100644
--- a/meson.build
+++ b/meson.build
@@ -1730,6 +1730,11 @@ else
   if cc.has_header_symbol('pthread.h', 'pthread_getname_np', prefix : pthread_prefix)
     glib_conf.set('HAVE_PTHREAD_GETNAME_NP', 1)
   endif
+
+  if cc.has_header_symbol('sys/syscall.h', 'SYS_sched_getattr,')
+    glib_conf.set('HAVE_SYS_SCHED_GETATTR', 1)
+  endif
+
   # Assume that pthread_setname_np is available in some form; same as configure
   if cc.links(pthread_prefix + '''
               int main() {


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