From 27bfe52bba06283df3e9481b89a903390ee70369 Mon Sep 17 00:00:00 2001 From: Blas Rodriguez Irizar Date: Sat, 8 Aug 2020 22:41:55 +0200 Subject: sync: show correct permits in fmt::Debug (#2750) Fixes: #2744 --- tokio/src/sync/batch_semaphore.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tokio/src/sync/batch_semaphore.rs') diff --git a/tokio/src/sync/batch_semaphore.rs b/tokio/src/sync/batch_semaphore.rs index 070cd201..2baf7478 100644 --- a/tokio/src/sync/batch_semaphore.rs +++ b/tokio/src/sync/batch_semaphore.rs @@ -100,6 +100,9 @@ impl Semaphore { /// future. pub(crate) const MAX_PERMITS: usize = std::usize::MAX >> 3; const CLOSED: usize = 1; + // The least-significant bit in the number of permits is reserved to use + // as a flag indicating that the semaphore has been closed. Consequently + // PERMIT_SHIFT is used to leave that bit for that purpose. const PERMIT_SHIFT: usize = 1; /// Creates a new semaphore with the initial number of permits @@ -357,7 +360,7 @@ impl Semaphore { impl fmt::Debug for Semaphore { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("Semaphore") - .field("permits", &self.permits.load(Relaxed)) + .field("permits", &self.available_permits()) .finish() } } -- cgit v1.2.3