From: Bart Van Assche Date: Sat, 20 Feb 2021 22:48:58 +0000 (-0800) Subject: drd/tests/swapcontext: Improve portability X-Git-Tag: VALGRIND_3_17_0~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=719d23b7a9c3b02411dee7d5d4d3744938bb768c;p=thirdparty%2Fvalgrind.git drd/tests/swapcontext: Improve portability --- 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)