refactor: replace OnceCell with AtomicBool for UI readiness state

This commit is contained in:
Tunglies
2025-11-09 02:29:50 +08:00
parent a57ffba8ba
commit 243f5b1b96

View File

@@ -8,8 +8,8 @@ use tokio::sync::Notify;
use crate::{logging, utils::logging::Type}; use crate::{logging, utils::logging::Type};
// 使用 AtomicBool 替代 RwLock<bool>,性能更好且无锁 // 获取 UI 是否准备就绪的全局状态
static UI_READY: OnceCell<AtomicBool> = OnceCell::new(); static UI_READY: AtomicBool = AtomicBool::new(false);
// 获取UI就绪状态细节 // 获取UI就绪状态细节
static UI_READY_STATE: OnceCell<UiReadyState> = OnceCell::new(); static UI_READY_STATE: OnceCell<UiReadyState> = OnceCell::new();
// 添加通知机制,用于事件驱动的 UI 就绪检测 // 添加通知机制,用于事件驱动的 UI 就绪检测
@@ -39,8 +39,8 @@ impl Default for UiReadyState {
} }
} }
pub(super) fn get_ui_ready() -> &'static AtomicBool { pub fn get_ui_ready() -> &'static AtomicBool {
UI_READY.get_or_init(|| AtomicBool::new(false)) &UI_READY
} }
fn get_ui_ready_state() -> &'static UiReadyState { fn get_ui_ready_state() -> &'static UiReadyState {