aboutsummaryrefslogtreecommitdiff
path: root/embassy-time/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-10-26 20:02:58 +0200
committerDario Nieuwenhuis <[email protected]>2022-10-26 20:02:58 +0200
commit4976cbbe6040d5e147e7c42bd29b72d6223b05b0 (patch)
treede40bd215475bed247ee76b20c3b498c5b66487d /embassy-time/src
parent560eecdb737642e6aba132408039195c7d6b6dd8 (diff)
time/generic-queue: ensure queue goes in .bss instead of .data
Diffstat (limited to 'embassy-time/src')
-rw-r--r--embassy-time/src/queue_generic.rs38
1 files changed, 18 insertions, 20 deletions
diff --git a/embassy-time/src/queue_generic.rs b/embassy-time/src/queue_generic.rs
index 6769d6a58..8a355b327 100644
--- a/embassy-time/src/queue_generic.rs
+++ b/embassy-time/src/queue_generic.rs
@@ -57,19 +57,11 @@ impl Ord for Timer {
57 57
58struct InnerQueue { 58struct InnerQueue {
59 queue: SortedLinkedList<Timer, LinkedIndexU8, Min, { QUEUE_SIZE }>, 59 queue: SortedLinkedList<Timer, LinkedIndexU8, Min, { QUEUE_SIZE }>,
60 alarm: Option<AlarmHandle>, 60 alarm: AlarmHandle,
61 alarm_at: Instant, 61 alarm_at: Instant,
62} 62}
63 63
64impl InnerQueue { 64impl InnerQueue {
65 const fn new() -> Self {
66 Self {
67 queue: SortedLinkedList::new_u8(),
68 alarm: None,
69 alarm_at: Instant::MAX,
70 }
71 }
72
73 fn schedule_wake(&mut self, at: Instant, waker: &Waker) { 65 fn schedule_wake(&mut self, at: Instant, waker: &Waker) {
74 self.queue 66 self.queue
75 .find_mut(|timer| timer.waker.will_wake(waker)) 67 .find_mut(|timer| timer.waker.will_wake(waker))
@@ -121,7 +113,7 @@ impl InnerQueue {
121 if self.alarm_at != new_at { 113 if self.alarm_at != new_at {
122 self.alarm_at = new_at; 114 self.alarm_at = new_at;
123 115
124 return set_alarm(self.alarm.unwrap(), self.alarm_at.as_ticks()); 116 return set_alarm(self.alarm, self.alarm_at.as_ticks());
125 } 117 }
126 } else { 118 } else {
127 self.alarm_at = Instant::MAX; 119 self.alarm_at = Instant::MAX;
@@ -138,13 +130,13 @@ impl InnerQueue {
138} 130}
139 131
140struct Queue { 132struct Queue {
141 inner: Mutex<CriticalSectionRawMutex, RefCell<InnerQueue>>, 133 inner: Mutex<CriticalSectionRawMutex, RefCell<Option<InnerQueue>>>,
142} 134}
143 135
144impl Queue { 136impl Queue {
145 const fn new() -> Self { 137 const fn new() -> Self {
146 Self { 138 Self {
147 inner: Mutex::new(RefCell::new(InnerQueue::new())), 139 inner: Mutex::new(RefCell::new(None)),
148 } 140 }
149 } 141 }
150 142
@@ -152,19 +144,25 @@ impl Queue {
152 self.inner.lock(|inner| { 144 self.inner.lock(|inner| {
153 let mut inner = inner.borrow_mut(); 145 let mut inner = inner.borrow_mut();
154 146
155 if inner.alarm.is_none() { 147 if inner.is_none() {}
156 let handle = unsafe { allocate_alarm() }.unwrap();
157 inner.alarm = Some(handle);
158
159 set_alarm_callback(handle, Self::handle_alarm_callback, self as *const _ as _);
160 }
161 148
162 inner.schedule_wake(at, waker) 149 inner
150 .get_or_insert_with(|| {
151 let handle = unsafe { allocate_alarm() }.unwrap();
152 set_alarm_callback(handle, Self::handle_alarm_callback, self as *const _ as _);
153 InnerQueue {
154 queue: SortedLinkedList::new_u8(),
155 alarm: handle,
156 alarm_at: Instant::MAX,
157 }
158 })
159 .schedule_wake(at, waker)
163 }); 160 });
164 } 161 }
165 162
166 fn handle_alarm(&self) { 163 fn handle_alarm(&self) {
167 self.inner.lock(|inner| inner.borrow_mut().handle_alarm()); 164 self.inner
165 .lock(|inner| inner.borrow_mut().as_mut().unwrap().handle_alarm());
168 } 166 }
169 167
170 fn handle_alarm_callback(ctx: *mut ()) { 168 fn handle_alarm_callback(ctx: *mut ()) {