raspberrypi / pico-sdk

BSD 3-Clause "New" or "Revised" License
3.28k stars 850 forks source link

`alarm_pool_add_alarm_at` fires when timestamp missed, even if interrupts are disabled #1555

Open yacinbm opened 8 months ago

yacinbm commented 8 months ago

Context I have an application that queues alarms at different timestamps, which can be very small depending on the context. However, before calling alarm_pool_add_alarm_at I disable interrupts with the save_and_disable_interrupts API.

Expected behaviour. When disabling interrupts, I expect that my alarm callback cannot be called until the interrupts are re-enabled. However, in alarm_pool_add_alarm_at(), the callback is called if the timestamp was missed, regardless of state of the interrupts.

Possible Fix In add_alarm_under_lock, when is_missed is true, check the state of the interrupts. If the interrupt level of the alarm is currently blocked, don't remove the entry from the pool and set the timer IRQ. This way, when interrupts are re-enabled, the timer IRQ will fire and the callback will be called without bypassing the interrupt block.

kilograham commented 2 months ago

Planning a new pico_time implementation which should not suffer this problem