]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
drd/tests/swapcontext: Improve portability
authorBart Van Assche <bvanassche@acm.org>
Sat, 20 Feb 2021 22:48:58 +0000 (14:48 -0800)
committerBart Van Assche <bvanassche@acm.org>
Sat, 20 Feb 2021 22:51:15 +0000 (14:51 -0800)
drd/tests/swapcontext.c

index f3944d1ba636d75775959eae88a21cb78897779e..e692559b06f0ddfe5aa0a6c95bcbc78c77f64532 100644 (file)
@@ -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)