From c0c4a87103942f9e620cd6595a9be9f5ff6c5c39 Mon Sep 17 00:00:00 2001 From: pjht Date: Wed, 5 Jun 2024 10:47:05 -0500 Subject: [PATCH] Tell std to use statics for TLS given mikros is single-threaded --- .../src/sys/pal/mikros/thread_local_key.rs | 23 +++++-------------- library/std/src/sys/thread_local/mod.rs | 2 +- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/library/std/src/sys/pal/mikros/thread_local_key.rs b/library/std/src/sys/pal/mikros/thread_local_key.rs index 1c60d3bad35..b6e5e4cd2e1 100644 --- a/library/std/src/sys/pal/mikros/thread_local_key.rs +++ b/library/std/src/sys/pal/mikros/thread_local_key.rs @@ -1,32 +1,21 @@ -use crate::{ - ptr, - sync::atomic::{AtomicUsize, Ordering} -}; - pub type Key = usize; -static mut TLS_SLOTS: [*mut u8; 64] = [ptr::null_mut(); 64]; -static NEXT_TLS: AtomicUsize = AtomicUsize::new(1); - #[inline] pub unsafe fn create(_dtor: Option) -> Key { - if NEXT_TLS.load(Ordering::Relaxed) == 65 { - panic!("Out of TLS slots"); - } - NEXT_TLS.fetch_add(1, Ordering::Relaxed) + panic!("should not be used on this target"); } #[inline] -pub unsafe fn set(key: Key, value: *mut u8) { - unsafe { TLS_SLOTS[key - 1] = value } +pub unsafe fn set(_key: Key, _value: *mut u8) { + panic!("should not be used on this target"); } #[inline] -pub unsafe fn get(key: Key) -> *mut u8 { - unsafe { TLS_SLOTS[key - 1]} +pub unsafe fn get(_key: Key) -> *mut u8 { + panic!("should not be used on this target"); } #[inline] pub unsafe fn destroy(_key: Key) { - // Ignore destructors for now + panic!("should not be used on this target"); } diff --git a/library/std/src/sys/thread_local/mod.rs b/library/std/src/sys/thread_local/mod.rs index 0a78a1a1cf0..7bae18dbba4 100644 --- a/library/std/src/sys/thread_local/mod.rs +++ b/library/std/src/sys/thread_local/mod.rs @@ -7,7 +7,7 @@ // "static" is for single-threaded platforms where a global static is sufficient. cfg_if::cfg_if! { - if #[cfg(any(all(target_family = "wasm", not(target_feature = "atomics")), target_os = "uefi"))] { + if #[cfg(any(all(target_family = "wasm", not(target_feature = "atomics")), target_os = "uefi", target_os = "mikros"))] { #[doc(hidden)] mod static_local; #[doc(hidden)]