rust/kernel/time/hrtimer/arc.rs
Source file repositories/reference/linux-study-clean/rust/kernel/time/hrtimer/arc.rs
File Facts
- System
- Linux kernel
- Corpus path
rust/kernel/time/hrtimer/arc.rs- Extension
.rs- Size
- 3672 bytes
- Lines
- 112
- 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 drop
Annotated Snippet
fn drop(&mut self) {
self.cancel();
}
}
impl<T> HrTimerPointer for Arc<T>
where
T: 'static,
T: Send + Sync,
T: HasHrTimer<T>,
T: for<'a> HrTimerCallback<Pointer<'a> = Self>,
{
type TimerMode = <T as HasHrTimer<T>>::TimerMode;
type TimerHandle = ArcHrTimerHandle<T>;
fn start(
self,
expires: <<T as HasHrTimer<T>>::TimerMode as HrTimerMode>::Expires,
) -> ArcHrTimerHandle<T> {
// SAFETY:
// - We keep `self` alive by wrapping it in a handle below.
// - Since we generate the pointer passed to `start` from a valid
// reference, it is a valid pointer.
unsafe { T::start(Arc::as_ptr(&self), expires) };
ArcHrTimerHandle { inner: self }
}
}
impl<T> RawHrTimerCallback for Arc<T>
where
T: 'static,
T: HasHrTimer<T>,
T: for<'a> HrTimerCallback<Pointer<'a> = Self>,
{
type CallbackTarget<'a> = ArcBorrow<'a, T>;
unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrtimer_restart {
// `HrTimer` is `repr(C)`
let timer_ptr = ptr.cast::<super::HrTimer<T>>();
// SAFETY: By C API contract `ptr` is the pointer we passed when
// queuing the timer, so it is a `HrTimer<T>` embedded in a `T`.
let data_ptr = unsafe { T::timer_container_of(timer_ptr) };
// SAFETY:
// - `data_ptr` is derived form the pointer to the `T` that was used to
// queue the timer.
// - As per the safety requirements of the trait `HrTimerHandle`, the
// `ArcHrTimerHandle` associated with this timer is guaranteed to
// be alive until this method returns. That handle borrows the `T`
// behind `data_ptr` thus guaranteeing the validity of
// the `ArcBorrow` created below.
// - We own one refcount in the `ArcTimerHandle` associated with this
// timer, so it is not possible to get a `UniqueArc` to this
// allocation from other `Arc` clones.
let receiver = unsafe { ArcBorrow::from_raw(data_ptr) };
// SAFETY:
// - By C API contract `timer_ptr` is the pointer that we passed when queuing the timer, so
// it is a valid pointer to a `HrTimer<T>` embedded in a `T`.
// - We are within `RawHrTimerCallback::run`
let context = unsafe { HrTimerCallbackContext::from_raw(timer_ptr) };
T::run(receiver, context).into_c()
}
}
Annotation
- Detected declarations: `function drop`.
- 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.