Bugfix: should not invoke timer if timer list is empty.
This commit is contained in:
parent
5b3923141f
commit
c4b212898b
1 changed files with 24 additions and 13 deletions
|
@ -28,13 +28,13 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* @(#)$Id: rtimer.c,v 1.2 2007/03/28 20:28:22 adamdunkels Exp $
|
* @(#)$Id: rtimer.c,v 1.3 2007/05/17 00:23:58 adamdunkels Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "sys/rtimer.h"
|
#include "sys/rtimer.h"
|
||||||
#include "contiki.h"
|
#include "contiki.h"
|
||||||
|
|
||||||
#define LIST_SIZE 16
|
#define LIST_SIZE 4
|
||||||
|
|
||||||
static struct rtimer *rtimers[LIST_SIZE];
|
static struct rtimer *rtimers[LIST_SIZE];
|
||||||
static u8_t next, firstempty;
|
static u8_t next, firstempty;
|
||||||
|
@ -78,6 +78,12 @@ rtimer_set(struct rtimer *rtimer, rtimer_clock_t time, rtimer_clock_t duration,
|
||||||
for(i = next; i != firstempty;
|
for(i = next; i != firstempty;
|
||||||
i = (i + 1) % LIST_SIZE) {
|
i = (i + 1) % LIST_SIZE) {
|
||||||
|
|
||||||
|
if(rtimers[i] == rtimer) {
|
||||||
|
/* Check if timer is already scheduled. If so, we do not
|
||||||
|
schedule it again. */
|
||||||
|
return RTIMER_ERR_ALREADY_SCHEDULED;
|
||||||
|
|
||||||
|
}
|
||||||
/* XXX: should check a range of time not just the same precise
|
/* XXX: should check a range of time not just the same precise
|
||||||
moment. */
|
moment. */
|
||||||
if(rtimers[i]->time == time) {
|
if(rtimers[i]->time == time) {
|
||||||
|
@ -89,7 +95,7 @@ rtimer_set(struct rtimer *rtimer, rtimer_clock_t time, rtimer_clock_t duration,
|
||||||
/* Put the rtimer at the end of the rtimer list. */
|
/* Put the rtimer at the end of the rtimer list. */
|
||||||
rtimer->time = time;
|
rtimer->time = time;
|
||||||
rtimers[firstempty] = rtimer;
|
rtimers[firstempty] = rtimer;
|
||||||
PRINTF("rtimer_post: putting rtimer %s as %d\n", rtimer->name, firstempty);
|
PRINTF("rtimer_post: putting rtimer %p as %d\n", rtimer, firstempty);
|
||||||
|
|
||||||
firstempty = (firstempty + 1) % LIST_SIZE;
|
firstempty = (firstempty + 1) % LIST_SIZE;
|
||||||
|
|
||||||
|
@ -100,8 +106,8 @@ rtimer_set(struct rtimer *rtimer, rtimer_clock_t time, rtimer_clock_t duration,
|
||||||
run the rtimer_arch_schedule() function to get the ball rolling. */
|
run the rtimer_arch_schedule() function to get the ball rolling. */
|
||||||
if(firstempty == (next + 1) % LIST_SIZE) {
|
if(firstempty == (next + 1) % LIST_SIZE) {
|
||||||
|
|
||||||
PRINTF("rtimer_set scheduling %d %s (%d)\n",
|
PRINTF("rtimer_set scheduling %d %p (%d)\n",
|
||||||
next, rtimers[next]->name, rtimers[next]->time);
|
next, rtimers[next], rtimers[next]->time);
|
||||||
rtimer_arch_schedule(rtimers[next]->time);
|
rtimer_arch_schedule(rtimers[next]->time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,13 +120,18 @@ rtimer_run_next(void)
|
||||||
int i, n;
|
int i, n;
|
||||||
struct rtimer *t;
|
struct rtimer *t;
|
||||||
|
|
||||||
|
/* Do not run timer if list is empty. */
|
||||||
|
if(next == firstempty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
t = rtimers[next];
|
t = rtimers[next];
|
||||||
|
|
||||||
/* Increase the pointer to the next rtimer. */
|
/* Increase the pointer to the next rtimer. */
|
||||||
next = (next + 1) % LIST_SIZE;
|
next = (next + 1) % LIST_SIZE;
|
||||||
|
|
||||||
/* Run the rtimer. */
|
/* Run the rtimer. */
|
||||||
PRINTF("rtimer_run_next running %s\n", t->name);
|
PRINTF("rtimer_run_next running %p\n", t);
|
||||||
t->func(t, t->ptr);
|
t->func(t, t->ptr);
|
||||||
|
|
||||||
if(next == firstempty) {
|
if(next == firstempty) {
|
||||||
|
@ -132,24 +143,24 @@ rtimer_run_next(void)
|
||||||
/* Find the next rtimer to run. */
|
/* Find the next rtimer to run. */
|
||||||
n = next;
|
n = next;
|
||||||
for(i = next; i != firstempty; i = (i + 1) % LIST_SIZE) {
|
for(i = next; i != firstempty; i = (i + 1) % LIST_SIZE) {
|
||||||
PRINTF("rtimer_run_next checking %s (%d) against %s (%d)\n",
|
PRINTF("rtimer_run_next checking %p (%d) against %p (%d)\n",
|
||||||
rtimers[i]->name, rtimers[i]->time,
|
rtimers[i], rtimers[i]->time,
|
||||||
rtimers[n]->name, rtimers[n]->time);
|
rtimers[n], rtimers[n]->time);
|
||||||
if(RTIMER_CLOCK_LT(rtimers[i]->time, rtimers[n]->time)) {
|
if(RTIMER_CLOCK_LT(rtimers[i]->time, rtimers[n]->time)) {
|
||||||
n = i;
|
n = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PRINTF("rtimer_run_next next rtimer is %d %s (%d)\n",
|
PRINTF("rtimer_run_next next rtimer is %d %p (%d)\n",
|
||||||
n, rtimers[n]->name, rtimers[n]->time);
|
n, rtimers[n], rtimers[n]->time);
|
||||||
|
|
||||||
/* Put the next rtimer first in the rtimer list. */
|
/* Put the next rtimer first in the rtimer list. */
|
||||||
t = rtimers[next];
|
t = rtimers[next];
|
||||||
rtimers[next] = rtimers[n];
|
rtimers[next] = rtimers[n];
|
||||||
rtimers[n] = t;
|
rtimers[n] = t;
|
||||||
|
|
||||||
PRINTF("rtimer_run_next scheduling %d %s (%d)\n",
|
PRINTF("rtimer_run_next scheduling %d %p (%d)\n",
|
||||||
next, rtimers[next]->name, rtimers[next]->time);
|
next, rtimers[next], rtimers[next]->time);
|
||||||
|
|
||||||
rtimer_arch_schedule(rtimers[next]->time);
|
rtimer_arch_schedule(rtimers[next]->time);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue