|
From: Bart V. A. <bva...@so...> - 2021-02-20 22:57:25
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=719d23b7a9c3b02411dee7d5d4d3744938bb768c commit 719d23b7a9c3b02411dee7d5d4d3744938bb768c Author: Bart Van Assche <bva...@ac...> Date: Sat Feb 20 14:48:58 2021 -0800 drd/tests/swapcontext: Improve portability Diff: --- drd/tests/swapcontext.c | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/drd/tests/swapcontext.c b/drd/tests/swapcontext.c index f3944d1ba6..e692559b06 100644 --- a/drd/tests/swapcontext.c +++ b/drd/tests/swapcontext.c @@ -16,7 +16,6 @@ typedef struct thread_local { ucontext_t uc[3]; size_t nrsw; - int tfd; } thread_local_t; static void f(void *data, int n) @@ -26,15 +25,11 @@ static void f(void *data, int n) thread_local_t *tlocal = data; while (1) { - memset(&pfd, 0, sizeof(pfd)); - pfd.fd = tlocal->tfd; - pfd.events = POLLIN; - - if (poll(&pfd, 1, 0) == 1) { - if (++tlocal->nrsw == NR_SWITCHES) - return; - swapcontext(&tlocal->uc[n], &tlocal->uc[3 - n]); - } + struct timespec delay = { .tv_nsec = 1000 }; + nanosleep(&delay, NULL); + if (++tlocal->nrsw == NR_SWITCHES) + return; + swapcontext(&tlocal->uc[n], &tlocal->uc[3 - n]); } } @@ -62,19 +57,6 @@ void *worker(void *data) __valgrind_register_current_stack(); - tlocal->tfd = timerfd_create(CLOCK_REALTIME, 0); - if (tlocal->tfd < 0) - abort(); - - it.it_interval.tv_sec = 0; - it.it_interval.tv_nsec = 1000; - - it.it_value.tv_sec = time(NULL); - it.it_value.tv_nsec = 1000; - - if (timerfd_settime(tlocal->tfd, TFD_TIMER_ABSTIME, &it, NULL) < 0) - abort(); - if (getcontext(&(tlocal->uc[1])) < 0) abort(); if (getcontext(&(tlocal->uc[2])) < 0) |