Reimplemented waiting with select() instead of nanosleep(). Let's see if Linux compiles this code now...
This commit is contained in:
parent
13ca6c9946
commit
a725de0f79
5 changed files with 32 additions and 32 deletions
|
@ -29,7 +29,7 @@
|
|||
*
|
||||
* 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) {
|
||||
int n;
|
||||
struct timespec ts;
|
||||
struct timeval tv;
|
||||
|
||||
n = process_run();
|
||||
/* if(n > 0) {
|
||||
printf("%d processes in queue\n");
|
||||
}*/
|
||||
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = 1000;
|
||||
nanosleep(&ts, NULL);
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 1;
|
||||
select(0, NULL, NULL, NULL, &tv);
|
||||
etimer_request_poll();
|
||||
}
|
||||
|
||||
|
|
|
@ -29,12 +29,12 @@
|
|||
*
|
||||
* 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 <time.h>
|
||||
#include <sys/select.h>
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
|
@ -73,12 +73,12 @@ main(void)
|
|||
|
||||
while(1) {
|
||||
int n;
|
||||
struct timespec ts;
|
||||
struct timeval tv;
|
||||
|
||||
n = process_run();
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = 1000;
|
||||
nanosleep(&ts, NULL);
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 1;
|
||||
select(0, NULL, NULL, NULL, &tv);
|
||||
etimer_request_poll();
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
*
|
||||
* 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"
|
||||
|
@ -55,7 +55,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <sys/select.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "dev/button-sensor.h"
|
||||
|
@ -125,15 +125,15 @@ contiki_main(int flag)
|
|||
|
||||
while(1) {
|
||||
int n;
|
||||
struct timespec ts;
|
||||
struct timeval tv;
|
||||
|
||||
n = process_run();
|
||||
/* if(n > 0) {
|
||||
printf("%d processes in queue\n");
|
||||
}*/
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = 1000;
|
||||
nanosleep(&ts, NULL);
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 1;
|
||||
select(0, NULL, NULL, NULL, &tv);
|
||||
etimer_request_poll();
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
*
|
||||
* 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)
|
||||
{
|
||||
pid_t pid;
|
||||
struct timespec ts;
|
||||
struct timeval tv;
|
||||
static unsigned short port = NODES_PORTBASE;
|
||||
|
||||
pid = fork();
|
||||
|
@ -123,9 +123,9 @@ start_node(int x, int y, int b)
|
|||
|
||||
srand(getpid());
|
||||
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = 1000000 * (rand() % 1000);
|
||||
nanosleep(&ts, NULL);
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 1000 * (rand() % 1000);
|
||||
select(0, NULL, NULL, NULL, &tv);
|
||||
|
||||
node_init(port - NODES_PORTBASE + 2, x, y, b);
|
||||
ethernode_init(port);
|
||||
|
@ -213,10 +213,10 @@ static signed long drift = 0;
|
|||
void
|
||||
clock_delay(unsigned int num)
|
||||
{
|
||||
struct timespec ts;
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = 100000 * num;
|
||||
nanosleep(&ts, NULL);
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 100 * num;
|
||||
select(0, NULL, NULL, NULL, &tv);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
*
|
||||
* 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
|
||||
|
@ -51,7 +51,7 @@
|
|||
#include "lib/random.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <sys/select.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define BUF ((uip_tcpip_hdr *)&uip_buf[HDR_LEN])
|
||||
|
@ -198,7 +198,7 @@ ethernode_send(void)
|
|||
static char tmpbuf[2048];
|
||||
struct hdr *hdr = (struct hdr *)tmpbuf;
|
||||
u8_t dest;
|
||||
struct timespec ts;
|
||||
struct timeval tv;
|
||||
|
||||
if(uip_len > sizeof(tmpbuf)) {
|
||||
PRINTF(("Ethernode_send: too large uip_len %d\n", uip_len));
|
||||
|
@ -209,9 +209,9 @@ ethernode_send(void)
|
|||
len = uip_len + HDR_LEN;
|
||||
|
||||
dest = ID_BROADCAST;
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = 1000 * (random_rand() % 1000);
|
||||
nanosleep(&ts, NULL);
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = (random_rand() % 1000);
|
||||
select(0, NULL, NULL, NULL, &tv);
|
||||
|
||||
do_send(TYPE_DATA, dest, hdr, len);
|
||||
|
||||
|
|
Loading…
Reference in a new issue