Reverted the recent change from random_rand() to rand(). It turned out that

since libc rand() returns a signed int, there were frequently problems with
timer values wrapping. By reverting to random_rand(), we can provide a
random generator that returns an unsigned and the timer problems are solved.
This commit is contained in:
adamdunkels 2009-02-11 11:08:53 +00:00
parent b80d3cfdb9
commit 585620c102
10 changed files with 28 additions and 29 deletions

View file

@ -33,7 +33,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: trickle.c,v 1.14 2009/02/07 16:16:31 adamdunkels Exp $
* $Id: trickle.c,v 1.15 2009/02/11 11:08:56 adamdunkels Exp $
*/
/**
@ -44,7 +44,7 @@
*/
#include "net/rime/trickle.h"
#include "lib/rand.h"
#include "lib/random.h"
#if CONTIKI_TARGET_NETSIM
#include "ether.h"
@ -116,7 +116,7 @@ run_trickle(struct trickle_conn *c)
while(1) {
interval = c->interval << c->interval_scaling;
set_timer(c, &c->interval_timer, interval);
set_timer(c, &c->t, interval / 2 + (rand() % (interval / 2)));
set_timer(c, &c->t, interval / 2 + (random_rand() % (interval / 2)));
c->duplicates = 0;
PT_YIELD(&c->pt); /* Wait until listen timeout */