Skip to content

Commit cd5b0ba

Browse files
committed
chore: switch to std::task::Wake
`tokio::util::Wake` was a copy of `std::task::Wake`, which is now stable for our MSRV.
1 parent 23c6ad6 commit cd5b0ba

File tree

4 files changed

+19
-28
lines changed

4 files changed

+19
-28
lines changed

tokio/src/runtime/scheduler/current_thread/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ use crate::runtime::{
1010
};
1111
use crate::sync::notify::Notify;
1212
use crate::util::atomic_cell::AtomicCell;
13-
use crate::util::{waker_ref, RngSeedGenerator, Wake, WakerRef};
13+
use crate::util::{waker_ref, RngSeedGenerator, WakerRef};
1414

1515
use std::cell::RefCell;
1616
use std::collections::VecDeque;
1717
use std::future::{poll_fn, Future};
1818
use std::sync::atomic::Ordering::{AcqRel, Release};
1919
use std::task::Poll::{Pending, Ready};
20-
use std::task::Waker;
20+
use std::task::{Wake, Waker};
2121
use std::thread::ThreadId;
2222
use std::time::Duration;
2323
use std::{fmt, thread};
@@ -694,14 +694,14 @@ impl Schedule for Arc<Handle> {
694694
}
695695

696696
impl Wake for Handle {
697-
fn wake(arc_self: Arc<Self>) {
698-
Wake::wake_by_ref(&arc_self);
697+
fn wake(self: Arc<Self>) {
698+
self.wake_by_ref();
699699
}
700700

701701
/// Wake by reference
702-
fn wake_by_ref(arc_self: &Arc<Self>) {
703-
arc_self.shared.woken.store(true, Release);
704-
arc_self.driver.unpark();
702+
fn wake_by_ref(self: &Arc<Self>) {
703+
self.shared.woken.store(true, Release);
704+
self.driver.unpark();
705705
}
706706
}
707707

tokio/src/util/idle_notified_set.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
use std::marker::PhantomPinned;
1010
use std::mem::ManuallyDrop;
1111
use std::ptr::NonNull;
12-
use std::task::{Context, Waker};
12+
use std::task::{Context, Wake, Waker};
1313

1414
use crate::loom::cell::UnsafeCell;
1515
use crate::loom::sync::{Arc, Mutex};
1616
use crate::util::linked_list::{self, Link};
17-
use crate::util::{waker_ref, Wake};
17+
use crate::util::waker_ref;
1818

1919
type LinkedList<T> =
2020
linked_list::LinkedList<ListEntry<T>, <ListEntry<T> as linked_list::Link>::Target>;
@@ -432,12 +432,16 @@ impl<T> Drop for IdleNotifiedSet<T> {
432432
}
433433

434434
impl<T: 'static> Wake for ListEntry<T> {
435-
fn wake_by_ref(me: &Arc<Self>) {
436-
let mut lock = me.parent.lock();
435+
fn wake(self: Arc<Self>) {
436+
self.wake_by_ref();
437+
}
438+
439+
fn wake_by_ref(self: &Arc<Self>) {
440+
let mut lock = self.parent.lock();
437441

438442
// Safety: We are holding the lock and we will update the lists to
439443
// maintain invariants.
440-
let old_my_list = me.my_list.with_mut(|ptr| unsafe {
444+
let old_my_list = self.my_list.with_mut(|ptr| unsafe {
441445
let old_my_list = *ptr;
442446
if old_my_list == List::Idle {
443447
*ptr = List::Notified;
@@ -449,7 +453,7 @@ impl<T: 'static> Wake for ListEntry<T> {
449453
// We move ourself to the notified list.
450454
let me = unsafe {
451455
// Safety: We just checked that we are in this particular list.
452-
lock.idle.remove(ListEntry::as_raw(me)).unwrap()
456+
lock.idle.remove(ListEntry::as_raw(self)).unwrap()
453457
};
454458
lock.notified.push_front(me);
455459

@@ -459,10 +463,6 @@ impl<T: 'static> Wake for ListEntry<T> {
459463
}
460464
}
461465
}
462-
463-
fn wake(me: Arc<Self>) {
464-
Self::wake_by_ref(&me);
465-
}
466466
}
467467

468468
/// # Safety

tokio/src/util/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ cfg_rt! {
6868

6969
mod wake;
7070
pub(crate) use wake::WakerRef;
71-
pub(crate) use wake::{waker_ref, Wake};
71+
pub(crate) use wake::waker_ref;
7272

7373
mod sync_wrapper;
7474
pub(crate) use sync_wrapper::SyncWrapper;

tokio/src/util/wake.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,7 @@ use crate::loom::sync::Arc;
33
use std::marker::PhantomData;
44
use std::mem::ManuallyDrop;
55
use std::ops::Deref;
6-
use std::task::{RawWaker, RawWakerVTable, Waker};
7-
8-
/// Simplified waking interface based on Arcs.
9-
pub(crate) trait Wake: Send + Sync + Sized + 'static {
10-
/// Wake by value.
11-
fn wake(arc_self: Arc<Self>);
12-
13-
/// Wake by reference.
14-
fn wake_by_ref(arc_self: &Arc<Self>);
15-
}
6+
use std::task::{RawWaker, RawWakerVTable, Wake, Waker};
167

178
/// A `Waker` that is only valid for a given lifetime.
189
#[derive(Debug)]

0 commit comments

Comments
 (0)