[PATCH 1/2] Linux: Add futex_waitv

André Almeida <[email protected]>
Newsgroups gmane.comp.lib.glibc.alpha
Message-ID <[email protected]>
This syscall can wait on multiple futexes at the same time, and wake up on
any.

Signed-off-by: André Almeida <[email protected]>
---
 include/sys/futex.h                   |  4 ++++
 sysdeps/unix/sysv/linux/Makefile      |  2 ++
 sysdeps/unix/sysv/linux/futex_waitv.c | 32 +++++++++++++++++++++++++++
 sysdeps/unix/sysv/linux/sys/futex.h   | 24 ++++++++++++++++++++
 4 files changed, 62 insertions(+)
 create mode 100644 include/sys/futex.h
 create mode 100644 sysdeps/unix/sysv/linux/futex_waitv.c
 create mode 100644 sysdeps/unix/sysv/linux/sys/futex.h

diff --git a/include/sys/futex.h b/include/sys/futex.h
new file mode 100644
index 0000000000..8f0f56c58c
--- /dev/null
+++ b/include/sys/futex.h
@@ -0,0 +1,4 @@
+#ifndef _SYS_FUTEX_H
+#include_next <sys/futex.h>
+
+#endif
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 14a56d5cc3..d3ccb57b59 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -74,6 +74,7 @@ sysdep_routines += \
   eventfd_read \
   eventfd_write \
   fanotify_mark \
+  futex_waitv \
   fxstat \
   fxstat64 \
   fxstatat \
@@ -169,6 +170,7 @@ sysdep_headers += \
   sys/eventfd.h \
   sys/fanotify.h \
   sys/fsuid.h \
+  sys/futex.h \
   sys/inotify.h \
   sys/kd.h \
   sys/klog.h \
diff --git a/sysdeps/unix/sysv/linux/futex_waitv.c b/sysdeps/unix/sysv/linux/futex_waitv.c
new file mode 100644
index 0000000000..b77df2f2cd
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/futex_waitv.c
@@ -0,0 +1,32 @@
+/* futex_waitv -- Wait on multiple futexes.  Linux version.
+   Copyright (C) 2020-2026 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <time.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/futex.h>
+
+#include <sysdep-cancel.h>
+
+int
+futex_waitv (struct futex_waitv *waiters, unsigned int nr_waiters,
+	       unsigned int flags, const struct __timespec64 *timeout,
+	       clockid_t clockid)
+{
+	return SYSCALL_CANCEL (futex_waitv, waiters, nr_waiters, flags, &timeout, clockid);
+}
diff --git a/sysdeps/unix/sysv/linux/sys/futex.h b/sysdeps/unix/sysv/linux/sys/futex.h
new file mode 100644
index 0000000000..89780e9e5a
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sys/futex.h
@@ -0,0 +1,24 @@
+#ifndef	_SYS_FUTEX_H
+#define	_SYS_FUTEX_H	1
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <struct___timespec64.h>
+
+#define FUTEX2_SIZE_U8		0x00
+#define FUTEX2_SIZE_U16		0x01
+#define FUTEX2_SIZE_U32		0x02
+#define FUTEX2_SIZE_U64		0x03
+
+struct futex_waitv {
+	uint64_t val;
+	uint64_t uaddr;
+	uint32_t flags;
+	uint32_t __reserved;
+};
+
+extern int
+futex_waitv (struct futex_waitv *waiters, unsigned int nr_waiters,
+	       unsigned int flags, const struct __timespec64 *timeout,
+	       clockid_t clockid);
+#endif
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.