diff mbox

[PATCHv5,3/6] validation: odp_timer.c: use nanosleep instead of usleep

Message ID 1423124161-18716-4-git-send-email-ola.liljedahl@linaro.org
State Accepted
Commit 1955b525b62465bb37b3226eb99151b201fd1619
Headers show

Commit Message

Ola Liljedahl Feb. 5, 2015, 8:15 a.m. UTC
Use nanosleep instead of the deprecated usleep. Define POSIX version to be able
to use rand_r. (https://bugs.linaro.org/show_bug.cgi?id=1048)

Signed-off-by: Ola Liljedahl <ola.liljedahl@linaro.org>
---
(This document/code contribution attached is provided under the terms of
agreement LES-LTM-21309)

 test/validation/odp_timer.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/test/validation/odp_timer.c b/test/validation/odp_timer.c
index 3fc9327..d74a273 100644
--- a/test/validation/odp_timer.c
+++ b/test/validation/odp_timer.c
@@ -8,7 +8,10 @@ 
  * @file
  */
 
+/* For rand_r and nanosleep */
+#define _POSIX_C_SOURCE 200112L
 #include <assert.h>
+#include <time.h>
 #include <unistd.h>
 #include <odp.h>
 #include "odp_cunit_common.h"
@@ -210,8 +213,11 @@  static void *worker_entrypoint(void *arg)
 			/* Save expected expiration tick */
 			tt[i].tick = cur_tick + tck;
 		}
-		if (usleep(1000/*1ms*/) < 0)
-			perror("usleep"), abort();
+		struct timespec ts;
+		ts.tv_sec = 0;
+		ts.tv_nsec = 1000000; /* 1ms */
+		if (nanosleep(&ts, NULL) < 0)
+			perror("nanosleep"), abort();
 	}
 
 	/* Cancel and free all timers */
@@ -238,7 +244,11 @@  static void *worker_entrypoint(void *arg)
 
 	/* Delay some more to ensure timeouts for expired timers can be
 	 * received */
-	usleep(1000/*1ms*/);
+	struct timespec ts;
+	ts.tv_sec = 0;
+	ts.tv_nsec = 1000000; /* 1ms */
+	if (nanosleep(&ts, NULL) < 0)
+		perror("nanosleep"), abort();
 	while (nstale != 0) {
 		odp_event_t ev = odp_queue_deq(queue);
 		if (ev != ODP_EVENT_INVALID) {