Skip to content

Commit 904fef0

Browse files
committed
SeqCst->{Release,Acquire} for alloc error hook.
SeqCst is unnecessary.
1 parent bf3debe commit 904fef0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

library/std/src/alloc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ static HOOK: AtomicPtr<()> = AtomicPtr::new(ptr::null_mut());
329329
/// ```
330330
#[unstable(feature = "alloc_error_hook", issue = "51245")]
331331
pub fn set_alloc_error_hook(hook: fn(Layout)) {
332-
HOOK.store(hook as *mut (), Ordering::SeqCst);
332+
HOOK.store(hook as *mut (), Ordering::Release);
333333
}
334334

335335
/// Unregisters the current allocation error hook, returning it.
@@ -339,7 +339,7 @@ pub fn set_alloc_error_hook(hook: fn(Layout)) {
339339
/// If no custom hook is registered, the default hook will be returned.
340340
#[unstable(feature = "alloc_error_hook", issue = "51245")]
341341
pub fn take_alloc_error_hook() -> fn(Layout) {
342-
let hook = HOOK.swap(ptr::null_mut(), Ordering::SeqCst);
342+
let hook = HOOK.swap(ptr::null_mut(), Ordering::Acquire);
343343
if hook.is_null() { default_alloc_error_hook } else { unsafe { mem::transmute(hook) } }
344344
}
345345

@@ -362,7 +362,7 @@ fn default_alloc_error_hook(layout: Layout) {
362362
#[alloc_error_handler]
363363
#[unstable(feature = "alloc_internals", issue = "none")]
364364
pub fn rust_oom(layout: Layout) -> ! {
365-
let hook = HOOK.load(Ordering::SeqCst);
365+
let hook = HOOK.load(Ordering::Acquire);
366366
let hook: fn(Layout) =
367367
if hook.is_null() { default_alloc_error_hook } else { unsafe { mem::transmute(hook) } };
368368
hook(layout);

0 commit comments

Comments
 (0)