mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 23:12:02 +00:00
Directly use raw pointers in AtomicPtr
store/load
This commit is contained in:
parent
4ae328bef4
commit
aabe70f90e
@ -437,7 +437,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||||||
match split[1] {
|
match split[1] {
|
||||||
"cxchg" | "cxchgweak" => {
|
"cxchg" | "cxchgweak" => {
|
||||||
let ty = substs.type_at(0);
|
let ty = substs.type_at(0);
|
||||||
if int_type_width_signed(ty, bx.tcx()).is_some() {
|
if int_type_width_signed(ty, bx.tcx()).is_some() || ty.is_unsafe_ptr() {
|
||||||
let weak = split[1] == "cxchgweak";
|
let weak = split[1] == "cxchgweak";
|
||||||
let pair = bx.atomic_cmpxchg(
|
let pair = bx.atomic_cmpxchg(
|
||||||
args[0].immediate(),
|
args[0].immediate(),
|
||||||
@ -464,7 +464,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||||||
|
|
||||||
"load" => {
|
"load" => {
|
||||||
let ty = substs.type_at(0);
|
let ty = substs.type_at(0);
|
||||||
if int_type_width_signed(ty, bx.tcx()).is_some() {
|
if int_type_width_signed(ty, bx.tcx()).is_some() || ty.is_unsafe_ptr() {
|
||||||
let size = bx.layout_of(ty).size;
|
let size = bx.layout_of(ty).size;
|
||||||
bx.atomic_load(args[0].immediate(), order, size)
|
bx.atomic_load(args[0].immediate(), order, size)
|
||||||
} else {
|
} else {
|
||||||
@ -474,7 +474,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||||||
|
|
||||||
"store" => {
|
"store" => {
|
||||||
let ty = substs.type_at(0);
|
let ty = substs.type_at(0);
|
||||||
if int_type_width_signed(ty, bx.tcx()).is_some() {
|
if int_type_width_signed(ty, bx.tcx()).is_some() || ty.is_unsafe_ptr() {
|
||||||
let size = bx.layout_of(ty).size;
|
let size = bx.layout_of(ty).size;
|
||||||
bx.atomic_store(args[1].immediate(), args[0].immediate(), order, size);
|
bx.atomic_store(args[1].immediate(), args[0].immediate(), order, size);
|
||||||
return;
|
return;
|
||||||
|
@ -966,8 +966,16 @@ impl<T> AtomicPtr<T> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn load(&self, order: Ordering) -> *mut T {
|
pub fn load(&self, order: Ordering) -> *mut T {
|
||||||
|
#[cfg(not(bootstrap))]
|
||||||
// SAFETY: data races are prevented by atomic intrinsics.
|
// SAFETY: data races are prevented by atomic intrinsics.
|
||||||
unsafe { atomic_load(self.p.get() as *mut usize, order) as *mut T }
|
unsafe {
|
||||||
|
atomic_load(self.p.get(), order)
|
||||||
|
}
|
||||||
|
#[cfg(bootstrap)]
|
||||||
|
// SAFETY: data races are prevented by atomic intrinsics.
|
||||||
|
unsafe {
|
||||||
|
atomic_load(self.p.get() as *mut usize, order) as *mut T
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stores a value into the pointer.
|
/// Stores a value into the pointer.
|
||||||
@ -994,6 +1002,12 @@ impl<T> AtomicPtr<T> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn store(&self, ptr: *mut T, order: Ordering) {
|
pub fn store(&self, ptr: *mut T, order: Ordering) {
|
||||||
|
#[cfg(not(bootstrap))]
|
||||||
|
// SAFETY: data races are prevented by atomic intrinsics.
|
||||||
|
unsafe {
|
||||||
|
atomic_store(self.p.get(), ptr, order);
|
||||||
|
}
|
||||||
|
#[cfg(bootstrap)]
|
||||||
// SAFETY: data races are prevented by atomic intrinsics.
|
// SAFETY: data races are prevented by atomic intrinsics.
|
||||||
unsafe {
|
unsafe {
|
||||||
atomic_store(self.p.get() as *mut usize, ptr as usize, order);
|
atomic_store(self.p.get() as *mut usize, ptr as usize, order);
|
||||||
@ -1105,6 +1119,7 @@ impl<T> AtomicPtr<T> {
|
|||||||
success: Ordering,
|
success: Ordering,
|
||||||
failure: Ordering,
|
failure: Ordering,
|
||||||
) -> Result<*mut T, *mut T> {
|
) -> Result<*mut T, *mut T> {
|
||||||
|
#[cfg(bootstrap)]
|
||||||
// SAFETY: data races are prevented by atomic intrinsics.
|
// SAFETY: data races are prevented by atomic intrinsics.
|
||||||
unsafe {
|
unsafe {
|
||||||
let res = atomic_compare_exchange(
|
let res = atomic_compare_exchange(
|
||||||
@ -1119,6 +1134,11 @@ impl<T> AtomicPtr<T> {
|
|||||||
Err(x) => Err(x as *mut T),
|
Err(x) => Err(x as *mut T),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(not(bootstrap))]
|
||||||
|
// SAFETY: data races are prevented by atomic intrinsics.
|
||||||
|
unsafe {
|
||||||
|
atomic_compare_exchange(self.p.get(), current, new, success, failure)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stores a value into the pointer if the current value is the same as the `current` value.
|
/// Stores a value into the pointer if the current value is the same as the `current` value.
|
||||||
@ -1165,6 +1185,7 @@ impl<T> AtomicPtr<T> {
|
|||||||
success: Ordering,
|
success: Ordering,
|
||||||
failure: Ordering,
|
failure: Ordering,
|
||||||
) -> Result<*mut T, *mut T> {
|
) -> Result<*mut T, *mut T> {
|
||||||
|
#[cfg(bootstrap)]
|
||||||
// SAFETY: data races are prevented by atomic intrinsics.
|
// SAFETY: data races are prevented by atomic intrinsics.
|
||||||
unsafe {
|
unsafe {
|
||||||
let res = atomic_compare_exchange_weak(
|
let res = atomic_compare_exchange_weak(
|
||||||
@ -1179,6 +1200,11 @@ impl<T> AtomicPtr<T> {
|
|||||||
Err(x) => Err(x as *mut T),
|
Err(x) => Err(x as *mut T),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(not(bootstrap))]
|
||||||
|
// SAFETY: data races are prevented by atomic intrinsics.
|
||||||
|
unsafe {
|
||||||
|
atomic_compare_exchange_weak(self.p.get(), current, new, success, failure)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetches the value, and applies a function to it that returns an optional
|
/// Fetches the value, and applies a function to it that returns an optional
|
||||||
|
Loading…
Reference in New Issue
Block a user