diff --git a/src/ipc/context.rs b/src/ipc/context.rs index f8f7c30b..beff8e25 100644 --- a/src/ipc/context.rs +++ b/src/ipc/context.rs @@ -88,7 +88,6 @@ pub struct PooledContext { contexts: Vec>, } -#[derive(Clone)] pub struct PoolGuard where T: Clone, @@ -117,6 +116,20 @@ where } } +impl Clone for PoolGuard +where + T: Clone, +{ + fn clone(&self) -> Self { + self.acquire(); + + Self { + inner: self.inner.clone(), + count: Arc::clone(&self.count), + } + } +} + impl Drop for PoolGuard where T: Clone, @@ -137,19 +150,18 @@ where } } - /// Acquires the context by adding 1 to the count and - /// returning the cloned variant + /// Acquires the context by adding 1 to the count #[tracing::instrument(level = "trace", skip_all)] - pub(crate) fn acquire(&self) -> Self { - self.count.fetch_add(1, Ordering::Relaxed); - - self.clone() + pub(crate) fn acquire(&self) { + let count = self.count.fetch_add(1, Ordering::Relaxed); + tracing::trace!(count); } /// Releases the connection by subtracting from the stored count #[tracing::instrument(level = "trace", skip_all)] pub(crate) fn release(&self) { - self.count.fetch_sub(1, Ordering::Relaxed); + let count = self.count.fetch_sub(1, Ordering::Relaxed); + tracing::trace!(count); } pub(crate) fn count(&self) -> usize { @@ -173,6 +185,6 @@ impl PooledContext { .iter() .min_by_key(|c| c.count()) .unwrap() - .acquire() + .clone() } }