use super::Engine;
pub(crate) struct StatementGateGuard<'a> {
engine: &'a Engine,
_guard: Option<parking_lot::ReentrantMutexGuard<'a, ()>>,
counted: bool,
}
impl Drop for StatementGateGuard<'_> {
fn drop(&mut self) {
if self.counted && self.engine.runtime.terminations.leave_gate() {
self.engine.session_became_idle();
}
}
}
impl Engine {
pub(crate) fn lock_statement_gate(&self) -> StatementGateGuard<'_> {
let guard = self.runtime.statement_gate.lock();
let counted = guard.is_some();
if counted && self.runtime.terminations.enter_gate() {
self.session_became_busy();
}
StatementGateGuard {
engine: self,
_guard: guard,
counted,
}
}
}