From e6fbbfa69e73a4410ec603e4f1bdfef6cedc90f3 Mon Sep 17 00:00:00 2001 From: genusistimelord Date: Thu, 7 Sep 2023 12:03:30 -0400 Subject: [PATCH] Remove mutex --- src/pool/connection.rs | 11 ++++------- src/pool/shared.rs | 9 +++------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/pool/connection.rs b/src/pool/connection.rs index 0b1c1a8..b8d9e81 100644 --- a/src/pool/connection.rs +++ b/src/pool/connection.rs @@ -31,14 +31,11 @@ impl Drop for RedisConnection { if self.connection.is_some() && self.pool.is_some() { let shared = self.pool.take().unwrap(); let connection = self.connection.take().unwrap(); - { - let pool = shared.pool.blocking_lock(); - if pool.len() < pool.capacity() { - // pool has space lets insert it back into the Pool - if pool.push(connection).is_err() { - panic!("Queue was maxed out"); - } + if shared.pool.len() < shared.pool.capacity() { + // pool has space lets insert it back into the Pool + if shared.pool.push(connection).is_err() { + panic!("Queue was maxed out"); } } } diff --git a/src/pool/shared.rs b/src/pool/shared.rs index d13f11b..54759e2 100644 --- a/src/pool/shared.rs +++ b/src/pool/shared.rs @@ -3,17 +3,16 @@ use crate::RedisError; use crossbeam_queue::ArrayQueue; pub use redis::{aio::Connection, Client}; use std::sync::Arc; -use tokio::sync::Mutex; pub(crate) struct SharedPool { - pub(crate) pool: Mutex>, + pub(crate) pool: ArrayQueue, pub(crate) client: Client, } impl SharedPool { pub(crate) fn new_arc(client: Client, limit: u32) -> Arc { let pool = Self { - pool: Mutex::new(ArrayQueue::new(limit as usize)), + pool: ArrayQueue::new(limit as usize), client, }; @@ -22,9 +21,7 @@ impl SharedPool { pub(crate) async fn aquire(self: Arc) -> Result { { - let pool = self.pool.lock().await; - - if let Some(connection) = pool.pop() { + if let Some(connection) = self.pool.pop() { return Ok(RedisConnection::new(Arc::clone(&self), connection)); } }