Skip to content

Commit

Permalink
Merge pull request #1 from AscendingCreations/tests
Browse files Browse the repository at this point in the history
Remove mutex
  • Loading branch information
Andrew Wheeler(Genusis) authored Sep 7, 2023
2 parents 3aa1003 + e6fbbfa commit 9a7f662
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
11 changes: 4 additions & 7 deletions src/pool/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
Expand Down
9 changes: 3 additions & 6 deletions src/pool/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArrayQueue<Connection>>,
pub(crate) pool: ArrayQueue<Connection>,
pub(crate) client: Client,
}

impl SharedPool {
pub(crate) fn new_arc(client: Client, limit: u32) -> Arc<Self> {
let pool = Self {
pool: Mutex::new(ArrayQueue::new(limit as usize)),
pool: ArrayQueue::new(limit as usize),
client,
};

Expand All @@ -22,9 +21,7 @@ impl SharedPool {

pub(crate) async fn aquire(self: Arc<Self>) -> Result<RedisConnection, RedisError> {
{
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));
}
}
Expand Down

0 comments on commit 9a7f662

Please sign in to comment.