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
This commit is contained in:
Érico Nogueira 2021-07-20 12:10:40 -03:00 committed by Wim Taymans
parent a4b8bd6d52
commit 4c166709d0
2 changed files with 9 additions and 2 deletions

View file

@ -254,6 +254,9 @@ endif
if cc.has_function('getpagesize', prefix : '#include<unistd.h>') if cc.has_function('getpagesize', prefix : '#include<unistd.h>')
cdata.set('HAVE_GETPAGESIZE', 1) cdata.set('HAVE_GETPAGESIZE', 1)
endif endif
if cc.has_function('gettid', prefix : '#include<unistd.h>', args: [ '-D_GNU_SOURCE' ])
cdata.set('HAVE_GETTID', 1)
endif
if cc.has_function('clock_gettime', prefix : '#include <time.h>') if cc.has_function('clock_gettime', prefix : '#include <time.h>')
cdata.set('HAVE_CLOCK_GETTIME', 1) cdata.set('HAVE_CLOCK_GETTIME', 1)
endif endif

View file

@ -182,12 +182,16 @@ void pw_rtkit_bus_free(struct pw_rtkit_bus *system_bus)
static pid_t _gettid(void) static pid_t _gettid(void)
{ {
#ifndef __FreeBSD__ #if defined(HAVE_GETTID)
return (pid_t) gettid(); return (pid_t) gettid();
#else #elif defined(__linux__)
return syscall(SYS_gettid);
#elif defined(__FreeBSD__)
long pid; long pid;
thr_self(&pid); thr_self(&pid);
return (pid_t)pid; return (pid_t)pid;
#else
#error "No gettid impl"
#endif #endif
} }