Skip to content

Commit 8b519f9

Browse files
committed
Use less restricted memory ordering in xous::thread_local_key.
SeqCst isn't necessary in any of these cases.
1 parent 5a594f7 commit 8b519f9

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

library/std/src/sys/pal/xous/thread_local_key.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::mem::ManuallyDrop;
22
use crate::ptr;
33
use crate::sync::atomic::AtomicPtr;
44
use crate::sync::atomic::AtomicUsize;
5-
use crate::sync::atomic::Ordering::SeqCst;
5+
use crate::sync::atomic::Ordering::{Acquire, Relaxed, Release};
66
use core::arch::asm;
77

88
use crate::os::xous::ffi::{map_memory, unmap_memory, MemoryFlags};
@@ -92,7 +92,7 @@ fn tls_table() -> &'static mut [*mut u8] {
9292
pub unsafe fn create(dtor: Option<Dtor>) -> Key {
9393
// Allocate a new TLS key. These keys are shared among all threads.
9494
#[allow(unused_unsafe)]
95-
let key = unsafe { TLS_KEY_INDEX.fetch_add(1, SeqCst) };
95+
let key = unsafe { TLS_KEY_INDEX.fetch_add(1, Relaxed) };
9696
if let Some(f) = dtor {
9797
unsafe { register_dtor(key, f) };
9898
}
@@ -154,11 +154,11 @@ unsafe fn register_dtor(key: Key, dtor: Dtor) {
154154
let mut node = ManuallyDrop::new(Box::new(Node { key, dtor, next: ptr::null_mut() }));
155155

156156
#[allow(unused_unsafe)]
157-
let mut head = unsafe { DTORS.load(SeqCst) };
157+
let mut head = unsafe { DTORS.load(Acquire) };
158158
loop {
159159
node.next = head;
160160
#[allow(unused_unsafe)]
161-
match unsafe { DTORS.compare_exchange(head, &mut **node, SeqCst, SeqCst) } {
161+
match unsafe { DTORS.compare_exchange(head, &mut **node, Release, Acquire) } {
162162
Ok(_) => return, // nothing to drop, we successfully added the node to the list
163163
Err(cur) => head = cur,
164164
}
@@ -199,7 +199,7 @@ unsafe fn run_dtors() {
199199
}
200200
any_run = false;
201201
#[allow(unused_unsafe)]
202-
let mut cur = unsafe { DTORS.load(SeqCst) };
202+
let mut cur = unsafe { DTORS.load(Acquire) };
203203
while !cur.is_null() {
204204
let ptr = unsafe { get((*cur).key) };
205205

0 commit comments

Comments
 (0)