pub struct Thread {
proc: Arc<Proc>,
active_pins: AtomicU8,
active_interrupts: AtomicU8,
active_mutexes: PrivateCell<Cell<u16>>,
sleeping: Gutex<usize>,
profiling_ticks: PrivateCell<Cell<u32>>,
active_heap_guard: PrivateCell<Cell<usize>>,
}
Expand description
Implementation of thread
structure.
All thread must run to completion once execution has been started otherwise resource will be leak if the thread is dropped while its execution currently in the kernel space.
We subtitute TDP_NOSLEEPING
with td_intr_nesting_level
and td_critnest
since it is the
only cases the thread should not allow to sleep.
Do not try to access any RefCell fields from interrupt handler because it might currently locked.
Fields§
§proc: Arc<Proc>
§active_pins: AtomicU8
§active_interrupts: AtomicU8
§active_mutexes: PrivateCell<Cell<u16>>
§sleeping: Gutex<usize>
§profiling_ticks: PrivateCell<Cell<u32>>
§active_heap_guard: PrivateCell<Cell<usize>>
Implementations§
Source§impl Thread
impl Thread
Sourcepub fn new_bare(proc: Arc<Proc>) -> Self
pub fn new_bare(proc: Arc<Proc>) -> Self
This function does not do anything except initialize the struct memory. It is the caller responsibility to configure the thread after this so it have a proper states and trigger necessary events.
§Context safety
This function does not require a CPU context.
pub fn can_sleep(&self) -> bool
pub fn proc(&self) -> &Arc<Proc>
Sourcepub unsafe fn active_pins(&self) -> &AtomicU8
pub unsafe fn active_pins(&self) -> &AtomicU8
See crate::context::pin_cpu()
for a safe wrapper.
§Safety
Once this value is zero this thread can switch to a different CPU. The code after this value decrement must not depend on a specific CPU.
This value must not modified by the other thread.
Sourcepub unsafe fn active_interrupts(&self) -> &AtomicU8
pub unsafe fn active_interrupts(&self) -> &AtomicU8
§Safety
This value can only modified by interrupt entry point.
Sourcepub fn active_mutexes(&self) -> u16
pub fn active_mutexes(&self) -> u16
§Panics
If called from the other thread.
Sourcepub fn set_active_mutexes(&self, v: u16)
pub fn set_active_mutexes(&self, v: u16)
§Panics
If called from the other thread.
Sourcepub fn sleeping_mut(&self) -> GutexWrite<'_, usize>
pub fn sleeping_mut(&self) -> GutexWrite<'_, usize>
Sleeping address. Zero if this thread is not in a sleep queue.
Sourcepub fn set_profiling_ticks(&self, v: u32)
pub fn set_profiling_ticks(&self, v: u32)
§Panics
If called from the other thread.
Sourcepub fn active_heap_guard(&self) -> usize
pub fn active_heap_guard(&self) -> usize
§Panics
If called from the other thread.