From d163e8a8ac7e1e8ba758095ae6244544fdce2024 Mon Sep 17 00:00:00 2001 From: Sam Kumar Date: Thu, 30 Mar 2017 16:37:03 -0700 Subject: [PATCH] Fix race condition in _xtimer_set_absolute --- sys/xtimer/xtimer_core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sys/xtimer/xtimer_core.c b/sys/xtimer/xtimer_core.c index c299fac2d561f..6e26356ba70ee 100644 --- a/sys/xtimer/xtimer_core.c +++ b/sys/xtimer/xtimer_core.c @@ -170,20 +170,22 @@ static inline void _lltimer_set(uint32_t target) int _xtimer_set_absolute(xtimer_t *timer, uint32_t target) { - uint32_t now = _xtimer_now(); + uint32_t now; int res = 0; DEBUG("timer_set_absolute(): now=%" PRIu32 " target=%" PRIu32 "\n", now, target); + unsigned state = irq_disable(); timer->next = NULL; + now = _xtimer_now(); if ((target >= now) && ((target - XTIMER_BACKOFF) < now)) { + irq_restore(state); /* backoff */ xtimer_spin_until(target + XTIMER_BACKOFF); _shoot(timer); return 0; } - unsigned state = irq_disable(); if (_is_set(timer)) { _remove(timer); }