Use `Waker::will_wake()` to avoid a cloning op

This commit is contained in:
dAxpeDDa 2023-03-15 22:30:55 +01:00
parent b96ee39889
commit ab5c1b1c85
No known key found for this signature in database
GPG Key ID: 43D62A3EA388E46F
1 changed files with 6 additions and 1 deletions

View File

@ -285,7 +285,12 @@ impl AtomicWaker {
WAITING => {
unsafe {
// Locked acquired, update the waker cell
*self.waker.get() = Some(waker.clone());
// Avoid cloning the waker if the old waker will awaken the same task.
match &*self.waker.get() {
Some(old_waker) if old_waker.will_wake(waker) => (),
_ => *self.waker.get() = Some(waker.clone()),
}
// Release the lock. If the state transitioned to include
// the `WAKING` bit, this means that at least one wake has