Skip to content

Commit 1c47175

Browse files
committed
use godot_thread_local instead of thread_local
esrt
1 parent f52b02e commit 1c47175

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

godot-core/src/meta/signature.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ pub mod trace {
739739
TRACE.set(Some(report));
740740
}
741741

742-
thread_local! {
742+
crate::private::godot_thread_local! {
743743
static TRACE: Cell<Option<CallReport>> = Cell::default();
744744
}
745745
}

godot-core/src/private.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,12 @@ pub(crate) fn has_error_print_level(level: u8) -> bool {
320320
/// Internal type used to store context information for debug purposes. Debug context is stored on the thread-local
321321
/// ERROR_CONTEXT_STACK, which can later be used to retrieve the current context in the event of a panic. This value
322322
/// probably shouldn't be used directly; use ['get_gdext_panic_context()'](get_gdext_panic_context) instead.
323-
#[cfg(all(debug_assertions, not(wasm_nothreads)))]
323+
#[cfg(debug_assertions)]
324324
struct ScopedFunctionStack {
325325
functions: Vec<*const dyn Fn() -> String>,
326326
}
327327

328-
#[cfg(all(debug_assertions, not(wasm_nothreads)))]
328+
#[cfg(debug_assertions)]
329329
impl ScopedFunctionStack {
330330
/// # Safety
331331
/// Function must be removed (using [`pop_function()`](Self::pop_function)) before lifetime is invalidated.
@@ -594,19 +594,19 @@ macro_rules! godot_thread_local {
594594

595595
pub(crate) use godot_thread_local;
596596

597-
#[cfg(all(debug_assertions, not(wasm_nothreads)))]
598-
thread_local! {
597+
#[cfg(debug_assertions)]
598+
godot_thread_local! {
599599
static ERROR_CONTEXT_STACK: RefCell<ScopedFunctionStack> = const {
600600
RefCell::new(ScopedFunctionStack { functions: Vec::new() })
601601
}
602602
}
603603

604604
// Value may return `None`, even from panic hook, if called from a non-Godot thread.
605605
pub fn get_gdext_panic_context() -> Option<String> {
606-
#[cfg(all(debug_assertions, not(wasm_nothreads)))]
606+
#[cfg(debug_assertions)]
607607
return ERROR_CONTEXT_STACK.with(|cell| cell.borrow().get_last());
608608

609-
#[cfg(not(all(debug_assertions, not(wasm_nothreads))))]
609+
#[cfg(not(debug_assertions))]
610610
None
611611
}
612612

@@ -621,10 +621,10 @@ where
621621
E: Fn() -> String,
622622
F: FnOnce() -> R + std::panic::UnwindSafe,
623623
{
624-
#[cfg(not(all(debug_assertions, not(wasm_nothreads))))]
625-
let _ = error_context; // Unused in Release or `wasm_nothreads` builds.
624+
#[cfg(not(debug_assertions))]
625+
let _ = error_context; // Unused in Release.
626626

627-
#[cfg(all(debug_assertions, not(wasm_nothreads)))]
627+
#[cfg(debug_assertions)]
628628
ERROR_CONTEXT_STACK.with(|cell| unsafe {
629629
// SAFETY: &error_context is valid for lifetime of function, and is removed from LAST_ERROR_CONTEXT before end of function.
630630
cell.borrow_mut().push_function(&error_context)
@@ -633,7 +633,7 @@ where
633633
let result =
634634
std::panic::catch_unwind(code).map_err(|payload| extract_panic_message(payload.as_ref()));
635635

636-
#[cfg(all(debug_assertions, not(wasm_nothreads)))]
636+
#[cfg(debug_assertions)]
637637
ERROR_CONTEXT_STACK.with(|cell| cell.borrow_mut().pop_function());
638638
result
639639
}

godot-core/src/task/async_runtime.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::panic::AssertUnwindSafe;
1212
use std::pin::Pin;
1313
use std::sync::Arc;
1414
use std::task::{Context, Poll, Wake, Waker};
15-
use std::thread::{self, LocalKey, ThreadId};
15+
use std::thread::{self, ThreadId};
1616

1717
use crate::builtin::{Callable, Variant};
1818
use crate::private::handle_panic;
@@ -147,7 +147,7 @@ impl TaskHandle {
147147

148148
const ASYNC_RUNTIME_DEINIT_PANIC_MESSAGE: &str = "The async runtime is being accessed after it has been deinitialized. This should not be possible and is most likely a bug.";
149149

150-
thread_local! {
150+
crate::private::godot_thread_local! {
151151
/// The thread local is only initialized the first time it's used. This means the async runtime won't be allocated until a task is
152152
/// spawned.
153153
static ASYNC_RUNTIME: RefCell<Option<AsyncRuntime>> = RefCell::new(Some(AsyncRuntime::new()));
@@ -346,7 +346,7 @@ trait WithRuntime {
346346
fn with_runtime_mut<R>(&'static self, f: impl FnOnce(&mut AsyncRuntime) -> R) -> R;
347347
}
348348

349-
impl WithRuntime for LocalKey<RefCell<Option<AsyncRuntime>>> {
349+
impl WithRuntime for crate::private::GodotThreadLocal<RefCell<Option<AsyncRuntime>>> {
350350
fn with_runtime<R>(&'static self, f: impl FnOnce(&AsyncRuntime) -> R) -> R {
351351
self.with_borrow(|rt| {
352352
let rt_ref = rt.as_ref().expect(ASYNC_RUNTIME_DEINIT_PANIC_MESSAGE);

0 commit comments

Comments
 (0)