From fa7219d0b8ebb012e7f785a08d8b9f0a50bd0828 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 28 Aug 2013 13:22:35 +0100 Subject: [PATCH 1/3] Add a way to determine whether a trickle timer is running --- core/lib/trickle-timer.h | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/core/lib/trickle-timer.h b/core/lib/trickle-timer.h index d32a3358e..042f434c0 100644 --- a/core/lib/trickle-timer.h +++ b/core/lib/trickle-timer.h @@ -111,6 +111,16 @@ */ #define TRICKLE_TIMER_TX_SUPPRESS 0 #define TRICKLE_TIMER_TX_OK 1 + +/** + * \brief A trickle timer is considered 'stopped' when + * i_cur == TRICKLE_TIMER_IS_STOPPED. + * + * trickle_timer_stop() must be used to correctly disable a trickle timer. + * Do NOT set the value of i_cur to 0 directly, as this will fail to stop the + * timer. + */ +#define TRICKLE_TIMER_IS_STOPPED 0 /** @} */ /*---------------------------------------------------------------------------*/ /** @@ -437,7 +447,10 @@ uint8_t trickle_timer_set(struct trickle_timer *tt, * to reset a timer manually. Instead, in response to events or inconsistencies, * the corresponding functions must be used */ -#define trickle_timer_stop(tt) ctimer_stop(&((tt)->ct)) +#define trickle_timer_stop(tt) do { \ + ctimer_stop(&((tt)->ct)); \ + (tt)->i_cur = 0; \ +} while(0) /** * \brief To be called by the protocol when it hears a consistent @@ -484,6 +497,16 @@ void trickle_timer_inconsistency(struct trickle_timer *tt); */ #define trickle_timer_reset_event(tt) trickle_timer_inconsistency(tt) +/** + * \brief To be called in order to determine whether a trickle timer is + * running + * \param tt A pointer to a ::trickle_timer structure + * \retval 0 The timer is stopped + * \retval non-zero The timer is running + * + */ +#define trickle_timer_is_running(tt) ((tt)->i_cur != TRICKLE_TIMER_IS_STOPPED) + /** @} */ #endif /* __TRICKLE_TIMER_H__ */ From 995a9c92d91dc91c91b0e55f2eb8572f8a344c16 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 28 Aug 2013 13:26:04 +0100 Subject: [PATCH 2/3] Only schedule a trickle interval doubling for running timers --- core/lib/trickle-timer.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/lib/trickle-timer.c b/core/lib/trickle-timer.c index 1297fdb4d..97a620767 100644 --- a/core/lib/trickle-timer.c +++ b/core/lib/trickle-timer.c @@ -276,7 +276,9 @@ fire(void *ptr) loctt->cb(loctt->cb_arg, TRICKLE_TIMER_PROTO_TX_ALLOW(loctt)); } - schedule_for_end(loctt); + if(trickle_timer_is_running(loctt)) { + schedule_for_end(loctt); + } } /*---------------------------------------------------------------------------*/ /* New trickle interval, either due to a newly set trickle timer or due to an From 060b00c4b50837fa7b5490aabff4d80f7c930bfd Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Mon, 30 Sep 2013 12:37:01 +0100 Subject: [PATCH 3/3] Use TRICKLE_TIMER_IS_STOPPED in trickle_timer_stop() --- core/lib/trickle-timer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/lib/trickle-timer.h b/core/lib/trickle-timer.h index 042f434c0..dedee3301 100644 --- a/core/lib/trickle-timer.h +++ b/core/lib/trickle-timer.h @@ -449,7 +449,7 @@ uint8_t trickle_timer_set(struct trickle_timer *tt, */ #define trickle_timer_stop(tt) do { \ ctimer_stop(&((tt)->ct)); \ - (tt)->i_cur = 0; \ + (tt)->i_cur = TRICKLE_TIMER_IS_STOPPED; \ } while(0) /**