Skip to content

[libc][NFC] Cleanup code for poll #141802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2025

Conversation

michaelrj-google
Copy link
Contributor

Ensure everything is defined inside the namespace, reduce number of
ifdefs.

Ensure everything is defined inside the namespace, reduce number of
ifdefs.
@llvmbot
Copy link
Member

llvmbot commented May 28, 2025

@llvm/pr-subscribers-libc

Author: Michael Jones (michaelrj-google)

Changes

Ensure everything is defined inside the namespace, reduce number of
ifdefs.


Full diff: https://github.com/llvm/llvm-project/pull/141802.diff

1 Files Affected:

  • (modified) libc/src/poll/linux/poll.cpp (+12-15)
diff --git a/libc/src/poll/linux/poll.cpp b/libc/src/poll/linux/poll.cpp
index 2579ec04c1200..f82fcbcc6577c 100644
--- a/libc/src/poll/linux/poll.cpp
+++ b/libc/src/poll/linux/poll.cpp
@@ -18,24 +18,14 @@
 
 #include <sys/syscall.h> // SYS_poll, SYS_ppoll
 
-#ifdef SYS_poll
-constexpr auto POLL_SYSCALL_ID = SYS_poll;
-#elif defined(SYS_ppoll)
-constexpr auto POLL_SYSCALL_ID = SYS_ppoll;
-#elif defined(SYS_ppoll_time64)
-constexpr auto POLL_SYSCALL_ID = SYS_ppoll_time64;
-#else
-#error "poll, ppoll, ppoll_time64 syscalls not available."
-#endif
-
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, poll, (pollfd * fds, nfds_t nfds, int timeout)) {
   int ret = 0;
 
-#ifdef SYS_poll
-  ret = LIBC_NAMESPACE::syscall_impl<int>(POLL_SYSCALL_ID, fds, nfds, timeout);
-#elif defined(SYS_ppoll) || defined(SYS_ppoll_time64)
+#if defined(SYS_poll)
+  ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_poll, fds, nfds, timeout);
+#else // no SYS_poll
   timespec ts, *tsp;
   if (timeout >= 0) {
     ts.tv_sec = timeout / 1000;
@@ -44,9 +34,16 @@ LLVM_LIBC_FUNCTION(int, poll, (pollfd * fds, nfds_t nfds, int timeout)) {
   } else {
     tsp = nullptr;
   }
-  ret = LIBC_NAMESPACE::syscall_impl<int>(POLL_SYSCALL_ID, fds, nfds, tsp,
+#if defined(SYS_ppoll)
+  ret =
+      LIBC_NAMESPACE::syscall_impl<int>(SYS_ppoll, fds, nfds, tsp, nullptr, 0);
+#elif defined(SYS_ppoll_time64)
+  ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_ppoll_time64, fds, nfds, tsp,
                                           nullptr, 0);
-#endif
+#else
+#error "poll, ppoll, ppoll_time64 syscalls not available."
+#endif // defined(SYS_ppoll) || defined(SYS_ppoll_time64)
+#endif // defined(SYS_poll)
 
   if (ret < 0) {
     libc_errno = -ret;

@michaelrj-google
Copy link
Contributor Author

CI failures seem to be unrelated, merging.

@michaelrj-google michaelrj-google merged commit 3a0205a into llvm:main May 28, 2025
19 of 21 checks passed
@michaelrj-google michaelrj-google deleted the libcCleanupPoll branch May 28, 2025 21:09
google-yfyang pushed a commit to google-yfyang/llvm-project that referenced this pull request May 29, 2025
Ensure everything is defined inside the namespace, reduce number of
ifdefs.
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
Ensure everything is defined inside the namespace, reduce number of
ifdefs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants