Merge branch 'threadpool-sched-getattr' into 'master'

Check for SYS_sched_getattr before using it unconditionally

See merge request GNOME/glib!1325
This commit is contained in:
Sebastian Dröge 2020-01-17 07:40:38 +00:00
commit 457ea97c75
3 changed files with 13 additions and 5 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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() {