[libcxx-commits] [libcxx] Update libcxx test to use timer_settime instead of setitimer (PR #120354)

B I Mohammed Abbas via libcxx-commits libcxx-commits at lists.llvm.org
Wed Dec 18 01:30:50 PST 2024


https://github.com/biabbas updated https://github.com/llvm/llvm-project/pull/120354

>From 7e3487aa20fe4fe0dff9f3a4d620b44f5456f6ea Mon Sep 17 00:00:00 2001
From: B I Mohammed Abbas <bimohammadabbas at gmail.com>
Date: Wed, 18 Dec 2024 13:20:22 +0530
Subject: [PATCH] Update libcxx sleep_for.signal.pass to use timer_settime
 instead of setitimer

---
 .../sleep_for.signals.pass.cpp                  | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

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..f979a8dfde95c7 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
@@ -27,6 +27,7 @@
 #include <cstring> // for std::memset
 
 #include <signal.h>
+#include <time.h>
 #include <sys/time.h>
 
 #include "test_macros.h"
@@ -44,13 +45,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 = 0;
+  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;



More information about the libcxx-commits mailing list