summaryrefslogtreecommitdiffstats
path: root/tokio/src/sync/batch_semaphore.rs
diff options
context:
space:
mode:
authorBlas Rodriguez Irizar <rodrigblas@gmail.com>2020-08-08 22:41:55 +0200
committerGitHub <noreply@github.com>2020-08-08 13:41:55 -0700
commit27bfe52bba06283df3e9481b89a903390ee70369 (patch)
tree796f00f6a3c39da09a7bc4c7bbfbb7c5fff04a9c /tokio/src/sync/batch_semaphore.rs
parent6ccefb77e273d8bfda72d638404c797fc8d5f2d4 (diff)
sync: show correct permits in fmt::Debug (#2750)
Fixes: #2744
Diffstat (limited to 'tokio/src/sync/batch_semaphore.rs')
-rw-r--r--tokio/src/sync/batch_semaphore.rs5
1 files changed, 4 insertions, 1 deletions
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()
}
}