Files
tuwunel/src/database/cork.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
783 B
Rust
Raw Normal View History

use std::sync::Arc;
use crate::{Database, Engine};
pub struct Cork {
2025-09-09 18:12:38 +05:00
engine: Arc<Engine>,
flush: bool,
sync: bool,
}
impl Database {
#[inline]
#[must_use]
2025-09-09 18:12:38 +05:00
pub fn cork(&self) -> Cork { Cork::new(&self.engine, false, false) }
#[inline]
#[must_use]
2025-09-09 18:12:38 +05:00
pub fn cork_and_flush(&self) -> Cork { Cork::new(&self.engine, true, false) }
#[inline]
#[must_use]
2025-09-09 18:12:38 +05:00
pub fn cork_and_sync(&self) -> Cork { Cork::new(&self.engine, true, true) }
}
impl Cork {
#[inline]
2025-09-09 18:12:38 +05:00
pub(super) fn new(engine: &Arc<Engine>, flush: bool, sync: bool) -> Self {
engine.cork();
Self { engine: engine.clone(), flush, sync }
}
}
impl Drop for Cork {
fn drop(&mut self) {
2025-09-09 18:12:38 +05:00
self.engine.uncork();
if self.flush {
2025-09-09 18:12:38 +05:00
self.engine.flush().ok();
}
if self.sync {
2025-09-09 18:12:38 +05:00
self.engine.sync().ok();
}
}
}