rust/kernel/cpumask.rs
Source file repositories/reference/linux-study-clean/rust/kernel/cpumask.rs
File Facts
- System
- Linux kernel
- Corpus path
rust/kernel/cpumask.rs- Extension
.rs- Size
- 11221 bytes
- Lines
- 344
- Domain
- Rust Kernel Layer
- Bucket
- Rust API Membrane
- Inferred role
- Rust Kernel Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
Rust-side wrappers and abstractions around kernel C APIs, ownership contracts, allocation, synchronization, and module integration.
- Rust-side wrappers and abstractions around kernel C APIs, ownership contracts, allocation, synchronization, and module integration.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
function setfunction clearfunction testfunction emptyfunction deref
Annotated Snippet
pub fn set(&mut self, cpu: CpuId) {
// SAFETY: By the type invariant, `self.as_raw` is a valid argument to `__cpumask_set_cpu`.
unsafe { bindings::__cpumask_set_cpu(u32::from(cpu), self.as_raw()) };
}
/// Clear `cpu` in the cpumask.
///
/// ATTENTION: Contrary to C, this Rust `clear()` method is non-atomic.
/// This mismatches kernel naming convention and corresponds to the C
/// function `__cpumask_clear_cpu()`.
#[inline]
pub fn clear(&mut self, cpu: CpuId) {
// SAFETY: By the type invariant, `self.as_raw` is a valid argument to
// `__cpumask_clear_cpu`.
unsafe { bindings::__cpumask_clear_cpu(i32::from(cpu), self.as_raw()) };
}
/// Test `cpu` in the cpumask.
///
/// Equivalent to the kernel's `cpumask_test_cpu` API.
#[inline]
pub fn test(&self, cpu: CpuId) -> bool {
// SAFETY: By the type invariant, `self.as_raw` is a valid argument to `cpumask_test_cpu`.
unsafe { bindings::cpumask_test_cpu(i32::from(cpu), self.as_raw()) }
}
/// Set all CPUs in the cpumask.
///
/// Equivalent to the kernel's `cpumask_setall` API.
#[inline]
pub fn setall(&mut self) {
// SAFETY: By the type invariant, `self.as_raw` is a valid argument to `cpumask_setall`.
unsafe { bindings::cpumask_setall(self.as_raw()) };
}
/// Checks if cpumask is empty.
///
/// Equivalent to the kernel's `cpumask_empty` API.
#[inline]
pub fn empty(&self) -> bool {
// SAFETY: By the type invariant, `self.as_raw` is a valid argument to `cpumask_empty`.
unsafe { bindings::cpumask_empty(self.as_raw()) }
}
/// Checks if cpumask is full.
///
/// Equivalent to the kernel's `cpumask_full` API.
#[inline]
pub fn full(&self) -> bool {
// SAFETY: By the type invariant, `self.as_raw` is a valid argument to `cpumask_full`.
unsafe { bindings::cpumask_full(self.as_raw()) }
}
/// Get weight of the cpumask.
///
/// Equivalent to the kernel's `cpumask_weight` API.
#[inline]
pub fn weight(&self) -> u32 {
// SAFETY: By the type invariant, `self.as_raw` is a valid argument to `cpumask_weight`.
unsafe { bindings::cpumask_weight(self.as_raw()) }
}
/// Copy cpumask.
///
/// Equivalent to the kernel's `cpumask_copy` API.
#[inline]
pub fn copy(&self, dstp: &mut Self) {
// SAFETY: By the type invariant, `Self::as_raw` is a valid argument to `cpumask_copy`.
unsafe { bindings::cpumask_copy(dstp.as_raw(), self.as_raw()) };
}
}
/// A CPU Mask pointer.
///
/// Rust abstraction for the C `struct cpumask_var_t`.
///
/// # Invariants
///
/// A [`CpumaskVar`] instance always corresponds to a valid C `struct cpumask_var_t`.
///
/// The callers must ensure that the `struct cpumask_var_t` is valid for access and remains valid
/// for the lifetime of [`CpumaskVar`].
///
/// # Examples
///
/// The following example demonstrates how to create and update a [`CpumaskVar`].
///
/// ```
/// use kernel::cpu::CpuId;
/// use kernel::cpumask::CpumaskVar;
Annotation
- Detected declarations: `function set`, `function clear`, `function test`, `function empty`, `function deref`.
- Atlas domain: Rust Kernel Layer / Rust API Membrane.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.