Files
continuwuity/src/database/cork.rs
T

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

34 lines
432 B
Rust
Raw Normal View History

2024-04-06 01:24:08 -07:00
use std::sync::Arc;
2024-05-28 06:59:50 +00:00
use crate::Engine;
2024-04-06 01:24:08 -07:00
2024-05-09 15:59:08 -07:00
pub struct Cork {
2024-05-28 06:59:50 +00:00
db: Arc<Engine>,
2024-04-06 01:24:08 -07:00
flush: bool,
sync: bool,
}
impl Cork {
#[inline]
2024-07-01 20:54:38 +00:00
pub(super) fn new(db: &Arc<Engine>, flush: bool, sync: bool) -> Self {
2024-05-28 06:59:50 +00:00
db.cork();
2024-06-09 10:23:06 +00:00
Self {
2024-04-06 01:24:08 -07:00
db: db.clone(),
flush,
sync,
}
}
}
impl Drop for Cork {
fn drop(&mut self) {
2024-05-28 06:59:50 +00:00
self.db.uncork();
2024-04-06 01:24:08 -07:00
if self.flush {
self.db.flush().ok();
}
if self.sync {
self.db.sync().ok();
}
}
}