Skip to content

Conversation

@biabbas
Copy link
Contributor

@biabbas biabbas commented Dec 18, 2024

setitimer is obsolete since POSIX.2008. POSIX recommends use of timer_settimer.

Regards,

@biabbas biabbas requested a review from a team as a code owner December 18, 2024 04:30
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Dec 18, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 18, 2024

@llvm/pr-subscribers-libcxx

Author: B I Mohammed Abbas (biabbas)

Changes

setitimer is obsolete since POSIX.2008. POSIX recommends use of timer_settimer.

Regards,


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

1 Files Affected:

  • (modified) libcxx/test/libcxx/thread/thread.threads/thread.thread.this/sleep_for.signals.pass.cpp (+12-4)
diff --git a/libcxx/test/libcxx/thread/thread.threads/thread.thread.this/sleep_for.signals.pass.cpp b/libcxx/test/libcxx/thread/thread.threads/thread.thread.this/sleep_for.signals.pass.cpp
index 1dba5d8a409766..687974aaf0ac95 100644
--- a/libcxx/test/libcxx/thread/thread.threads/thread.thread.this/sleep_for.signals.pass.cpp
+++ b/libcxx/test/libcxx/thread/thread.threads/thread.thread.this/sleep_for.signals.pass.cpp
@@ -44,13 +44,21 @@ int main(int, char**)
   ec = sigaction(SIGALRM, &action, nullptr);
   assert(!ec);
 
-  struct itimerval it;
-  std::memset(&it, 0, sizeof(itimerval));
+  timer_t timer_id;
+  struct sigevent _sev;
+  _sev.sigev_signo = SIGALRM;
+  _sev.sigev_notify = SIGEV_SIGNAL;
+  _sev.sigev_value.sival_ptr = timer_id;
+  ec = timer_create(CLOCK_REALTIME, &_sev, &timer_id);
+  assert(!ec);
+
+  struct itimerspec it;
+  std::memset(&it, 0, sizeof(itimerspec));
   it.it_value.tv_sec = 0;
-  it.it_value.tv_usec = 250000;
+  it.it_value.tv_nsec = 250000000;
   // This will result in a SIGALRM getting fired resulting in the nanosleep
   // inside sleep_for getting EINTR.
-  ec = setitimer(ITIMER_REAL, &it, nullptr);
+  ec = timer_settime(timer_id, 0, &it, nullptr);
   assert(!ec);
 
   typedef std::chrono::system_clock Clock;

@github-actions
Copy link

github-actions bot commented Dec 18, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@biabbas biabbas force-pushed the libcxx_setitimer branch 2 times, most recently from 81184d4 to cdeb514 Compare December 18, 2024 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants