Hardy Griech's timer bugfix: avoid direct comparison for timer values since they may wrap. Instead, use the CLOCK_LT() that works correctly even for wrapped timers.
This commit is contained in:
parent
86b835dd2c
commit
9324dc1e7d
2 changed files with 37 additions and 28 deletions
|
@ -53,14 +53,23 @@
|
||||||
*
|
*
|
||||||
* Author: Adam Dunkels <adam@sics.se>
|
* Author: Adam Dunkels <adam@sics.se>
|
||||||
*
|
*
|
||||||
* $Id: clock.h,v 1.6 2008/07/10 17:09:32 adamdunkels Exp $
|
* $Id: clock.h,v 1.7 2008/08/15 19:16:09 adamdunkels Exp $
|
||||||
*/
|
*/
|
||||||
#ifndef __CLOCK_H__
|
#ifndef __CLOCK_H__
|
||||||
#define __CLOCK_H__
|
#define __CLOCK_H__
|
||||||
|
|
||||||
#include "contiki-conf.h"
|
#include "contiki-conf.h"
|
||||||
|
|
||||||
#define CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0)
|
/**
|
||||||
|
* Check if a clock time value is less than another clock time value.
|
||||||
|
*
|
||||||
|
* This macro checks if a clock time value is less than another clock
|
||||||
|
* time value. This macro is needed to correctly handle wrap-around of
|
||||||
|
* clock time values.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define CLOCK_LT(a, b) ((clock_time_t)((a) - (b)) < \
|
||||||
|
((clock_time_t)(~((clock_time_t)0)) >> 1))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the clock library.
|
* Initialize the clock library.
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
*
|
*
|
||||||
* Author: Adam Dunkels <adam@sics.se>
|
* Author: Adam Dunkels <adam@sics.se>
|
||||||
*
|
*
|
||||||
* $Id: timer.c,v 1.2 2007/05/27 11:11:28 oliverschmidt Exp $
|
* $Id: timer.c,v 1.3 2008/08/15 19:16:09 adamdunkels Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "contiki-conf.h"
|
#include "contiki-conf.h"
|
||||||
|
@ -121,7 +121,7 @@ timer_restart(struct timer *t)
|
||||||
int
|
int
|
||||||
timer_expired(struct timer *t)
|
timer_expired(struct timer *t)
|
||||||
{
|
{
|
||||||
return (clock_time_t)(clock_time() - t->start) >= (clock_time_t)t->interval;
|
return CLOCK_LT(clock_time(), t->start + t->interval);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue