Skip to content

Commit 7e3487a

Browse files
committed
Update libcxx sleep_for.signal.pass to use timer_settime instead of setitimer
1 parent db09014 commit 7e3487a

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

libcxx/test/libcxx/thread/thread.threads/thread.thread.this/sleep_for.signals.pass.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <cstring> // for std::memset
2828

2929
#include <signal.h>
30+
#include <time.h>
3031
#include <sys/time.h>
3132

3233
#include "test_macros.h"
@@ -44,13 +45,21 @@ int main(int, char**)
4445
ec = sigaction(SIGALRM, &action, nullptr);
4546
assert(!ec);
4647

47-
struct itimerval it;
48-
std::memset(&it, 0, sizeof(itimerval));
48+
timer_t timer_id = 0;
49+
struct sigevent _sev;
50+
_sev.sigev_signo = SIGALRM;
51+
_sev.sigev_notify = SIGEV_SIGNAL;
52+
_sev.sigev_value.sival_ptr = &timer_id;
53+
ec = timer_create(CLOCK_REALTIME, &_sev, &timer_id);
54+
assert(!ec);
55+
56+
struct itimerspec it;
57+
std::memset(&it, 0, sizeof(itimerspec));
4958
it.it_value.tv_sec = 0;
50-
it.it_value.tv_usec = 250000;
59+
it.it_value.tv_nsec = 250000000;
5160
// This will result in a SIGALRM getting fired resulting in the nanosleep
5261
// inside sleep_for getting EINTR.
53-
ec = setitimer(ITIMER_REAL, &it, nullptr);
62+
ec = timer_settime(timer_id, 0, &it, nullptr);
5463
assert(!ec);
5564

5665
typedef std::chrono::system_clock Clock;

0 commit comments

Comments
 (0)