Skip to content

Commit cdeb514

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

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,21 @@ int main(int, char**)
4444
ec = sigaction(SIGALRM, &action, nullptr);
4545
assert(!ec);
4646

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

5664
typedef std::chrono::system_clock Clock;

0 commit comments

Comments
 (0)