use crate::locksmith::tracker::GuardTracker;
use parking_lot::{Mutex, MutexGuard};
use snowflake::ProcessUniqueId;
use std::{collections::HashMap, time::Duration};
lazy_static! {
pub(crate) static ref IMMORTAL_TIMEOUT: Duration = Duration::from_secs(60);
pub(crate) static ref LOCK_TIMEOUT: Duration = Duration::from_secs(120);
pub(crate) static ref GUARD_WATCHER_POLL_INTERVAL: Duration = Duration::from_millis(1000);
pub(crate) static ref ACTIVE_GUARD_MIN_ELAPSED: Duration = Duration::from_millis(1000);
pub(crate) static ref ACTIVE_GUARD_NO_ACTIVITY_INTERVAL: Duration = Duration::from_secs(10);
static ref GUARDS: Mutex<GuardsMap> = Mutex::new(HashMap::new());
}
type GuardsMap = HashMap<ProcessUniqueId, GuardTracker>;
pub(crate) fn guards_guard<'a>() -> MutexGuard<'a, GuardsMap> {
GUARDS
.try_lock_for(Duration::from_secs(20))
.expect("Guard-tracking mutex has been locked up for 20 seconds!")
}