Skip to content

glib/gthread-posix: Conditionally use `futex` and/or `futex_time64` syscalls...

Sebastian Dröge requested to merge sdroege/glib:futex64 into main

glib/gthread-posix: Conditionally use futex and/or futex_time64 syscalls as necessary and use the correct struct timespec definition

On some systems only futex_time64 exists (e.g. riscv32) while on others only futex exists (old Linux, 64 bit platforms), so it is necessary to check for both and try calling both at runtime.

Additionally use the correct struct timespec definition. There is not necessarily any relation between the libc's definition and the kernel's.

Specifically, the libc headers might use 64-bit time_t while the kernel headers use 32-bit __kernel_old_time_t on certain systems.

To get around this problem we

  1. check if futex_time64 is available, which only exists on 32-bit platforms and always uses 64-bit time_t.
  2. otherwise (or if that returns ENOSYS), we call the normal futex syscall with the struct timespec used by the kernel, which uses __kernel_long_t for both its fields. We use that instead of __kernel_old_time_t because it is equivalent and available in the kernel headers for a longer time.
Edited by Sebastian Dröge

Merge request reports