Skip to content

Commit

Permalink
revert changes, is_hot_reload_enabled panic instead of initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinThierauf committed Feb 14, 2025
1 parent 67ebc57 commit 277379e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions godot-ffi/src/linux_reload_workaround.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
// See: https://fasterthanli.me/articles/so-you-want-to-live-reload-rust#what-can-prevent-dlclose-from-unloading-a-library

use std::ffi::c_void;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::OnceLock;

pub type ThreadAtexitFn = unsafe extern "C" fn(*mut c_void, *mut c_void, *mut c_void);

static SYSTEM_THREAD_ATEXIT: OnceLock<Option<ThreadAtexitFn>> = OnceLock::new();
static HOT_RELOADING_ENABLED: AtomicBool = AtomicBool::new(false);
static HOT_RELOADING_ENABLED: OnceLock<bool> = OnceLock::new();

fn system_thread_atexit() -> &'static Option<ThreadAtexitFn> {
SYSTEM_THREAD_ATEXIT.get_or_init(|| unsafe {
Expand All @@ -30,12 +29,14 @@ fn system_thread_atexit() -> &'static Option<ThreadAtexitFn> {

pub fn enable_hot_reload() {
// If hot reloading is enabled then we should properly unload the library, so this will only be called once.
HOT_RELOADING_ENABLED.store(true, Ordering::SeqCst);
HOT_RELOADING_ENABLED
.set(true)
.expect("hot reloading should only be set once")
}

pub fn disable_hot_reload() {
// If hot reloading is disabled then we may call this method multiple times.
HOT_RELOADING_ENABLED.store(false, Ordering::SeqCst);
_ = HOT_RELOADING_ENABLED.set(false);
}

pub fn default_set_hot_reload() {
Expand All @@ -53,7 +54,7 @@ fn is_hot_reload_enabled() -> bool {
// destructors exist for good reasons.
// This is needed for situations like unit-tests, where we may create TLS-destructors without explicitly calling any of the methods
// that set hot reloading to be enabled or disabled.
HOT_RELOADING_ENABLED.load(Ordering::SeqCst)
*HOT_RELOADING_ENABLED.get().expect("hot reloading status has not yet been marked as enabled/disabled")
}

/// Turns glibc's TLS destructor register function, `__cxa_thread_atexit_impl`,
Expand Down

0 comments on commit 277379e

Please sign in to comment.