Lines Matching +full:write +full:- +full:file +full:- +full:atomic
3 // Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4 // http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5 // http://opensource.org/licenses/MIT>, at your option. This file may not be
13 use core::sync::atomic::{AtomicUsize, Ordering};
18 // on architectures that don't have byte-sized atomics.
42 // A big array of spinlocks which we use to guard atomic accesses. A spinlock is
43 // chosen based on a hash of the address of the atomic object, which helps to
46 (@accum (0, $($_es:expr),*) -> ($($body:tt)*))
48 (@accum (1, $($es:expr),*) -> ($($body:tt)*))
49 => {array!(@accum (0, $($es),*) -> ($($body)* $($es,)*))};
50 (@accum (2, $($es:expr),*) -> ($($body:tt)*))
51 => {array!(@accum (0, $($es),*) -> ($($body)* $($es,)* $($es,)*))};
52 (@accum (4, $($es:expr),*) -> ($($body:tt)*))
53 => {array!(@accum (2, $($es,)* $($es),*) -> ($($body)*))};
54 (@accum (8, $($es:expr),*) -> ($($body:tt)*))
55 => {array!(@accum (4, $($es,)* $($es),*) -> ($($body)*))};
56 (@accum (16, $($es:expr),*) -> ($($body:tt)*))
57 => {array!(@accum (8, $($es,)* $($es),*) -> ($($body)*))};
58 (@accum (32, $($es:expr),*) -> ($($body:tt)*))
59 => {array!(@accum (16, $($es,)* $($es),*) -> ($($body)*))};
60 (@accum (64, $($es:expr),*) -> ($($body:tt)*))
61 => {array!(@accum (32, $($es,)* $($es),*) -> ($($body)*))};
65 [$e:expr; $n:tt] => { array!(@accum ($n, $e) -> ()) };
69 // Spinlock pointer hashing function from compiler-rt
71 fn lock_for_addr(addr: usize) -> &'static SpinLock { in lock_for_addr()
77 let low = hash & (SPINLOCKS.len() - 1); in lock_for_addr()
79 // get collisions from atomic fields in a single object in lock_for_addr()
83 &SPINLOCKS[hash & (SPINLOCKS.len() - 1)] in lock_for_addr()
87 fn lock(addr: usize) -> LockGuard { in lock()
102 pub unsafe fn atomic_load<T>(dst: *mut T) -> T { in atomic_load()
110 ptr::write(dst, val); in atomic_store()
114 pub unsafe fn atomic_swap<T>(dst: *mut T, val: T) -> T { in atomic_swap()
124 ) -> Result<T, T> { in atomic_compare_exchange()
131 ptr::write(dst, new); in atomic_compare_exchange()
139 pub unsafe fn atomic_add<T: Copy>(dst: *mut T, val: T) -> T in atomic_add()
145 ptr::write(dst, (Wrapping(result) + Wrapping(val)).0); in atomic_add()
150 pub unsafe fn atomic_sub<T: Copy>(dst: *mut T, val: T) -> T in atomic_sub()
156 ptr::write(dst, (Wrapping(result) - Wrapping(val)).0); in atomic_sub()
161 pub unsafe fn atomic_and<T: Copy + ops::BitAnd<Output = T>>(dst: *mut T, val: T) -> T { in atomic_and()
164 ptr::write(dst, result & val); in atomic_and()
169 pub unsafe fn atomic_or<T: Copy + ops::BitOr<Output = T>>(dst: *mut T, val: T) -> T { in atomic_or()
172 ptr::write(dst, result | val); in atomic_or()
177 pub unsafe fn atomic_xor<T: Copy + ops::BitXor<Output = T>>(dst: *mut T, val: T) -> T { in atomic_xor()
180 ptr::write(dst, result ^ val); in atomic_xor()
185 pub unsafe fn atomic_min<T: Copy + cmp::Ord>(dst: *mut T, val: T) -> T { in atomic_min()
188 ptr::write(dst, cmp::min(result, val)); in atomic_min()
193 pub unsafe fn atomic_max<T: Copy + cmp::Ord>(dst: *mut T, val: T) -> T { in atomic_max()
196 ptr::write(dst, cmp::max(result, val)); in atomic_max()