pub struct Static<T> { /* private fields */ }
Expand description
A helper that implements static variables.
It ensures that even if you use the same static variable in both an IRQ and normal code, the IRQ will never observe an invalid value of the variable.
This type only works with owned values. If you need to work with borrows,
consider using sync::Mutex
instead.
§Performance
Writing or reading from a static variable is efficient under the following conditions:
- The type is aligned to 4 bytes and can be stored in 40 bytes or less.
- The type is aligned to 2 bytes and can be stored in 2 bytes.
- The type is can be stored in a single byte.
Replacing the current value of the static variable is efficient under the following conditions:
- The type is aligned to 4 bytes and can be stored in 4 bytes or less.
- The type is can be stored in a single byte.
When these conditions are not met, static variables are handled using a fallback routine that disables IRQs and does a normal copy. This can be dangerous as disabling IRQs can cause your program to miss out on important interrupts such as V-Blank.
Consider using sync::Mutex
instead if you need to
use a large amount of operations that would cause IRQs to be disabled. Also
consider using #[repr(align(4))]
to force proper alignment for your type.