Skip to main content

luaur_common/functions/
thread_context_provider.rs

1use crate::type_aliases::thread_context_provider::ThreadContextProvider;
2
3pub fn thread_context_provider() -> &'static mut ThreadContextProvider {
4    static mut HANDLER: ThreadContextProvider = {
5        extern "C" fn default_provider() -> *mut crate::records::thread_context::ThreadContext {
6            core::ptr::null_mut()
7        }
8        default_provider
9    };
10
11    // Safety: In the original C++, this is a function-local static.
12    // While C++11 guarantees thread-safe initialization for statics,
13    // it does not guarantee thread-safe access to the object itself.
14    // Luau's TimeTrace usage of this global provider is typically
15    // configured once at startup or in a single-threaded context.
16    unsafe { &mut HANDLER }
17}