mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-28 12:10:37 +00:00
sync: replace non-binding if let
statements (#4735)
Found some `if let` statements that don't actually bind any variables. This can make it somewhat confusing as to whether the pattern is binding the value or being matched against. Switching to `matches!` and equality comparisons allow these to be removed. Co-authored-by: David Koloski <dkoloski@google.com>
This commit is contained in:
parent
4941fbf7c4
commit
0d4d3c34f1
@ -501,7 +501,7 @@ impl Notify {
|
|||||||
// transition out of WAITING while the lock is held.
|
// transition out of WAITING while the lock is held.
|
||||||
let curr = self.state.load(SeqCst);
|
let curr = self.state.load(SeqCst);
|
||||||
|
|
||||||
if let EMPTY | NOTIFIED = get_state(curr) {
|
if matches!(get_state(curr), EMPTY | NOTIFIED) {
|
||||||
// There are no waiting tasks. All we need to do is increment the
|
// There are no waiting tasks. All we need to do is increment the
|
||||||
// number of times this method was called.
|
// number of times this method was called.
|
||||||
atomic_inc_num_notify_waiters_calls(&self.state);
|
atomic_inc_num_notify_waiters_calls(&self.state);
|
||||||
@ -896,7 +896,7 @@ impl Drop for Notified<'_> {
|
|||||||
// This is where we ensure safety. The `Notified` value is being
|
// This is where we ensure safety. The `Notified` value is being
|
||||||
// dropped, which means we must ensure that the waiter entry is no
|
// dropped, which means we must ensure that the waiter entry is no
|
||||||
// longer stored in the linked list.
|
// longer stored in the linked list.
|
||||||
if let Waiting = *state {
|
if matches!(*state, Waiting) {
|
||||||
let mut waiters = notify.waiters.lock();
|
let mut waiters = notify.waiters.lock();
|
||||||
let mut notify_state = notify.state.load(SeqCst);
|
let mut notify_state = notify.state.load(SeqCst);
|
||||||
|
|
||||||
@ -906,11 +906,9 @@ impl Drop for Notified<'_> {
|
|||||||
// being the only `LinkedList` available to the type.
|
// being the only `LinkedList` available to the type.
|
||||||
unsafe { waiters.remove(NonNull::new_unchecked(waiter.get())) };
|
unsafe { waiters.remove(NonNull::new_unchecked(waiter.get())) };
|
||||||
|
|
||||||
if waiters.is_empty() {
|
if waiters.is_empty() && get_state(notify_state) == WAITING {
|
||||||
if let WAITING = get_state(notify_state) {
|
notify_state = set_state(notify_state, EMPTY);
|
||||||
notify_state = set_state(notify_state, EMPTY);
|
notify.state.store(notify_state, SeqCst);
|
||||||
notify.state.store(notify_state, SeqCst);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// See if the node was notified but not received. In this case, if
|
// See if the node was notified but not received. In this case, if
|
||||||
@ -919,7 +917,10 @@ impl Drop for Notified<'_> {
|
|||||||
//
|
//
|
||||||
// Safety: with the entry removed from the linked list, there can be
|
// Safety: with the entry removed from the linked list, there can be
|
||||||
// no concurrent access to the entry
|
// no concurrent access to the entry
|
||||||
if let Some(NotificationType::OneWaiter) = unsafe { (*waiter.get()).notified } {
|
if matches!(
|
||||||
|
unsafe { (*waiter.get()).notified },
|
||||||
|
Some(NotificationType::OneWaiter)
|
||||||
|
) {
|
||||||
if let Some(waker) = notify_locked(&mut waiters, ¬ify.state, notify_state) {
|
if let Some(waker) = notify_locked(&mut waiters, ¬ify.state, notify_state) {
|
||||||
drop(waiters);
|
drop(waiters);
|
||||||
waker.wake();
|
waker.wake();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user