rust/kernel/sync/atomic/predefine.rs
Source file repositories/reference/linux-study-clean/rust/kernel/sync/atomic/predefine.rs
File Facts
- System
- Linux kernel
- Corpus path
rust/kernel/sync/atomic/predefine.rs- Extension
.rs- Size
- 10334 bytes
- Lines
- 336
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
function atomic_basic_testsfunction atomic_acquire_release_testsfunction atomic_xchg_testsfunction atomic_cmpxchg_testsfunction atomic_arithmetic_testsfunction atomic_bool_testsfunction atomic_ptr_testsfunction atomic_flag_tests
Annotated Snippet
fn atomic_basic_tests() {
for_each_type!(42 in [i8, i16, i32, i64, u32, u64, isize, usize] |v| {
let x = Atomic::new(v);
assert_eq!(v, x.load(Relaxed));
});
for_each_type!(42 in [i8, i16, i32, i64, u32, u64, isize, usize] |v| {
let x = Atomic::new(v);
let ptr = x.as_ptr();
// SAFETY: `ptr` is a valid pointer and no concurrent access.
assert_eq!(v, unsafe { atomic_load(ptr, Relaxed) });
});
}
#[test]
fn atomic_acquire_release_tests() {
for_each_type!(42 in [i8, i16, i32, i64, u32, u64, isize, usize] |v| {
let x = Atomic::new(0);
x.store(v, Release);
assert_eq!(v, x.load(Acquire));
});
for_each_type!(42 in [i8, i16, i32, i64, u32, u64, isize, usize] |v| {
let x = Atomic::new(0);
let ptr = x.as_ptr();
// SAFETY: `ptr` is a valid pointer and no concurrent access.
unsafe { atomic_store(ptr, v, Release) };
// SAFETY: `ptr` is a valid pointer and no concurrent access.
assert_eq!(v, unsafe { atomic_load(ptr, Acquire) });
});
}
#[test]
fn atomic_xchg_tests() {
for_each_type!(42 in [i8, i16, i32, i64, u32, u64, isize, usize] |v| {
let x = Atomic::new(v);
let old = v;
let new = v + 1;
assert_eq!(old, x.xchg(new, Full));
assert_eq!(new, x.load(Relaxed));
});
for_each_type!(42 in [i8, i16, i32, i64, u32, u64, isize, usize] |v| {
let x = Atomic::new(v);
let ptr = x.as_ptr();
let old = v;
let new = v + 1;
// SAFETY: `ptr` is a valid pointer and no concurrent access.
assert_eq!(old, unsafe { xchg(ptr, new, Full) });
assert_eq!(new, x.load(Relaxed));
});
}
#[test]
fn atomic_cmpxchg_tests() {
for_each_type!(42 in [i8, i16, i32, i64, u32, u64, isize, usize] |v| {
let x = Atomic::new(v);
let old = v;
let new = v + 1;
assert_eq!(Err(old), x.cmpxchg(new, new, Full));
assert_eq!(old, x.load(Relaxed));
assert_eq!(Ok(old), x.cmpxchg(old, new, Relaxed));
assert_eq!(new, x.load(Relaxed));
});
for_each_type!(42 in [i8, i16, i32, i64, u32, u64, isize, usize] |v| {
let x = Atomic::new(v);
let ptr = x.as_ptr();
let old = v;
let new = v + 1;
// SAFETY: `ptr` is a valid pointer and no concurrent access.
assert_eq!(Err(old), unsafe { cmpxchg(ptr, new, new, Full) });
assert_eq!(old, x.load(Relaxed));
// SAFETY: `ptr` is a valid pointer and no concurrent access.
assert_eq!(Ok(old), unsafe { cmpxchg(ptr, old, new, Relaxed) });
assert_eq!(new, x.load(Relaxed));
});
Annotation
- Detected declarations: `function atomic_basic_tests`, `function atomic_acquire_release_tests`, `function atomic_xchg_tests`, `function atomic_cmpxchg_tests`, `function atomic_arithmetic_tests`, `function atomic_bool_tests`, `function atomic_ptr_tests`, `function atomic_flag_tests`.
- Atlas domain: Rust Kernel Layer / Rust API Membrane.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.