Skip to content

Commit

Permalink
core/hwtimer: disable interrupts in hwtimer_remove
Browse files Browse the repository at this point in the history
Before only the hardware timer's own interrupt was being disabled.
This led to a race condition in the following scenario:

```
Thread1:
    hwtimer_remove()
    hwtimer_arch_disable_interrupt();

// INTERRUPT -> Thread2 (which has a higher priority than Thread1) gets scheduled

Thread2:
    ...
    hwtimer_remove()
    hwtimer_arch_disable_interrupt(); // hwtimer interrupt is already disabled
    ...
    hwtimer_arch_enable_interrupt();
    ...
   // yield | terminate -> Thread1 gets scheduled again

Thread1:
    ... // these instructions are being run with the hwtimer interrupt enabled
    hwtimer_arch_enable_interrupt(); // hwtimer interrupt is already enabled
```

Fixes #924
  • Loading branch information
LudwigKnuepfer committed May 16, 2014
1 parent 988de6b commit 9d4a920
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions core/hwtimer.c
Expand Up @@ -202,14 +202,16 @@ int hwtimer_set_absolute(unsigned long offset, void (*callback)(void*), void *pt
int hwtimer_remove(int n)
{
DEBUG("hwtimer_remove n=%d\n", n);
hwtimer_arch_disable_interrupt();

int state = disableIRQ();
hwtimer_arch_unset(n);

lifo_insert(lifo, n);
timer[n].callback = NULL;

lpm_prevent_sleep--;

hwtimer_arch_enable_interrupt();
restoreIRQ(state);

return 1;
}

0 comments on commit 9d4a920

Please sign in to comment.