Changed usleep() to nanosleep()

This commit is contained in:
adamdunkels 2007-11-26 23:28:33 +00:00
parent 85c75d18fb
commit 4eae027dd3
5 changed files with 37 additions and 13 deletions

View file

@ -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 <stdio.h>
#include <time.h>
#include <unistd.h>
#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();
}

View file

@ -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 <stdio.h>
#include <unistd.h>
#include <time.h>
#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();
}

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $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 <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#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();
}

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $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

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $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,6 +197,7 @@ 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));
@ -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);