Skip to content

Commit 4c6cb4e

Browse files
mikhailramalhoyuxuanchen1997
authored andcommitted
[libc] Implement pwait2 using pwait (#99781)
Summary: 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. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251459
1 parent 616b0a2 commit 4c6cb4e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

libc/src/sys/epoll/linux/epoll_pwait2.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,22 @@ namespace LIBC_NAMESPACE_DECL {
2525
LLVM_LIBC_FUNCTION(int, epoll_pwait2,
2626
(int epfd, struct epoll_event *events, int maxevents,
2727
const struct timespec *timeout, const sigset_t *sigmask)) {
28+
#ifdef SYS_epoll_pwait2
2829
int ret = LIBC_NAMESPACE::syscall_impl<int>(
2930
SYS_epoll_pwait2, epfd, reinterpret_cast<long>(events), maxevents,
3031
reinterpret_cast<long>(timeout), reinterpret_cast<long>(sigmask),
3132
NSIG / 8);
33+
#elif defined(SYS_epoll_pwait)
34+
// Convert nanoseconds to milliseconds, rounding up if there are remaining
35+
// nanoseconds
36+
long timeout_ms = static_cast<long>(timeout->tv_sec * 1000 +
37+
(timeout->tv_nsec + 999999) / 1000000);
38+
int ret = LIBC_NAMESPACE::syscall_impl<int>(
39+
SYS_epoll_pwait, epfd, reinterpret_cast<long>(events), maxevents,
40+
timeout_ms, reinterpret_cast<long>(sigmask), NSIG / 8);
41+
#else
42+
#error "epoll_pwait and epoll_pwait2 syscalls not available."
43+
#endif
3244

3345
// A negative return value indicates an error with the magnitude of the
3446
// value being the error code.

0 commit comments

Comments
 (0)