rust/kernel/sync/condvar.rs
Source file repositories/reference/linux-study-clean/rust/kernel/sync/condvar.rs
File Facts
- System
- Linux kernel
- Corpus path
rust/kernel/sync/condvar.rs- Extension
.rs- Size
- 9585 bytes
- Lines
- 259
- 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 matchfunction notify_syncfunction notify_onefunction notify_all
Annotated Snippet
match (res as Jiffies, crate::current!().signal_pending()) {
(jiffies, true) => CondVarTimeoutResult::Signal { jiffies },
(0, false) => CondVarTimeoutResult::Timeout,
(jiffies, false) => CondVarTimeoutResult::Woken { jiffies },
}
}
/// Calls the kernel function to notify the appropriate number of threads.
fn notify(&self, count: c_int) {
// SAFETY: `wait_queue_head` points to valid memory.
unsafe {
bindings::__wake_up(
self.wait_queue_head.get(),
TASK_NORMAL,
count,
ptr::null_mut(),
)
};
}
/// Calls the kernel function to notify one thread synchronously.
///
/// This method behaves like `notify_one`, except that it hints to the scheduler that the
/// current thread is about to go to sleep, so it should schedule the target thread on the same
/// CPU.
#[inline]
pub fn notify_sync(&self) {
// SAFETY: `wait_queue_head` points to valid memory.
unsafe { bindings::__wake_up_sync(self.wait_queue_head.get(), TASK_NORMAL) };
}
/// Wakes a single waiter up, if any.
///
/// This is not 'sticky' in the sense that if no thread is waiting, the notification is lost
/// completely (as opposed to automatically waking up the next waiter).
#[inline]
pub fn notify_one(&self) {
self.notify(1);
}
/// Wakes all waiters up, if any.
///
/// This is not 'sticky' in the sense that if no thread is waiting, the notification is lost
/// completely (as opposed to automatically waking up the next waiter).
#[inline]
pub fn notify_all(&self) {
self.notify(0);
}
}
/// The return type of `wait_timeout`.
pub enum CondVarTimeoutResult {
/// The timeout was reached.
Timeout,
/// Somebody woke us up.
Woken {
/// Remaining sleep duration.
jiffies: Jiffies,
},
/// A signal occurred.
Signal {
/// Remaining sleep duration.
jiffies: Jiffies,
},
}
Annotation
- Detected declarations: `function match`, `function notify_sync`, `function notify_one`, `function notify_all`.
- 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.