Use `Waker::will_wake()` to avoid a cloning op (#12)
This commit is contained in:
parent
b96ee39889
commit
4320c6739e
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue