Skip to content

Commit

Permalink
sync: rename local variable in Semaphore::poll_acquire
Browse files Browse the repository at this point in the history
  • Loading branch information
cip999 committed Jan 10, 2025
1 parent 74df9e7 commit b4e45b0
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tokio/src/sync/batch_semaphore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ impl Semaphore {
} << Self::PERMIT_SHIFT;

let mut available = self.permits.load(Acquire);
let mut acquired: usize;
let mut acquired_shifted: usize;

// We could acquire the lock right now, but that's going to be
// expensive. To optimize, we try once without holding the mutex
Expand All @@ -429,8 +429,8 @@ impl Semaphore {
return Poll::Ready(Err(AcquireError::closed()));
}

acquired = cmp::min(available, still_needed);
let remaining = available - acquired;
acquired_shifted = cmp::min(available, still_needed);
let remaining = available - acquired_shifted;

// Not all permits were immediately available, so this waiter will
// (probably) need to wait. We'll need to acquire a lock on the wait
Expand All @@ -439,7 +439,7 @@ impl Semaphore {
// Otherwise, if we subtract the permits and then acquire the lock,
// we might miss additional permits being added while waiting for
// the lock.
if acquired < still_needed && queue_guard.is_none() {
if acquired_shifted < still_needed && queue_guard.is_none() {
queue_guard = Some(self.waiters.lock());
}

Expand All @@ -458,19 +458,19 @@ impl Semaphore {
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::state_update",
permits = (acquired >> Self::PERMIT_SHIFT),
permits = (acquired_shifted >> Self::PERMIT_SHIFT),
permits.op = "sub",
);
});

// If the waiter gets all the permits at the first try, don't bother
// enqueuing it.
if acquired == still_needed && !queued {
if acquired_shifted == still_needed && !queued {
#[cfg(all(tokio_unstable, feature = "tracing"))]
self.resource_span.in_scope(|| {
tracing::trace!(
target: "runtime::resource::async_op::state_update",
permits_obtained = (acquired >> Self::PERMIT_SHIFT),
permits_obtained = (acquired_shifted >> Self::PERMIT_SHIFT),
permits.op = "add",
)
});
Expand All @@ -482,7 +482,7 @@ impl Semaphore {
return Poll::Ready(Err(AcquireError::closed()));
}

acquired >>= Self::PERMIT_SHIFT;
let mut acquired = acquired_shifted >> Self::PERMIT_SHIFT;

if node.assign_permits(&mut acquired) {
// If the waiter is happy with the acquired permits, return the
Expand Down

0 comments on commit b4e45b0

Please sign in to comment.