mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-05 14:10:18 +08:00
refactor(backend): share single-owner drivers for background tasks (#8759)
* docs(backend): define background task ownership * refactor(backend): give background operations single task owners * test(backend): remove actor migration regression cases * docs(changelog): drop backend actor migration entry * refactor(backend): extract workspace task drivers * fix(timer): omit profile identifier from panic log * docs(backend): define workspace crate boundaries * refactor(lightweight): use the task countdown driver * refactor(lightweight): name countdown callbacks * refactor(task): simplify driver startup and coalescing requests * refactor(core): bind service handoff to the sidecar generation * refactor(tun): coalesce background run state reconciliation * refactor(core): own sidecar exit resources in one session * refactor(core): remove automatic Windows service handoff * refactor(task): simplify coalescing job signals * refactor(runstate): keep operation status with service state * refactor(dns): coalesce background override synchronization * refactor(sysproxy): own the local guard under its operation lock * fix(tray): read menu settings at publication * fix(dns): retain script lock across caller cancellation * refactor(profiles): own selected node restoration in one task * refactor(timer): own subscription schedules in the scheduler * test(timer): remove the added application test * fix(service): renew provider sync retry budget on refresh
This commit is contained in:
@@ -4,19 +4,37 @@ use crate::core::notify::NoticeStatus;
|
||||
|
||||
use std::{
|
||||
mem::DropGuard,
|
||||
sync::atomic::{AtomicBool, Ordering},
|
||||
sync::{
|
||||
LazyLock,
|
||||
atomic::{AtomicBool, Ordering},
|
||||
},
|
||||
};
|
||||
|
||||
use clash_verge_logging::{Type, logging};
|
||||
use clash_verge_task::scheduled_task::{self, CoalescingJob};
|
||||
|
||||
use crate::{
|
||||
config::{Config, IVerge},
|
||||
core::{handle::Handle, manager::RunningMode, runstate::RUN_STATE},
|
||||
process::AsyncHandler,
|
||||
};
|
||||
|
||||
/// Prevents recursive runtime disable writes.
|
||||
static DISABLING_TUN: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
static TUN_RECONCILE: LazyLock<CoalescingJob> = LazyLock::new(|| {
|
||||
AsyncHandler::start_driver(scheduled_task::coalescing(reconcile_tun_availability, || {
|
||||
logging!(error, Type::Core, "TUN reconciliation panicked");
|
||||
}))
|
||||
});
|
||||
|
||||
pub(crate) fn request_tun_reconciliation() {
|
||||
// The internal disable can publish Run State as part of its own effects.
|
||||
if !DISABLING_TUN.load(Ordering::Acquire) {
|
||||
TUN_RECONCILE.request();
|
||||
}
|
||||
}
|
||||
|
||||
/// Turn TUN off when startup confirms the Service is absent, so the Core can start on Sidecar.
|
||||
///
|
||||
/// Runs before the runtime config is generated.
|
||||
@@ -61,7 +79,7 @@ pub async fn reconcile_tun_availability() {
|
||||
return;
|
||||
}
|
||||
|
||||
// The flag coalesces newly spawned tasks while the config lock serializes writers.
|
||||
// Suppress recursive requests while the config lock serializes writers.
|
||||
DISABLING_TUN.store(true, Ordering::Release);
|
||||
let _disabling_tun = DropGuard::new((), |()| {
|
||||
DISABLING_TUN.store(false, Ordering::Release);
|
||||
|
||||
Reference in New Issue
Block a user