Remove unnecessary cortex_m::interrupt::free in timer.rs (#402)

The only thing accessed by those methods is `&mut self`, which is
guaranteed to be a unique reference. So an interrupt can not
interfere with the correctness of the operation.
This commit is contained in:
Jan Niehusmann 2022-07-28 02:26:24 +02:00 committed by GitHub
parent c7acafda3c
commit 6e325ba099
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -60,50 +60,42 @@ impl Timer {
/// Retrieve a reference to alarm 0. Will only return a value the first time this is called /// Retrieve a reference to alarm 0. Will only return a value the first time this is called
pub fn alarm_0(&mut self) -> Option<Alarm0> { pub fn alarm_0(&mut self) -> Option<Alarm0> {
cortex_m::interrupt::free(|_| { if self.alarms[0] {
if self.alarms[0] { self.alarms[0] = false;
self.alarms[0] = false; Some(Alarm0(PhantomData))
Some(Alarm0(PhantomData)) } else {
} else { None
None }
}
})
} }
/// Retrieve a reference to alarm 1. Will only return a value the first time this is called /// Retrieve a reference to alarm 1. Will only return a value the first time this is called
pub fn alarm_1(&mut self) -> Option<Alarm1> { pub fn alarm_1(&mut self) -> Option<Alarm1> {
cortex_m::interrupt::free(|_| { if self.alarms[1] {
if self.alarms[1] { self.alarms[1] = false;
self.alarms[1] = false; Some(Alarm1(PhantomData))
Some(Alarm1(PhantomData)) } else {
} else { None
None }
}
})
} }
/// Retrieve a reference to alarm 2. Will only return a value the first time this is called /// Retrieve a reference to alarm 2. Will only return a value the first time this is called
pub fn alarm_2(&mut self) -> Option<Alarm2> { pub fn alarm_2(&mut self) -> Option<Alarm2> {
cortex_m::interrupt::free(|_| { if self.alarms[2] {
if self.alarms[2] { self.alarms[2] = false;
self.alarms[2] = false; Some(Alarm2(PhantomData))
Some(Alarm2(PhantomData)) } else {
} else { None
None }
}
})
} }
/// Retrieve a reference to alarm 3. Will only return a value the first time this is called /// Retrieve a reference to alarm 3. Will only return a value the first time this is called
pub fn alarm_3(&mut self) -> Option<Alarm3> { pub fn alarm_3(&mut self) -> Option<Alarm3> {
cortex_m::interrupt::free(|_| { if self.alarms[3] {
if self.alarms[3] { self.alarms[3] = false;
self.alarms[3] = false; Some(Alarm3(PhantomData))
Some(Alarm3(PhantomData)) } else {
} else { None
None }
}
})
} }
} }