Expand description
Atomic Mode
Multitasking, while powerful, can sometimes lead to undesirable or catastrophic consequences if being misused. For instance, a user of OSTD might accidentally write an IRQ handler that relies on mutexes, which could attempt to sleep within an interrupt context—something that must be avoided. Another common mistake is acquiring a spinlock in a task context and then attempting to yield or sleep, which can easily lead to deadlocks.
To mitigate the risks associated with improper multitasking, we introduce the concept of atomic mode. Kernel code is considered to be running in atomic mode if one of the following conditions is met:
- Task preemption is disabled, such as when a spinlock is held.
- Local IRQs are disabled, such as during interrupt context.
While in atomic mode, any attempt to perform “sleep-like” actions will trigger a panic:
- Switching to another task.
- Switching to user space.
This module provides API to detect such “sleep-like” actions.
Traits§
- AsAtomic
Mode Guard - Abstracts any type from which one can obtain a reference to an atomic-mode guard.
- InAtomic
Mode - A marker trait for guard types that enforce the atomic mode.
Functions§
- might_
sleep - Marks a function as one that might sleep.