SeqCst->{Release,Acquire} for alloc error hook.

SeqCst is unnecessary.
This commit is contained in:
Mara Bos 2024-03-19 14:57:59 +01:00
parent bf3debe9d7
commit 904fef0e24

View File

@ -329,7 +329,7 @@ static HOOK: AtomicPtr<()> = AtomicPtr::new(ptr::null_mut());
/// ``` /// ```
#[unstable(feature = "alloc_error_hook", issue = "51245")] #[unstable(feature = "alloc_error_hook", issue = "51245")]
pub fn set_alloc_error_hook(hook: fn(Layout)) { pub fn set_alloc_error_hook(hook: fn(Layout)) {
HOOK.store(hook as *mut (), Ordering::SeqCst); HOOK.store(hook as *mut (), Ordering::Release);
} }
/// Unregisters the current allocation error hook, returning it. /// Unregisters the current allocation error hook, returning it.
@ -339,7 +339,7 @@ pub fn set_alloc_error_hook(hook: fn(Layout)) {
/// If no custom hook is registered, the default hook will be returned. /// If no custom hook is registered, the default hook will be returned.
#[unstable(feature = "alloc_error_hook", issue = "51245")] #[unstable(feature = "alloc_error_hook", issue = "51245")]
pub fn take_alloc_error_hook() -> fn(Layout) { pub fn take_alloc_error_hook() -> fn(Layout) {
let hook = HOOK.swap(ptr::null_mut(), Ordering::SeqCst); let hook = HOOK.swap(ptr::null_mut(), Ordering::Acquire);
if hook.is_null() { default_alloc_error_hook } else { unsafe { mem::transmute(hook) } } if hook.is_null() { default_alloc_error_hook } else { unsafe { mem::transmute(hook) } }
} }
@ -362,7 +362,7 @@ fn default_alloc_error_hook(layout: Layout) {
#[alloc_error_handler] #[alloc_error_handler]
#[unstable(feature = "alloc_internals", issue = "none")] #[unstable(feature = "alloc_internals", issue = "none")]
pub fn rust_oom(layout: Layout) -> ! { pub fn rust_oom(layout: Layout) -> ! {
let hook = HOOK.load(Ordering::SeqCst); let hook = HOOK.load(Ordering::Acquire);
let hook: fn(Layout) = let hook: fn(Layout) =
if hook.is_null() { default_alloc_error_hook } else { unsafe { mem::transmute(hook) } }; if hook.is_null() { default_alloc_error_hook } else { unsafe { mem::transmute(hook) } };
hook(layout); hook(layout);