Skip to content

Commit 6162734

Browse files
committed
use godot_thread_local instead of thread_local
esrt
1 parent 8c64a51 commit 6162734

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.
@@ -616,19 +616,19 @@ macro_rules! godot_thread_local {
616616

617617
pub(crate) use godot_thread_local;
618618

619-
#[cfg(all(debug_assertions, not(wasm_nothreads)))]
620-
thread_local! {
619+
#[cfg(debug_assertions)]
620+
godot_thread_local! {
621621
static ERROR_CONTEXT_STACK: RefCell<ScopedFunctionStack> = const {
622622
RefCell::new(ScopedFunctionStack { functions: Vec::new() })
623623
}
624624
}
625625

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

631-
#[cfg(not(all(debug_assertions, not(wasm_nothreads))))]
631+
#[cfg(not(debug_assertions))]
632632
None
633633
}
634634

@@ -643,10 +643,10 @@ where
643643
E: Fn() -> String,
644644
F: FnOnce() -> R + std::panic::UnwindSafe,
645645
{
646-
#[cfg(not(all(debug_assertions, not(wasm_nothreads))))]
647-
let _ = error_context; // Unused in Release or `wasm_nothreads` builds.
646+
#[cfg(not(debug_assertions))]
647+
let _ = error_context; // Unused in Release.
648648

649-
#[cfg(all(debug_assertions, not(wasm_nothreads)))]
649+
#[cfg(debug_assertions)]
650650
ERROR_CONTEXT_STACK.with(|cell| unsafe {
651651
// SAFETY: &error_context is valid for lifetime of function, and is removed from LAST_ERROR_CONTEXT before end of function.
652652
cell.borrow_mut().push_function(&error_context)
@@ -655,7 +655,7 @@ where
655655
let result =
656656
std::panic::catch_unwind(code).map_err(|payload| extract_panic_message(payload.as_ref()));
657657

658-
#[cfg(all(debug_assertions, not(wasm_nothreads)))]
658+
#[cfg(debug_assertions)]
659659
ERROR_CONTEXT_STACK.with(|cell| cell.borrow_mut().pop_function());
660660
result
661661
}

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)