pub struct RunQueue<const N_QUEUES: usize, const N_THREADS: usize> { /* private fields */ }Expand description
Runqueue for N_QUEUES, supporting N_THREADS total.
assumptions:
-
higher runqueue number means higher priority
-
runqueue numbers (corresponding priorities) are 0..N_QUEUES (exclusive)
-
runqueue numbers fit in usize bits (supporting max 32 priority levels)
-
pids range from 0..N_THREADS
-
N_THREADS is <255 (as u8 is used to store them, but 0xFF is used as special value)
The current implementation needs an usize for the bit cache, an [u8; N_QUEUES] array for the list tail indexes and an [u8; N_THREADS] for the list next indexes.
Implementations§
Source§impl<const N_QUEUES: usize, const N_THREADS: usize> RunQueue<N_QUEUES, N_THREADS>
impl<const N_QUEUES: usize, const N_THREADS: usize> RunQueue<N_QUEUES, N_THREADS>
pub const fn new() -> RunQueue<N_QUEUES, N_THREADS>
Sourcepub fn add(&mut self, n: ThreadId, rq: RunqueueId)
pub fn add(&mut self, n: ThreadId, rq: RunqueueId)
add thread with pid n to runqueue number rq
Sourcepub fn del(&mut self, n: ThreadId, rq: RunqueueId)
pub fn del(&mut self, n: ThreadId, rq: RunqueueId)
remove thread with pid n from runqueue number rq @note: this implementation fails if “n” is not the queue’s head. This is fine, RIOT-rs only ever calls del() for the current thread.
Sourcepub fn get_next(&self) -> Option<u8>
pub fn get_next(&self) -> Option<u8>
get pid that should run next returns the next runnable thread of the runqueue with the highest index
Sourcepub fn advance(&mut self, rq: RunqueueId)
pub fn advance(&mut self, rq: RunqueueId)
advance runqueue number rq (this is used to “yield” to another thread of the same priority)