From 09046f98a8aef21c8ee96c2f17f50da920b2f087 Mon Sep 17 00:00:00 2001 From: Elena Frank Date: Thu, 2 May 2024 09:45:41 +0200 Subject: [PATCH] runqueue: use newtypes for ids --- src/riot-rs-embassy/src/blocker.rs | 4 +- src/riot-rs-runqueue/src/lib.rs | 92 ++++++------ src/riot-rs-runqueue/src/runqueue.rs | 178 ++++++++++++----------- src/riot-rs-threads/src/arch/cortex_m.rs | 6 +- src/riot-rs-threads/src/lib.rs | 21 +-- src/riot-rs-threads/src/thread.rs | 4 +- src/riot-rs-threads/src/threadlist.rs | 4 +- 7 files changed, 164 insertions(+), 145 deletions(-) diff --git a/src/riot-rs-embassy/src/blocker.rs b/src/riot-rs-embassy/src/blocker.rs index 25ab9b4dc..21e49455c 100644 --- a/src/riot-rs-embassy/src/blocker.rs +++ b/src/riot-rs-embassy/src/blocker.rs @@ -7,7 +7,7 @@ const THREAD_FLAG_WAKER: ThreadFlags = 1; // TODO: find more appropriate value fn wake(ptr: *const ()) { // wake - let thread_id = ptr as usize as ThreadId; + let thread_id = ThreadId(ptr as usize as u8); flags::set(thread_id, THREAD_FLAG_WAKER); } @@ -24,7 +24,7 @@ pub fn block_on(mut fut: F) -> F::Output { // safety: we don't move the future after this line. let mut fut = unsafe { Pin::new_unchecked(&mut fut) }; - let raw_waker = RawWaker::new(current_pid().unwrap() as usize as *const (), &VTABLE); + let raw_waker = RawWaker::new(usize::from(current_pid().unwrap()) as *const (), &VTABLE); let waker = unsafe { Waker::from_raw(raw_waker) }; let mut cx = Context::from_waker(&waker); loop { diff --git a/src/riot-rs-runqueue/src/lib.rs b/src/riot-rs-runqueue/src/lib.rs index 4112f4862..9817205b8 100644 --- a/src/riot-rs-runqueue/src/lib.rs +++ b/src/riot-rs-runqueue/src/lib.rs @@ -11,28 +11,28 @@ mod tests { fn test_rq_basic() { let mut runqueue: RunQueue<8, 32> = RunQueue::new(); - runqueue.add(0, 0); - runqueue.add(1, 0); - runqueue.add(2, 0); + runqueue.add(ThreadId(0), RunqueueId(0)); + runqueue.add(ThreadId(1), RunqueueId(0)); + runqueue.add(ThreadId(2), RunqueueId(0)); - assert_eq!(runqueue.get_next(), Some(0)); + assert_eq!(runqueue.get_next(), Some(ThreadId(0))); - runqueue.advance(0); + runqueue.advance(RunqueueId(0)); - assert_eq!(runqueue.get_next(), Some(1)); - runqueue.advance(0); + assert_eq!(runqueue.get_next(), Some(ThreadId(1))); + runqueue.advance(RunqueueId(0)); - assert_eq!(runqueue.get_next(), Some(2)); - assert_eq!(runqueue.get_next(), Some(2)); + assert_eq!(runqueue.get_next(), Some(ThreadId(2))); + assert_eq!(runqueue.get_next(), Some(ThreadId(2))); - runqueue.advance(0); - assert_eq!(runqueue.get_next(), Some(0)); + runqueue.advance(RunqueueId(0)); + assert_eq!(runqueue.get_next(), Some(ThreadId(0))); - runqueue.advance(0); - assert_eq!(runqueue.get_next(), Some(1)); + runqueue.advance(RunqueueId(0)); + assert_eq!(runqueue.get_next(), Some(ThreadId(1))); - runqueue.advance(0); - assert_eq!(runqueue.get_next(), Some(2)); + runqueue.advance(RunqueueId(0)); + assert_eq!(runqueue.get_next(), Some(ThreadId(2))); } #[test] @@ -40,17 +40,17 @@ mod tests { let mut runqueue: RunQueue<8, 32> = RunQueue::new(); for i in 0..=31 { - runqueue.add(i, 0); + runqueue.add(ThreadId(i), RunqueueId(0)); } for i in 0..=31 { - assert_eq!(runqueue.get_next(), Some(i)); - runqueue.advance(0); + assert_eq!(runqueue.get_next(), Some(ThreadId(i))); + runqueue.advance(RunqueueId(0)); } for i in 0..=31 { - assert_eq!(runqueue.get_next(), Some(i)); - runqueue.advance(0); + assert_eq!(runqueue.get_next(), Some(ThreadId(i))); + runqueue.advance(RunqueueId(0)); } } @@ -58,41 +58,41 @@ mod tests { fn test_rq_basic_twoprio() { let mut runqueue: RunQueue<8, 32> = RunQueue::new(); - runqueue.add(0, 0); - runqueue.add(1, 0); - runqueue.add(3, 0); - - runqueue.add(2, 1); - runqueue.add(4, 1); - - assert_eq!(runqueue.get_next(), Some(2)); - runqueue.del(2, 1); - assert_eq!(runqueue.get_next(), Some(4)); - runqueue.del(4, 1); - assert_eq!(runqueue.get_next(), Some(0)); - runqueue.del(0, 0); - assert_eq!(runqueue.get_next(), Some(1)); - runqueue.del(1, 0); - assert_eq!(runqueue.get_next(), Some(3)); - runqueue.del(3, 0); + runqueue.add(ThreadId(0), RunqueueId(0)); + runqueue.add(ThreadId(1), RunqueueId(0)); + runqueue.add(ThreadId(3), RunqueueId(0)); + + runqueue.add(ThreadId(2), RunqueueId(1)); + runqueue.add(ThreadId(4), RunqueueId(1)); + + assert_eq!(runqueue.get_next(), Some(ThreadId(2))); + runqueue.del(ThreadId(2), RunqueueId(1)); + assert_eq!(runqueue.get_next(), Some(ThreadId(4))); + runqueue.del(ThreadId(4), RunqueueId(1)); + assert_eq!(runqueue.get_next(), Some(ThreadId(0))); + runqueue.del(ThreadId(0), RunqueueId(0)); + assert_eq!(runqueue.get_next(), Some(ThreadId(1))); + runqueue.del(ThreadId(1), RunqueueId(0)); + assert_eq!(runqueue.get_next(), Some(ThreadId(3))); + runqueue.del(ThreadId(3), RunqueueId(0)); assert_eq!(runqueue.get_next(), None); } #[test] fn test_push_twice() { let mut runqueue: RunQueue<8, 32> = RunQueue::new(); - runqueue.add(0, 0); - runqueue.add(1, 0); + runqueue.add(ThreadId(0), RunqueueId(0)); + runqueue.add(ThreadId(1), RunqueueId(0)); - assert_eq!(runqueue.get_next(), Some(0)); - runqueue.del(0, 0); - assert_eq!(runqueue.get_next(), Some(1)); + assert_eq!(runqueue.get_next(), Some(ThreadId(0))); + runqueue.del(ThreadId(0), RunqueueId(0)); + assert_eq!(runqueue.get_next(), Some(ThreadId(1))); - runqueue.add(0, 0); + runqueue.add(ThreadId(0), RunqueueId(0)); - assert_eq!(runqueue.get_next(), Some(1)); + assert_eq!(runqueue.get_next(), Some(ThreadId(1))); - runqueue.advance(0); - assert_eq!(runqueue.get_next(), Some(0)); + runqueue.advance(RunqueueId(0)); + assert_eq!(runqueue.get_next(), Some(ThreadId(0))); } } diff --git a/src/riot-rs-runqueue/src/runqueue.rs b/src/riot-rs-runqueue/src/runqueue.rs index 80581931f..657bc11e3 100644 --- a/src/riot-rs-runqueue/src/runqueue.rs +++ b/src/riot-rs-runqueue/src/runqueue.rs @@ -8,8 +8,23 @@ use self::clist::CList; const USIZE_BITS: usize = mem::size_of::() * 8; /// Runqueue number. -pub type RunqueueId = u8; -pub type ThreadId = u8; +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] +pub struct RunqueueId(pub u8); + +impl From for usize { + fn from(value: RunqueueId) -> Self { + usize::from(value.0) + } +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] +pub struct ThreadId(pub u8); + +impl From for usize { + fn from(value: ThreadId) -> Self { + usize::from(value.0) + } +} /// Runqueue for `N_QUEUES`, supporting `N_THREADS` total. /// @@ -46,9 +61,9 @@ impl RunQueue<{ N_QUEUES }, { N_T /// Adds thread with pid `n` to runqueue number `rq`. pub fn add(&mut self, n: ThreadId, rq: RunqueueId) { - debug_assert!((n as usize) < N_THREADS); - debug_assert!((rq as usize) < N_QUEUES); - self.bitcache |= 1 << rq; + debug_assert!(usize::from(n) < N_THREADS); + debug_assert!(usize::from(rq) < N_QUEUES); + self.bitcache |= 1 << rq.0; self.queues.push(n, rq); } @@ -59,30 +74,28 @@ impl RunQueue<{ N_QUEUES }, { N_T /// Panics if `n` is not the queue's head. /// This is fine, RIOT-rs only ever calls `del()` for the current thread. pub fn del(&mut self, n: ThreadId, rq: RunqueueId) { - debug_assert!((n as usize) < N_THREADS); - debug_assert!((rq as usize) < N_QUEUES); + debug_assert!(usize::from(n) < N_THREADS); + debug_assert!(usize::from(rq) < N_QUEUES); let popped = self.queues.pop_head(rq); // assert_eq!(popped, Some(n)); if self.queues.is_empty(rq) { - self.bitcache &= !(1 << rq); + self.bitcache &= !(1 << rq.0); } } - fn ffs(val: usize) -> u32 { - USIZE_BITS as u32 - val.leading_zeros() + fn ffs(val: usize) -> u8 { + (USIZE_BITS as u32 - val.leading_zeros()) as u8 } /// Returns the pid that should run next. /// /// Returns the next runnable thread of /// the runqueue with the highest index. - // - // TODO: Return `ThreadId` instead of u8? - pub fn get_next(&self) -> Option { + pub fn get_next(&self) -> Option { let rq_ffs = Self::ffs(self.bitcache); if rq_ffs > 0 { - let rq = (rq_ffs - 1) as RunqueueId; + let rq = RunqueueId(rq_ffs - 1); self.queues.peek_head(rq) } else { None @@ -93,7 +106,7 @@ impl RunQueue<{ N_QUEUES }, { N_T /// /// This is used to "yield" to another thread of *the same* priority. pub fn advance(&mut self, rq: RunqueueId) { - debug_assert!((rq as usize) < N_QUEUES); + debug_assert!((usize::from(rq)) < N_QUEUES); self.queues.advance(rq) } } @@ -107,8 +120,8 @@ mod clist { #[derive(Debug, Copy, Clone)] pub struct CList { - tail: [u8; N_QUEUES], - next_idxs: [u8; N_THREADS], + tail: [ThreadId; N_QUEUES], + next_idxs: [ThreadId; N_THREADS], } impl CList { @@ -121,67 +134,70 @@ mod clist { } } - pub const fn sentinel() -> u8 { - 0xFF + pub const fn sentinel() -> ThreadId { + ThreadId(0xFF) } pub fn is_empty(&self, rq: RunqueueId) -> bool { - self.tail[rq as usize] == Self::sentinel() + self.tail[usize::from(rq)] == Self::sentinel() } pub fn push(&mut self, n: ThreadId, rq: RunqueueId) { assert!(n < Self::sentinel()); - if self.next_idxs[n as usize] == Self::sentinel() { - if self.tail[rq as usize] == Self::sentinel() { + if self.next_idxs[usize::from(n)] == Self::sentinel() { + if self.tail[usize::from(rq)] == Self::sentinel() { // rq is empty, link both tail and n.next to n - self.tail[rq as usize] = n; - self.next_idxs[n as usize] = n; + self.tail[usize::from(rq)] = n; + self.next_idxs[usize::from(n)] = n; } else { // rq has an entry already, so // 1. n.next = old_tail.next ("first" in list) - self.next_idxs[n as usize] = self.next_idxs[self.tail[rq as usize] as usize]; + self.next_idxs[usize::from(n)] = + self.next_idxs[usize::from(self.tail[usize::from(rq)])]; // 2. old_tail.next = n - self.next_idxs[self.tail[rq as usize] as usize] = n; + self.next_idxs[usize::from(self.tail[usize::from(rq)])] = n; // 3. tail = n - self.tail[rq as usize] = n; + self.tail[usize::from(rq)] = n; } } } - pub fn pop_head(&mut self, rq: RunqueueId) -> Option { - if self.tail[rq as usize] == Self::sentinel() { + pub fn pop_head(&mut self, rq: RunqueueId) -> Option { + if self.tail[usize::from(rq)] == Self::sentinel() { // rq is empty, do nothing None } else { - let head = self.next_idxs[self.tail[rq as usize] as usize]; - if head == self.tail[rq as usize] { + let head = self.next_idxs[usize::from(self.tail[usize::from(rq)])]; + if head == self.tail[usize::from(rq)] { // rq's tail bites itself, so there's only one entry. // so, clear tail. - self.tail[rq as usize] = Self::sentinel(); + self.tail[usize::from(rq)] = Self::sentinel(); // rq is now empty } else { // rq has multiple entries, // so set tail.next to head.next (second in list) - self.next_idxs[self.tail[rq as usize] as usize] = self.next_idxs[head as usize]; + self.next_idxs[usize::from(self.tail[usize::from(rq)])] = + self.next_idxs[usize::from(head)]; } // now clear head's next value - self.next_idxs[head as usize] = Self::sentinel(); + self.next_idxs[usize::from(head)] = Self::sentinel(); Some(head) } } - pub fn peek_head(&self, rq: RunqueueId) -> Option { - if self.tail[rq as usize] == Self::sentinel() { + pub fn peek_head(&self, rq: RunqueueId) -> Option { + if self.tail[usize::from(rq)] == Self::sentinel() { None } else { - Some(self.next_idxs[self.tail[rq as usize] as usize]) + Some(self.next_idxs[usize::from(self.tail[usize::from(rq)])]) } } pub fn advance(&mut self, rq: RunqueueId) { - if self.tail[rq as usize] != Self::sentinel() { - self.tail[rq as usize] = self.next_idxs[self.tail[rq as usize] as usize]; + if self.tail[usize::from(rq)] != Self::sentinel() { + self.tail[usize::from(rq)] = + self.next_idxs[usize::from(self.tail[usize::from(rq)])]; } } } @@ -193,80 +209,80 @@ mod clist { #[test] fn test_clist_basic() { let mut clist: CList<8, 32> = CList::new(); - assert!(clist.is_empty(0)); - clist.push(0, 0); - assert_eq!(clist.pop_head(0), Some(0)); - assert_eq!(clist.pop_head(0), None); + assert!(clist.is_empty(RunqueueId(0))); + clist.push(ThreadId(0), RunqueueId(0)); + assert_eq!(clist.pop_head(RunqueueId(0)), Some(ThreadId(0))); + assert_eq!(clist.pop_head(RunqueueId(0)), None); } #[test] fn test_clist_push_already_in_list() { let mut clist: CList<8, 32> = CList::new(); - assert!(clist.is_empty(0)); - clist.push(0, 0); - clist.push(0, 0); - assert_eq!(clist.pop_head(0), Some(0)); - assert_eq!(clist.pop_head(0), None); - assert!(clist.is_empty(0)); + assert!(clist.is_empty(RunqueueId(0))); + clist.push(ThreadId(0), RunqueueId(0)); + clist.push(ThreadId(0), RunqueueId(0)); + assert_eq!(clist.pop_head(RunqueueId(0)), Some(ThreadId(0))); + assert_eq!(clist.pop_head(RunqueueId(0)), None); + assert!(clist.is_empty(RunqueueId(0))); } #[test] fn test_clist_push_two() { let mut clist: CList<8, 32> = CList::new(); - assert!(clist.is_empty(0)); - clist.push(0, 0); - clist.push(1, 0); - assert_eq!(clist.pop_head(0), Some(0)); - assert_eq!(clist.pop_head(0), Some(1)); - assert_eq!(clist.pop_head(0), None); - assert!(clist.is_empty(0)); + assert!(clist.is_empty(RunqueueId(0))); + clist.push(ThreadId(0), RunqueueId(0)); + clist.push(ThreadId(1), RunqueueId(0)); + assert_eq!(clist.pop_head(RunqueueId(0)), Some(ThreadId(0))); + assert_eq!(clist.pop_head(RunqueueId(0)), Some(ThreadId(1))); + assert_eq!(clist.pop_head(RunqueueId(0)), None); + assert!(clist.is_empty(RunqueueId(0))); } #[test] fn test_clist_push_all() { const N: usize = 255; let mut clist: CList<8, N> = CList::new(); - assert!(clist.is_empty(0)); + assert!(clist.is_empty(RunqueueId(0))); for i in 0..(N - 1) { println!("pushing {}", i); - clist.push(i as u8, 0); + clist.push(ThreadId(i as u8), RunqueueId(0)); } for i in 0..(N - 1) { println!("{}", i); - assert_eq!(clist.pop_head(0), Some(i as u8)); + assert_eq!(clist.pop_head(RunqueueId(0)), Some(ThreadId(i as u8))); } - assert_eq!(clist.pop_head(0), None); - assert!(clist.is_empty(0)); + assert_eq!(clist.pop_head(RunqueueId(0)), None); + assert!(clist.is_empty(RunqueueId(0))); } #[test] fn test_clist_advance() { let mut clist: CList<8, 32> = CList::new(); - assert!(clist.is_empty(0)); - clist.push(0, 0); - clist.push(1, 0); - clist.advance(0); - assert_eq!(clist.pop_head(0), Some(1)); - assert_eq!(clist.pop_head(0), Some(0)); - assert_eq!(clist.pop_head(0), None); - assert!(clist.is_empty(0)); + assert!(clist.is_empty(RunqueueId(0))); + clist.push(ThreadId(0), RunqueueId(0)); + clist.push(ThreadId(1), RunqueueId(0)); + clist.advance(RunqueueId(0)); + assert_eq!(clist.pop_head(RunqueueId(0)), Some(ThreadId(1))); + assert_eq!(clist.pop_head(RunqueueId(0)), Some(ThreadId(0))); + assert_eq!(clist.pop_head(RunqueueId(0)), None); + assert!(clist.is_empty(RunqueueId(0))); } #[test] fn test_clist_peek_head() { let mut clist: CList<8, 32> = CList::new(); - assert!(clist.is_empty(0)); - clist.push(0, 0); - clist.push(1, 0); - assert_eq!(clist.peek_head(0), Some(0)); - assert_eq!(clist.peek_head(0), Some(0)); - assert_eq!(clist.pop_head(0), Some(0)); - assert_eq!(clist.peek_head(0), Some(1)); - assert_eq!(clist.pop_head(0), Some(1)); - assert_eq!(clist.peek_head(0), None); - assert_eq!(clist.peek_head(0), None); - assert_eq!(clist.pop_head(0), None); - assert!(clist.is_empty(0)); + assert!(clist.is_empty(RunqueueId(0))); + clist.push(ThreadId(0), RunqueueId(0)); + clist.push(ThreadId(1), RunqueueId(0)); + assert_eq!(clist.peek_head(RunqueueId(0)), Some(ThreadId(0))); + assert_eq!(clist.peek_head(RunqueueId(0)), Some(ThreadId(0))); + assert_eq!(clist.pop_head(RunqueueId(0)), Some(ThreadId(0))); + assert_eq!(clist.peek_head(RunqueueId(0)), Some(ThreadId(1))); + assert_eq!(clist.pop_head(RunqueueId(0)), Some(ThreadId(1))); + assert_eq!(clist.peek_head(RunqueueId(0)), None); + assert_eq!(clist.peek_head(RunqueueId(0)), None); + assert_eq!(clist.pop_head(RunqueueId(0)), None); + assert!(clist.is_empty(RunqueueId(0))); } } } diff --git a/src/riot-rs-threads/src/arch/cortex_m.rs b/src/riot-rs-threads/src/arch/cortex_m.rs index 559977044..acd21535b 100644 --- a/src/riot-rs-threads/src/arch/cortex_m.rs +++ b/src/riot-rs-threads/src/arch/cortex_m.rs @@ -196,15 +196,15 @@ unsafe fn sched() -> usize { return 0; } //println!("current: {} next: {}", current_pid, next_pid); - threads.threads[current_pid as usize].sp = cortex_m::register::psp::read() as usize; + threads.threads[usize::from(current_pid)].sp = cortex_m::register::psp::read() as usize; threads.current_thread = Some(next_pid); - current_high_regs = threads.threads[current_pid as usize].data.as_ptr(); + current_high_regs = threads.threads[usize::from(current_pid)].data.as_ptr(); } else { threads.current_thread = Some(next_pid); current_high_regs = core::ptr::null(); } - let next = &threads.threads[next_pid as usize]; + let next = &threads.threads[usize::from(next_pid)]; let next_sp = next.sp; let next_high_regs = next.data.as_ptr(); diff --git a/src/riot-rs-threads/src/lib.rs b/src/riot-rs-threads/src/lib.rs index d403e8dcd..0fff0e85f 100644 --- a/src/riot-rs-threads/src/lib.rs +++ b/src/riot-rs-threads/src/lib.rs @@ -72,7 +72,7 @@ impl Threads { /// Returns `None` if there is no current thread. pub(crate) fn current(&mut self) -> Option<&mut Thread> { self.current_thread - .map(|tid| &mut self.threads[tid as usize]) + .map(|tid| &mut self.threads[usize::from(tid)]) } pub fn current_pid(&self) -> Option { @@ -89,7 +89,7 @@ impl Threads { func: usize, arg: usize, stack: &'static mut [u8], - prio: u8, + prio: RunqueueId, ) -> Option<&mut Thread> { if let Some((thread, pid)) = self.get_unused() { thread.sp = Cpu::setup_stack(stack, func, arg); @@ -115,14 +115,14 @@ impl Threads { /// If the thread for this `thread_id` is in an invalid state, the /// data in the returned [`Thread`] is undefined, i.e. empty or outdated. fn get_unchecked_mut(&mut self, thread_id: ThreadId) -> &mut Thread { - &mut self.threads[thread_id as usize] + &mut self.threads[usize::from(thread_id)] } /// Returns an unused ThreadId / Thread slot. fn get_unused(&mut self) -> Option<(&mut Thread, ThreadId)> { for i in 0..THREADS_NUMOF { if self.threads[i].state == ThreadState::Invalid { - return Some((&mut self.threads[i], i as ThreadId)); + return Some((&mut self.threads[i], ThreadId(i as u8))); } } None @@ -130,10 +130,10 @@ impl Threads { /// Checks if a thread with valid state exists for this `thread_id`. fn is_valid_pid(&self, thread_id: ThreadId) -> bool { - if thread_id as usize >= THREADS_NUMOF { + if usize::from(thread_id) >= THREADS_NUMOF { false } else { - self.threads[thread_id as usize].state != ThreadState::Invalid + self.threads[usize::from(thread_id)].state != ThreadState::Invalid } } @@ -146,7 +146,7 @@ impl Threads { /// /// Panics if `pid` is >= [`THREADS_NUMOF`]. pub(crate) fn set_state(&mut self, pid: ThreadId, state: ThreadState) -> ThreadState { - let thread = &mut self.threads[pid as usize]; + let thread = &mut self.threads[usize::from(pid)]; let old_state = thread.state; thread.state = state; if old_state != ThreadState::Running && state == ThreadState::Running { @@ -161,7 +161,7 @@ impl Threads { /// Returns the state of a thread. pub fn get_state(&self, thread_id: ThreadId) -> Option { if self.is_valid_pid(thread_id) { - Some(self.threads[thread_id as usize].state) + Some(self.threads[usize::from(thread_id)].state) } else { None } @@ -241,7 +241,10 @@ pub unsafe fn thread_create_raw( prio: u8, ) -> ThreadId { THREADS.with_mut(|mut threads| { - let thread_id = threads.create(func, arg, stack, prio).unwrap().pid; + let thread_id = threads + .create(func, arg, stack, RunqueueId(prio)) + .unwrap() + .pid; threads.set_state(thread_id, ThreadState::Running); thread_id }) diff --git a/src/riot-rs-threads/src/thread.rs b/src/riot-rs-threads/src/thread.rs index fe37288b6..d9759654b 100644 --- a/src/riot-rs-threads/src/thread.rs +++ b/src/riot-rs-threads/src/thread.rs @@ -51,8 +51,8 @@ impl Thread { state: ThreadState::Invalid, data: Cpu::DEFAULT_THREAD_DATA, flags: 0, - prio: 0, - pid: 0, + prio: RunqueueId(0), + pid: ThreadId(0), } } } diff --git a/src/riot-rs-threads/src/threadlist.rs b/src/riot-rs-threads/src/threadlist.rs index 4b1993a1d..2e6fa084b 100644 --- a/src/riot-rs-threads/src/threadlist.rs +++ b/src/riot-rs-threads/src/threadlist.rs @@ -19,7 +19,7 @@ impl ThreadList { pub fn put_current(&mut self, cs: CriticalSection, state: ThreadState) { THREADS.with_mut_cs(cs, |mut threads| { let thread_id = threads.current_thread.unwrap(); - threads.thread_blocklist[thread_id as usize] = self.head; + threads.thread_blocklist[usize::from(thread_id)] = self.head; self.head = Some(thread_id); threads.set_state(thread_id, state); crate::schedule(); @@ -35,7 +35,7 @@ impl ThreadList { pub fn pop(&mut self, cs: CriticalSection) -> Option<(ThreadId, ThreadState)> { if let Some(head) = self.head { let old_state = THREADS.with_mut_cs(cs, |mut threads| { - self.head = threads.thread_blocklist[head as usize].take(); + self.head = threads.thread_blocklist[usize::from(head)].take(); let old_state = threads.set_state(head, ThreadState::Running); crate::schedule(); old_state