mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
fix: Prevent crash on process exit on MacOS
This commit is contained in:
@@ -5,13 +5,17 @@
|
|||||||
|
|
||||||
use std::{collections::BTreeMap, sync::OnceLock};
|
use std::{collections::BTreeMap, sync::OnceLock};
|
||||||
|
|
||||||
use crate::{SyncMutex, utils::exchange};
|
use crate::utils::exchange;
|
||||||
|
|
||||||
/// Raw capture of rustc flags used to build each crate in the project. Informed
|
/// Raw capture of rustc flags used to build each crate in the project. Informed
|
||||||
/// by rustc_flags_capture macro (one in each crate's mod.rs). This is
|
/// by rustc_flags_capture macro (one in each crate's mod.rs). This is
|
||||||
/// done during static initialization which is why it's mutex-protected and pub.
|
/// done during static initialization which is why it's mutex-protected and pub.
|
||||||
/// Should not be written to by anything other than our macro.
|
/// Should not be written to by anything other than our macro.
|
||||||
pub static FLAGS: SyncMutex<BTreeMap<&str, &[&str]>> = SyncMutex::new(BTreeMap::new());
|
///
|
||||||
|
/// We specifically use a std mutex here because parking_lot cannot be used
|
||||||
|
/// after thread local storage is destroyed on MacOS.
|
||||||
|
pub static FLAGS: std::sync::Mutex<BTreeMap<&str, &[&str]>> =
|
||||||
|
std::sync::Mutex::new(BTreeMap::new());
|
||||||
|
|
||||||
/// Processed list of enabled features across all project crates. This is
|
/// Processed list of enabled features across all project crates. This is
|
||||||
/// generated from the data in FLAGS.
|
/// generated from the data in FLAGS.
|
||||||
@@ -24,6 +28,7 @@ fn init_features() -> Vec<&'static str> {
|
|||||||
let mut features = Vec::new();
|
let mut features = Vec::new();
|
||||||
FLAGS
|
FLAGS
|
||||||
.lock()
|
.lock()
|
||||||
|
.expect("locked")
|
||||||
.iter()
|
.iter()
|
||||||
.for_each(|(_, flags)| append_features(&mut features, flags));
|
.for_each(|(_, flags)| append_features(&mut features, flags));
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -15,13 +15,13 @@ pub(super) fn flags_capture(args: TokenStream) -> TokenStream {
|
|||||||
|
|
||||||
#[ctor]
|
#[ctor]
|
||||||
fn _set_rustc_flags() {
|
fn _set_rustc_flags() {
|
||||||
conduwuit_core::info::rustc::FLAGS.lock().insert(#crate_name, &RUSTC_FLAGS);
|
conduwuit_core::info::rustc::FLAGS.lock().expect("locked").insert(#crate_name, &RUSTC_FLAGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
// static strings have to be yanked on module unload
|
// static strings have to be yanked on module unload
|
||||||
#[dtor]
|
#[dtor]
|
||||||
fn _unset_rustc_flags() {
|
fn _unset_rustc_flags() {
|
||||||
conduwuit_core::info::rustc::FLAGS.lock().remove(#crate_name);
|
conduwuit_core::info::rustc::FLAGS.lock().expect("locked").remove(#crate_name);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user