From 4c166709d06571b889a89812c962a91ba4d0a071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Nogueira?= Date: Tue, 20 Jul 2021 12:10:40 -0300 Subject: [PATCH] modules: improve _gettid wrapper - use meson to check for gettid() function, always use if available - use syscall fallback on linux, if not - restrict thr_self() fallback to *only* FreeBSD - error out if there isn't any gettid impl [Retrieved from: https://gitlab.freedesktop.org/pipewire/pipewire/-/commit/4c166709d06571b889a89812c962a91ba4d0a071] Signed-off-by: Fabrice Fontaine --- meson.build | 3 +++ src/modules/module-rtkit.c | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 838fb66be..977ce9ba1 100644 --- a/meson.build +++ b/meson.build @@ -254,6 +254,9 @@ endif if cc.has_function('getpagesize', prefix : '#include') cdata.set('HAVE_GETPAGESIZE', 1) endif +if cc.has_function('gettid', prefix : '#include', args: [ '-D_GNU_SOURCE' ]) + cdata.set('HAVE_GETTID', 1) +endif if cc.has_function('clock_gettime', prefix : '#include ') cdata.set('HAVE_CLOCK_GETTIME', 1) endif diff --git a/src/modules/module-rtkit.c b/src/modules/module-rtkit.c index 1f13aa371..7d55fb758 100644 --- a/src/modules/module-rtkit.c +++ b/src/modules/module-rtkit.c @@ -182,12 +182,16 @@ void pw_rtkit_bus_free(struct pw_rtkit_bus *system_bus) static pid_t _gettid(void) { -#ifndef __FreeBSD__ +#if defined(HAVE_GETTID) return (pid_t) gettid(); -#else +#elif defined(__linux__) + return syscall(SYS_gettid); +#elif defined(__FreeBSD__) long pid; thr_self(&pid); return (pid_t)pid; +#else +#error "No gettid impl" #endif } -- GitLab