time/generic-queue: ensure queue goes in .bss instead of .data

This commit is contained in:
Dario Nieuwenhuis 2022-10-26 20:02:58 +02:00
parent 560eecdb73
commit 4976cbbe60

View File

@ -57,19 +57,11 @@ impl Ord for Timer {
struct InnerQueue { struct InnerQueue {
queue: SortedLinkedList<Timer, LinkedIndexU8, Min, { QUEUE_SIZE }>, queue: SortedLinkedList<Timer, LinkedIndexU8, Min, { QUEUE_SIZE }>,
alarm: Option<AlarmHandle>, alarm: AlarmHandle,
alarm_at: Instant, alarm_at: Instant,
} }
impl InnerQueue { impl InnerQueue {
const fn new() -> Self {
Self {
queue: SortedLinkedList::new_u8(),
alarm: None,
alarm_at: Instant::MAX,
}
}
fn schedule_wake(&mut self, at: Instant, waker: &Waker) { fn schedule_wake(&mut self, at: Instant, waker: &Waker) {
self.queue self.queue
.find_mut(|timer| timer.waker.will_wake(waker)) .find_mut(|timer| timer.waker.will_wake(waker))
@ -121,7 +113,7 @@ impl InnerQueue {
if self.alarm_at != new_at { if self.alarm_at != new_at {
self.alarm_at = new_at; self.alarm_at = new_at;
return set_alarm(self.alarm.unwrap(), self.alarm_at.as_ticks()); return set_alarm(self.alarm, self.alarm_at.as_ticks());
} }
} else { } else {
self.alarm_at = Instant::MAX; self.alarm_at = Instant::MAX;
@ -138,13 +130,13 @@ impl InnerQueue {
} }
struct Queue { struct Queue {
inner: Mutex<CriticalSectionRawMutex, RefCell<InnerQueue>>, inner: Mutex<CriticalSectionRawMutex, RefCell<Option<InnerQueue>>>,
} }
impl Queue { impl Queue {
const fn new() -> Self { const fn new() -> Self {
Self { Self {
inner: Mutex::new(RefCell::new(InnerQueue::new())), inner: Mutex::new(RefCell::new(None)),
} }
} }
@ -152,19 +144,25 @@ impl Queue {
self.inner.lock(|inner| { self.inner.lock(|inner| {
let mut inner = inner.borrow_mut(); let mut inner = inner.borrow_mut();
if inner.alarm.is_none() { if inner.is_none() {}
let handle = unsafe { allocate_alarm() }.unwrap();
inner.alarm = Some(handle);
set_alarm_callback(handle, Self::handle_alarm_callback, self as *const _ as _); inner
} .get_or_insert_with(|| {
let handle = unsafe { allocate_alarm() }.unwrap();
inner.schedule_wake(at, waker) set_alarm_callback(handle, Self::handle_alarm_callback, self as *const _ as _);
InnerQueue {
queue: SortedLinkedList::new_u8(),
alarm: handle,
alarm_at: Instant::MAX,
}
})
.schedule_wake(at, waker)
}); });
} }
fn handle_alarm(&self) { fn handle_alarm(&self) {
self.inner.lock(|inner| inner.borrow_mut().handle_alarm()); self.inner
.lock(|inner| inner.borrow_mut().as_mut().unwrap().handle_alarm());
} }
fn handle_alarm_callback(ctx: *mut ()) { fn handle_alarm_callback(ctx: *mut ()) {