mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2025-12-08 08:42:41 -05:00
add a TimerGuard around db locks & ops
I moved the clocks member from LockedDatabase to Database to make this happen, so the new DatabaseGuard (replacing a direct MutexGuard<LockedDatabase>) can access it before acquiring the lock. I also made the type of clock a type parameter of Database (and so several other things throughout the system). This allowed me to drop the Arc<>, but more importantly it means that the Clocks trait doesn't need to stay object-safe. I plan to take advantage of that shortly.
This commit is contained in:
@@ -125,7 +125,7 @@ struct Args {
|
||||
pub fn run() -> Result<(), Error> {
|
||||
let args: Args = super::parse_args(USAGE)?;
|
||||
let (_db_dir, conn) = super::open_conn(&args.flag_db_dir, super::OpenMode::ReadWrite)?;
|
||||
let clocks = Arc::new(clock::RealClocks{});
|
||||
let clocks = clock::RealClocks {};
|
||||
let db = Arc::new(db::Database::new(clocks, conn, true)?);
|
||||
|
||||
let mut siv = Cursive::new();
|
||||
|
||||
@@ -66,7 +66,7 @@ pub fn run() -> Result<(), Error> {
|
||||
pragma journal_mode = wal;
|
||||
pragma page_size = 16384;
|
||||
"#)?;
|
||||
db::Database::init(&mut conn)?;
|
||||
db::init(&mut conn)?;
|
||||
info!("Database initialized.");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ struct Syncer {
|
||||
|
||||
pub fn run() -> Result<(), Error> {
|
||||
let args: Args = super::parse_args(USAGE)?;
|
||||
let clocks = Arc::new(clock::RealClocks{});
|
||||
let clocks = clock::RealClocks {};
|
||||
let (_db_dir, conn) = super::open_conn(
|
||||
&args.flag_db_dir,
|
||||
if args.flag_read_only { super::OpenMode::ReadOnly } else { super::OpenMode::ReadWrite })?;
|
||||
@@ -123,7 +123,6 @@ pub fn run() -> Result<(), Error> {
|
||||
let streams = l.streams_by_id().len();
|
||||
let env = streamer::Environment {
|
||||
db: &db,
|
||||
clocks: clocks.clone(),
|
||||
opener: &*stream::FFMPEG,
|
||||
shutdown: &shutdown_streamers,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user