Fix second audit findings and restore crash detection dialog

This commit is contained in:
2026-02-27 22:48:43 +02:00
parent df8606251f
commit 1da69dd44e
21 changed files with 228 additions and 181 deletions

View File

@@ -1,4 +1,5 @@
use std::path::PathBuf;
use std::sync::{Condvar, Mutex};
use std::sync::atomic::{AtomicUsize, Ordering};
use crate::core::database::Database;
@@ -14,17 +15,21 @@ const MAX_CONCURRENT_ANALYSES: usize = 2;
/// Counter for currently running analyses.
static RUNNING_ANALYSES: AtomicUsize = AtomicUsize::new(0);
/// Condvar to efficiently wait for a slot instead of busy-polling.
static SLOT_AVAILABLE: (Mutex<()>, Condvar) = (Mutex::new(()), Condvar::new());
/// Returns the number of currently running background analyses.
pub fn running_count() -> usize {
RUNNING_ANALYSES.load(Ordering::Relaxed)
}
/// RAII guard that decrements the analysis counter on drop.
/// RAII guard that decrements the analysis counter on drop and notifies waiters.
struct AnalysisGuard;
impl Drop for AnalysisGuard {
fn drop(&mut self) {
RUNNING_ANALYSES.fetch_sub(1, Ordering::Release);
SLOT_AVAILABLE.1.notify_one();
}
}
@@ -36,7 +41,7 @@ impl Drop for AnalysisGuard {
///
/// Blocks until a slot is available if the concurrency limit is reached.
pub fn run_background_analysis(id: i64, path: PathBuf, appimage_type: AppImageType, integrate: bool) {
// Wait for a slot to become available
// Wait for a slot to become available using condvar instead of busy-polling
loop {
let current = RUNNING_ANALYSES.load(Ordering::Acquire);
if current < MAX_CONCURRENT_ANALYSES {
@@ -44,7 +49,8 @@ pub fn run_background_analysis(id: i64, path: PathBuf, appimage_type: AppImageTy
break;
}
} else {
std::thread::sleep(std::time::Duration::from_millis(200));
let lock = SLOT_AVAILABLE.0.lock().unwrap();
let _ = SLOT_AVAILABLE.1.wait_timeout(lock, std::time::Duration::from_secs(1));
}
}
let _guard = AnalysisGuard;