From 34d0cc4270d935ddfd9f2c3a08bc845ab3f499d2 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 5 Jun 2024 22:18:31 -0700 Subject: [PATCH] `fn rav1d_open`: Initialize `c.state.frame_thread.out_delayed` w/ `Mutex::new` and `..Default::default()` rather than taking the lock. --- src/lib.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fe0a09863..9932142fd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,6 +32,7 @@ use crate::src::internal::Rav1dBitDepthDSPContext; use crate::src::internal::Rav1dContext; use crate::src::internal::Rav1dContextTaskThread; use crate::src::internal::Rav1dContextTaskType; +use crate::src::internal::Rav1dContext_frame_thread; use crate::src::internal::Rav1dFrameContext; use crate::src::internal::Rav1dState; use crate::src::internal::Rav1dTaskContext; @@ -239,11 +240,17 @@ pub(crate) unsafe fn rav1d_open(c_out: &mut *const Rav1dContext, s: &Rav1dSettin delayed_fg: Default::default(), }; (*c).task_thread = Arc::new(ttd); - (*c).state.try_lock().unwrap().frame_thread.out_delayed = if n_fc > 1 { - (0..n_fc).map(|_| Default::default()).collect() - } else { - Box::new([]) - }; + (*c).state = Mutex::new(Rav1dState { + frame_thread: Rav1dContext_frame_thread { + out_delayed: if n_fc > 1 { + (0..n_fc).map(|_| Default::default()).collect() + } else { + Box::new([]) + }, + ..Default::default() + }, + ..Default::default() + }); for fc in (*c).fc.iter_mut() { fc.task_thread.finished = AtomicBool::new(true); fc.task_thread.ttd = Arc::clone(&(*c).task_thread);