sync: show correct permits in fmt::Debug (#2750)

Fixes: #2744
This commit is contained in:
Blas Rodriguez Irizar
2020-08-08 13:41:55 -07:00
committed by GitHub
parent 6ccefb77e2
commit 27bfe52bba
+4 -1
View File
@@ -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()
}
}