Merge pull request #263 from WeirdConstructor/fix_alarm_schedule_race_cond

Fix alarm schedule race condition
This commit is contained in:
Jonathan 'theJPster' Pallant 2022-01-12 20:07:59 +00:00 committed by GitHub
commit d3c9c3b4e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -249,6 +249,7 @@ macro_rules! impl_alarm {
if duration < MIN_MICROSECONDS {
return Err(ScheduleAlarmError::AlarmTooSoon);
} else {
cortex_m::interrupt::free(|_| {
// safety: This is a read action and should not have any UB
let target_time = unsafe { &*TIMER::ptr() }
.timelr
@ -260,6 +261,7 @@ macro_rules! impl_alarm {
unsafe { &*TIMER::ptr() }
.$timer_alarm
.write(|w| unsafe { w.bits(target_time) });
});
Ok(())
}
}