aboutsummaryrefslogtreecommitdiff
path: root/libc/src
diff options
context:
space:
mode:
authorMikhail R. Gadelha <mikhail@igalia.com>2024-07-20 22:27:39 +0200
committerGitHub <noreply@github.com>2024-07-20 17:27:39 -0300
commit569814e862a7ce1de3144e76d0a97253ac161d05 (patch)
tree96b350428f6b3cdfc00e80827e975c75d111699d /libc/src
parentcc2fb58639a6b87f155e6052f5ef2bbe05d5c378 (diff)
downloadllvm-569814e862a7ce1de3144e76d0a97253ac161d05.zip
llvm-569814e862a7ce1de3144e76d0a97253ac161d05.tar.gz
llvm-569814e862a7ce1de3144e76d0a97253ac161d05.tar.bz2
[libc] Implement pwait2 using pwait (#99781)
This patch implements pwait2 using pwait. The implementation is an approximation of pwait2, since pwait only only supports timeouts in milliseconds, not nanoseconds, as required by pwait2.
Diffstat (limited to 'libc/src')
-rw-r--r--libc/src/sys/epoll/linux/epoll_pwait2.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/libc/src/sys/epoll/linux/epoll_pwait2.cpp b/libc/src/sys/epoll/linux/epoll_pwait2.cpp
index 14b4193..4123157 100644
--- a/libc/src/sys/epoll/linux/epoll_pwait2.cpp
+++ b/libc/src/sys/epoll/linux/epoll_pwait2.cpp
@@ -25,10 +25,22 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, epoll_pwait2,
(int epfd, struct epoll_event *events, int maxevents,
const struct timespec *timeout, const sigset_t *sigmask)) {
+#ifdef SYS_epoll_pwait2
int ret = LIBC_NAMESPACE::syscall_impl<int>(
SYS_epoll_pwait2, epfd, reinterpret_cast<long>(events), maxevents,
reinterpret_cast<long>(timeout), reinterpret_cast<long>(sigmask),
NSIG / 8);
+#elif defined(SYS_epoll_pwait)
+ // Convert nanoseconds to milliseconds, rounding up if there are remaining
+ // nanoseconds
+ long timeout_ms = static_cast<long>(timeout->tv_sec * 1000 +
+ (timeout->tv_nsec + 999999) / 1000000);
+ int ret = LIBC_NAMESPACE::syscall_impl<int>(
+ SYS_epoll_pwait, epfd, reinterpret_cast<long>(events), maxevents,
+ timeout_ms, reinterpret_cast<long>(sigmask), NSIG / 8);
+#else
+#error "epoll_pwait and epoll_pwait2 syscalls not available."
+#endif
// A negative return value indicates an error with the magnitude of the
// value being the error code.