From 4eae027dd31c06d8ace0c560adbe372a6b88b525 Mon Sep 17 00:00:00 2001 From: adamdunkels Date: Mon, 26 Nov 2007 23:28:33 +0000 Subject: [PATCH] Changed usleep() to nanosleep() --- platform/minimal-net/contiki-main.c | 10 ++++++++-- platform/native/contiki-main.c | 10 +++++++--- platform/netsim/contiki-main.c | 9 +++++++-- platform/netsim/main.c | 12 +++++++++--- platform/netsim/net/ethernode.c | 9 ++++++--- 5 files changed, 37 insertions(+), 13 deletions(-) diff --git a/platform/minimal-net/contiki-main.c b/platform/minimal-net/contiki-main.c index da6f8dd8b..e0365b995 100644 --- a/platform/minimal-net/contiki-main.c +++ b/platform/minimal-net/contiki-main.c @@ -29,11 +29,12 @@ * * This file is part of the Contiki OS * - * $Id: contiki-main.c,v 1.10 2007/11/25 15:00:32 oliverschmidt Exp $ + * $Id: contiki-main.c,v 1.11 2007/11/26 23:28:33 adamdunkels Exp $ * */ #include +#include #include #include "contiki.h" @@ -77,11 +78,16 @@ main(void) while(1) { int n; + struct timespec ts; + n = process_run(); /* if(n > 0) { printf("%d processes in queue\n"); }*/ - usleep(1); + + ts.tv_sec = 0; + ts.tv_nsec = 1000; + nanosleep(&ts, NULL); etimer_request_poll(); } diff --git a/platform/native/contiki-main.c b/platform/native/contiki-main.c index ab9d9f1ea..0130ef641 100644 --- a/platform/native/contiki-main.c +++ b/platform/native/contiki-main.c @@ -29,12 +29,12 @@ * * This file is part of the Contiki OS * - * $Id: contiki-main.c,v 1.4 2007/11/17 10:47:47 adamdunkels Exp $ + * $Id: contiki-main.c,v 1.5 2007/11/26 23:28:33 adamdunkels Exp $ * */ #include -#include +#include #include "contiki.h" @@ -73,8 +73,12 @@ main(void) while(1) { int n; + struct timespec ts; + n = process_run(); - usleep(1); + ts.tv_sec = 0; + ts.tv_nsec = 1000; + nanosleep(&ts, NULL); etimer_request_poll(); } diff --git a/platform/netsim/contiki-main.c b/platform/netsim/contiki-main.c index 38443c4f7..6a91e2b40 100644 --- a/platform/netsim/contiki-main.c +++ b/platform/netsim/contiki-main.c @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: contiki-main.c,v 1.19 2007/11/17 18:09:18 adamdunkels Exp $ + * $Id: contiki-main.c,v 1.20 2007/11/26 23:28:33 adamdunkels Exp $ */ #include "contiki.h" @@ -55,6 +55,7 @@ #include #include +#include #include #include "dev/button-sensor.h" @@ -124,11 +125,15 @@ contiki_main(int flag) while(1) { int n; + struct timespec ts; + n = process_run(); /* if(n > 0) { printf("%d processes in queue\n"); }*/ - usleep(1); + ts.tv_sec = 0; + ts.tv_nsec = 1000; + nanosleep(&ts, NULL); etimer_request_poll(); } diff --git a/platform/netsim/main.c b/platform/netsim/main.c index 5282c2587..6489feb1b 100644 --- a/platform/netsim/main.c +++ b/platform/netsim/main.c @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: main.c,v 1.6 2007/11/17 18:09:18 adamdunkels Exp $ + * $Id: main.c,v 1.7 2007/11/26 23:28:33 adamdunkels Exp $ */ /** @@ -111,6 +111,7 @@ static int start_node(int x, int y, int b) { pid_t pid; + struct timespec ts; static unsigned short port = NODES_PORTBASE; pid = fork(); @@ -122,7 +123,9 @@ start_node(int x, int y, int b) srand(getpid()); - usleep(1000 * (rand() % 1000)); + ts.tv_sec = 0; + ts.tv_nsec = 1000000 * (rand() % 1000); + nanosleep(&ts, NULL); node_init(port - NODES_PORTBASE + 2, x, y, b); ethernode_init(port); @@ -210,7 +213,10 @@ static signed long drift = 0; void clock_delay(unsigned int num) { - usleep(num * 100); + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = 100000 * num; + nanosleep(&ts, NULL); } void diff --git a/platform/netsim/net/ethernode.c b/platform/netsim/net/ethernode.c index c486d65ca..dd98d64d7 100644 --- a/platform/netsim/net/ethernode.c +++ b/platform/netsim/net/ethernode.c @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: ethernode.c,v 1.9 2007/11/17 18:09:19 adamdunkels Exp $ + * $Id: ethernode.c,v 1.10 2007/11/26 23:28:33 adamdunkels Exp $ */ /** * \file @@ -197,7 +197,8 @@ ethernode_send(void) static char tmpbuf[2048]; struct hdr *hdr = (struct hdr *)tmpbuf; u8_t dest; - + struct timespec ts; + if(uip_len > sizeof(tmpbuf)) { PRINTF(("Ethernode_send: too large uip_len %d\n", uip_len)); return UIP_FW_TOOLARGE; @@ -207,7 +208,9 @@ ethernode_send(void) len = uip_len + HDR_LEN; dest = ID_BROADCAST; - + ts.tv_sec = 0; + ts.tv_nsec = 1000; + nanosleep(&ts, NULL); usleep(1000 * (random_rand() % 1000)); do_send(TYPE_DATA, dest, hdr, len);