Reimplemented waiting with select() instead of nanosleep(). Let's see if Linux compiles this code now...

This commit is contained in:
adamdunkels 2007-11-28 12:54:41 +00:00
parent 13ca6c9946
commit a725de0f79
5 changed files with 32 additions and 32 deletions

View file

@ -29,7 +29,7 @@
* *
* This file is part of the Contiki OS * This file is part of the Contiki OS
* *
* $Id: contiki-main.c,v 1.11 2007/11/26 23:28:33 adamdunkels Exp $ * $Id: contiki-main.c,v 1.12 2007/11/28 12:54:41 adamdunkels Exp $
* *
*/ */
@ -78,16 +78,16 @@ main(void)
while(1) { while(1) {
int n; int n;
struct timespec ts; struct timeval tv;
n = process_run(); n = process_run();
/* if(n > 0) { /* if(n > 0) {
printf("%d processes in queue\n"); printf("%d processes in queue\n");
}*/ }*/
ts.tv_sec = 0; tv.tv_sec = 0;
ts.tv_nsec = 1000; tv.tv_usec = 1;
nanosleep(&ts, NULL); select(0, NULL, NULL, NULL, &tv);
etimer_request_poll(); etimer_request_poll();
} }

View file

@ -29,12 +29,12 @@
* *
* This file is part of the Contiki OS * This file is part of the Contiki OS
* *
* $Id: contiki-main.c,v 1.5 2007/11/26 23:28:33 adamdunkels Exp $ * $Id: contiki-main.c,v 1.6 2007/11/28 12:54:42 adamdunkels Exp $
* *
*/ */
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <sys/select.h>
#include "contiki.h" #include "contiki.h"
@ -73,12 +73,12 @@ main(void)
while(1) { while(1) {
int n; int n;
struct timespec ts; struct timeval tv;
n = process_run(); n = process_run();
ts.tv_sec = 0; tv.tv_sec = 0;
ts.tv_nsec = 1000; tv.tv_usec = 1;
nanosleep(&ts, NULL); select(0, NULL, NULL, NULL, &tv);
etimer_request_poll(); etimer_request_poll();
} }

View file

@ -30,7 +30,7 @@
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
* $Id: contiki-main.c,v 1.20 2007/11/26 23:28:33 adamdunkels Exp $ * $Id: contiki-main.c,v 1.21 2007/11/28 12:54:42 adamdunkels Exp $
*/ */
#include "contiki.h" #include "contiki.h"
@ -55,7 +55,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <sys/select.h>
#include <unistd.h> #include <unistd.h>
#include "dev/button-sensor.h" #include "dev/button-sensor.h"
@ -125,15 +125,15 @@ contiki_main(int flag)
while(1) { while(1) {
int n; int n;
struct timespec ts; struct timeval tv;
n = process_run(); n = process_run();
/* if(n > 0) { /* if(n > 0) {
printf("%d processes in queue\n"); printf("%d processes in queue\n");
}*/ }*/
ts.tv_sec = 0; tv.tv_sec = 0;
ts.tv_nsec = 1000; tv.tv_usec = 1;
nanosleep(&ts, NULL); select(0, NULL, NULL, NULL, &tv);
etimer_request_poll(); etimer_request_poll();
} }

View file

@ -30,7 +30,7 @@
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
* $Id: main.c,v 1.7 2007/11/26 23:28:33 adamdunkels Exp $ * $Id: main.c,v 1.8 2007/11/28 12:54:42 adamdunkels Exp $
*/ */
/** /**
@ -111,7 +111,7 @@ static int
start_node(int x, int y, int b) start_node(int x, int y, int b)
{ {
pid_t pid; pid_t pid;
struct timespec ts; struct timeval tv;
static unsigned short port = NODES_PORTBASE; static unsigned short port = NODES_PORTBASE;
pid = fork(); pid = fork();
@ -123,9 +123,9 @@ start_node(int x, int y, int b)
srand(getpid()); srand(getpid());
ts.tv_sec = 0; tv.tv_sec = 0;
ts.tv_nsec = 1000000 * (rand() % 1000); tv.tv_usec = 1000 * (rand() % 1000);
nanosleep(&ts, NULL); select(0, NULL, NULL, NULL, &tv);
node_init(port - NODES_PORTBASE + 2, x, y, b); node_init(port - NODES_PORTBASE + 2, x, y, b);
ethernode_init(port); ethernode_init(port);
@ -213,10 +213,10 @@ static signed long drift = 0;
void void
clock_delay(unsigned int num) clock_delay(unsigned int num)
{ {
struct timespec ts; struct timeval tv;
ts.tv_sec = 0; tv.tv_sec = 0;
ts.tv_nsec = 100000 * num; tv.tv_usec = 100 * num;
nanosleep(&ts, NULL); select(0, NULL, NULL, NULL, &tv);
} }
void void

View file

@ -30,7 +30,7 @@
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
* $Id: ethernode.c,v 1.12 2007/11/27 20:45:15 nvt-se Exp $ * $Id: ethernode.c,v 1.13 2007/11/28 12:54:42 adamdunkels Exp $
*/ */
/** /**
* \file * \file
@ -51,7 +51,7 @@
#include "lib/random.h" #include "lib/random.h"
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <sys/select.h>
#include <unistd.h> #include <unistd.h>
#define BUF ((uip_tcpip_hdr *)&uip_buf[HDR_LEN]) #define BUF ((uip_tcpip_hdr *)&uip_buf[HDR_LEN])
@ -198,7 +198,7 @@ ethernode_send(void)
static char tmpbuf[2048]; static char tmpbuf[2048];
struct hdr *hdr = (struct hdr *)tmpbuf; struct hdr *hdr = (struct hdr *)tmpbuf;
u8_t dest; u8_t dest;
struct timespec ts; struct timeval tv;
if(uip_len > sizeof(tmpbuf)) { if(uip_len > sizeof(tmpbuf)) {
PRINTF(("Ethernode_send: too large uip_len %d\n", uip_len)); PRINTF(("Ethernode_send: too large uip_len %d\n", uip_len));
@ -209,9 +209,9 @@ ethernode_send(void)
len = uip_len + HDR_LEN; len = uip_len + HDR_LEN;
dest = ID_BROADCAST; dest = ID_BROADCAST;
ts.tv_sec = 0; tv.tv_sec = 0;
ts.tv_nsec = 1000 * (random_rand() % 1000); tv.tv_usec = (random_rand() % 1000);
nanosleep(&ts, NULL); select(0, NULL, NULL, NULL, &tv);
do_send(TYPE_DATA, dest, hdr, len); do_send(TYPE_DATA, dest, hdr, len);