From 1ec569baf2412cf2eeef8d38d8054712e0fdc051 Mon Sep 17 00:00:00 2001 From: Kane Wang <50613gary@gmail.com> Date: Tue, 28 Nov 2023 04:03:57 +0800 Subject: [PATCH] Driver: Remove RwLock from ThreadPool (#206) --- src/driver/tasks/mixer/pool.rs | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/driver/tasks/mixer/pool.rs b/src/driver/tasks/mixer/pool.rs index 6b81230..66042fa 100644 --- a/src/driver/tasks/mixer/pool.rs +++ b/src/driver/tasks/mixer/pool.rs @@ -6,7 +6,7 @@ use crate::{ Config, }; use flume::Sender; -use parking_lot::RwLock; +use rusty_pool::ThreadPool; use std::{result::Result as StdResult, sync::Arc, time::Duration}; use symphonia_core::{ formats::{SeekMode, SeekTo}, @@ -16,18 +16,14 @@ use tokio::runtime::Handle; #[derive(Clone)] pub struct BlockyTaskPool { - pool: Arc>, + pool: ThreadPool, handle: Handle, } impl BlockyTaskPool { pub fn new(handle: Handle) -> Self { Self { - pool: Arc::new(RwLock::new(rusty_pool::ThreadPool::new( - 0, - 64, - Duration::from_secs(5), - ))), + pool: ThreadPool::new(0, 64, Duration::from_secs(5)), handle, } } @@ -52,8 +48,7 @@ impl BlockyTaskPool { far_pool.send_to_parse(out, lazy, callback, seek_time, config); }); } else { - let pool = self.pool.read(); - pool.execute(move || { + self.pool.execute(move || { let out = lazy.create(); far_pool.send_to_parse(out, lazy, callback, seek_time, config); }); @@ -91,10 +86,9 @@ impl BlockyTaskPool { seek_time: Option, ) { let pool_clone = self.clone(); - let pool = self.pool.read(); - pool.execute( - move || match input.promote(config.codec_registry, config.format_registry) { + self.pool.execute(move || { + match input.promote(config.codec_registry, config.format_registry) { Ok(LiveInput::Parsed(parsed)) => match seek_time { // If seek time is zero, then wipe it out. // Some formats (MKV) make SeekTo(0) require a backseek to realign with the @@ -110,8 +104,8 @@ impl BlockyTaskPool { Err(e) => { drop(callback.send(MixerInputResultMessage::ParseErr(e.into()))); }, - }, - ); + } + }); } pub fn seek( @@ -126,9 +120,8 @@ impl BlockyTaskPool { config: Arc, ) { let pool_clone = self.clone(); - let pool = self.pool.read(); - pool.execute(move || match rec { + self.pool.execute(move || match rec { Some(rec) if (!input.supports_backseek) && backseek_needed => { pool_clone.create(callback, Input::Lazy(rec), Some(seek_time), config); },