Skip to content

Commit 79ae892

Browse files
committed
Fix remaining compilation errors
1 parent c131541 commit 79ae892

File tree

16 files changed

+47
-57
lines changed

16 files changed

+47
-57
lines changed

futures-core/src/task/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ pub mod __internal;
66
pub use self::spawn::{Spawn, LocalSpawn, SpawnError};
77

88
pub use core::task::{Poll, Waker, RawWaker, RawWakerVTable};
9-
pub use self::Waker as LocalWaker;

futures-executor/src/local_pool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn run_executor<T, F: FnMut(&Waker) -> Poll<T>>(mut f: F) -> T {
6767
another executor");
6868

6969
CURRENT_THREAD_NOTIFY.with(|thread_notify| {
70-
let waker: WakerRef = unsafe { waker_ref(thread_notify) };
70+
let waker: WakerRef = waker_ref(thread_notify);
7171
loop {
7272
if let Poll::Ready(t) = f(&waker) {
7373
return t;

futures-executor/src/thread_pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::enter;
22
use crate::unpark_mutex::UnparkMutex;
33
use futures_core::future::{Future, FutureObj};
4-
use futures_core::task::{Poll, ArcWake, Spawn, SpawnError};
4+
use futures_core::task::{Poll, Spawn, SpawnError};
55
use futures_util::future::FutureExt;
6-
use futures_util::task::waker_ref;
6+
use futures_util::task::{ArcWake, waker_ref};
77
use num_cpus;
88
use std::io;
99
use std::prelude::v1::*;

futures-test/src/task/panic_waker.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ unsafe fn wake_panic(_data: *const()) {
1313
panic!("should not be woken");
1414
}
1515

16-
unsafe fn noop_into_waker(_data: *const()) -> Option<RawWaker> {
17-
Some(raw_panic_waker())
18-
}
19-
2016
const PANIC_WAKER_VTABLE: RawWakerVTable = RawWakerVTable {
2117
clone: noop_clone,
2218
drop_fn: noop,

futures-test/src/task/wake_counter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use futures_core::task::{local_waker_from_nonlocal, Waker, Wake};
1+
use futures_core::task::{Waker};
22
use std::sync::Arc;
33
use std::sync::atomic::{AtomicUsize, Ordering};
44
use futures_util::task::ArcWake;

futures-util/src/future/catch_unwind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl<Fut> Future for CatchUnwind<Fut>
2929
type Output = Result<Fut::Output, Box<dyn Any + Send>>;
3030

3131
fn poll(self: Pin<&mut Self>, waker: &Waker) -> Poll<Self::Output> {
32-
match catch_unwind(AssertUnwindSafe(|| self.future().poll(lw))) {
32+
match catch_unwind(AssertUnwindSafe(|| self.future().poll(waker))) {
3333
Ok(res) => res.map(Ok),
3434
Err(e) => Poll::Ready(Err(e))
3535
}

futures-util/src/future/join_all.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ where
135135

136136
for mut elem in iter_pin_mut(self.elems.as_mut()) {
137137
if let Some(pending) = elem.as_mut().pending_pin_mut() {
138-
if let Poll::Ready(output) = pending.poll(lw) {
138+
if let Poll::Ready(output) = pending.poll(waker) {
139139
elem.set(ElemState::Done(Some(output)));
140140
} else {
141141
all_done = false;

futures-util/src/future/shared.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::task::local_waker_ref_from_nonlocal;
1+
use crate::task::{ArcWake, waker_ref};
22
use futures_core::future::{FusedFuture, Future};
3-
use futures_core::task::{Waker, Poll, ArcWake};
3+
use futures_core::task::{Waker, Poll};
44
use slab::Slab;
55
use std::cell::UnsafeCell;
66
use std::fmt;
@@ -126,7 +126,7 @@ where
126126
};
127127

128128
if self.waker_key == NULL_WAKER_KEY {
129-
self.waker_key = wakers.insert(Some(waker.clone().into_waker()));
129+
self.waker_key = wakers.insert(Some(waker.clone()));
130130
} else {
131131
let waker_slot = &mut wakers[self.waker_key];
132132
let needs_replacement = if let Some(_old_waker) = waker_slot {
@@ -139,7 +139,7 @@ where
139139
true
140140
};
141141
if needs_replacement {
142-
*waker_slot = Some(waker.clone().into_waker());
142+
*waker_slot = Some(waker.clone());
143143
}
144144
}
145145
debug_assert!(self.waker_key != NULL_WAKER_KEY);
@@ -216,7 +216,7 @@ where
216216
_ => unreachable!(),
217217
}
218218

219-
let waker = local_waker_ref_from_nonlocal(&inner.notifier);
219+
let waker = waker_ref(&inner.notifier);
220220
let waker = &waker;
221221

222222
struct Reset<'a>(&'a AtomicUsize);

futures-util/src/lock/mutex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl Waiter {
4040
fn register(&mut self, waker: &Waker) {
4141
match self {
4242
Waiter::Waiting(waker) if waker.will_wake(waker) => {},
43-
_ => *self = Waiter::Waiting(waker.clone().into_waker()),
43+
_ => *self = Waiter::Waiting(waker.clone()),
4444
}
4545
}
4646

futures-util/src/stream/futures_unordered/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! An unbounded set of futures.
22
3-
use crate::task::AtomicWaker;
3+
use crate::task::{AtomicWaker};
44
use futures_core::future::{Future, FutureObj, LocalFutureObj};
55
use futures_core::stream::{FusedStream, Stream};
66
use futures_core::task::{Waker, Poll, Spawn, LocalSpawn, SpawnError};
@@ -402,7 +402,7 @@ impl<Fut: Future> Stream for FuturesUnordered<Fut> {
402402
// the internal allocation, appropriately accessing fields and
403403
// deallocating the task if need be.
404404
let res = {
405-
let waker = Task::local_waker(bomb.task.as_ref().unwrap());
405+
let waker = Task::waker_ref(bomb.task.as_ref().unwrap());
406406

407407
// Safety: We won't move the future ever again
408408
let future = unsafe { Pin::new_unchecked(future) };

futures-util/src/stream/futures_unordered/task.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::{Arc, Weak};
33
use std::sync::atomic::{AtomicPtr, AtomicBool};
44
use std::sync::atomic::Ordering::SeqCst;
55

6-
use crate::task::{ArcWake};
6+
use crate::task::{ArcWake, WakerRef, waker_ref};
77
use super::ReadyToRunQueue;
88
use super::abort::abort;
99

@@ -55,6 +55,13 @@ impl<Fut> ArcWake for Task<Fut> {
5555
}
5656
}
5757

58+
impl<Fut> Task<Fut> {
59+
/// Returns a waker reference for this task without cloning the Arc.
60+
pub(super) fn waker_ref<'a>(this: &'a Arc<Task<Fut>>) -> WakerRef<'a> {
61+
waker_ref(this)
62+
}
63+
}
64+
5865
impl<Fut> Drop for Task<Fut> {
5966
fn drop(&mut self) {
6067
// Since `Task<Fut>` is sent across all threads for any lifetime,

futures-util/src/task/arc_wake.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
use std::sync::Arc;
22
use std::task::{Waker, RawWaker, RawWakerVTable};
33

4+
macro_rules! waker_vtable {
5+
($ty:ident) => {
6+
&RawWakerVTable {
7+
clone: clone_arc_raw::<$ty>,
8+
drop_fn: drop_arc_raw::<$ty>,
9+
wake: wake_arc_raw::<$ty>,
10+
}
11+
};
12+
}
13+
414
/// A way of waking up a specific task.
515
///
616
/// By implementing this trait, types that are expected to be wrapped in an `Arc`
717
/// can be converted into `Waker` objects.
818
/// Those Wakers can be used to signal executors that a task it owns
919
/// is ready to be `poll`ed again.
10-
pub trait ArcWake: Send + Sync {
20+
pub trait ArcWake {
1121
/// Indicates that the associated task is ready to make progress and should
1222
/// be `poll`ed.
1323
///
@@ -30,21 +40,11 @@ pub trait ArcWake: Send + Sync {
3040
Waker::new_unchecked(RawWaker{
3141
data: ptr,
3242
vtable: waker_vtable!(Self),
33-
}
43+
})
3444
}
3545
}
3646
}
3747

38-
macro_rules! waker_vtable {
39-
($ty:ident) => {
40-
&RawWakerVTable {
41-
clone: clone_arc_raw::<$ty>,
42-
drop_fn: drop_arc_raw::<$ty>,
43-
wake: wake_arc_raw::<$ty>,
44-
}
45-
};
46-
}
47-
4848
unsafe fn increase_refcount<T: ArcWake>(data: *const()) {
4949
// Retain Arc by creating a copy
5050
let arc: Arc<T> = Arc::from_raw(data as *const T);
@@ -76,6 +76,7 @@ unsafe fn wake_arc_raw<T: ArcWake>(data: *const()) {
7676
#[cfg(test)]
7777
mod tests {
7878
use super::*;
79+
use std::sync::Mutex;
7980

8081
struct CountingWaker {
8182
nr_wake: Mutex<i32>,
@@ -106,6 +107,7 @@ mod tests {
106107

107108
let w1: Waker = ArcWake::into_waker(some_w.clone());
108109
assert_eq!(2, Arc::strong_count(&some_w));
110+
w1.wake();
109111
assert_eq!(1, some_w.wakes());
110112

111113
let w2 = w1.clone();

futures-util/src/task/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod spawn;
1212
pub use self::spawn::{SpawnExt, LocalSpawnExt};
1313

1414
#[cfg(feature = "std")]
15-
mod local_waker_ref;
15+
mod waker_ref;
1616
#[cfg(feature = "std")]
1717
pub use self::waker_ref::{waker_ref, WakerRef};
1818

@@ -24,4 +24,4 @@ pub use futures_core::task::__internal::AtomicWaker;
2424

2525
// re-export for `select!`
2626
#[doc(hidden)]
27-
pub use futures_core::task::{LocalWaker, Poll};
27+
pub use futures_core::task::{Waker, Poll};

futures-util/src/task/noop_waker.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Utilities for creating zero-cost wakers that don't do anything.
2-
use futures_core::task::{RawWaker, RawWakerVTable};
2+
use futures_core::task::{Waker, RawWaker, RawWakerVTable};
33
use core::ptr::null;
44
use core::cell::UnsafeCell;
55

@@ -10,15 +10,10 @@ unsafe fn noop_clone(_data: *const()) -> RawWaker {
1010
unsafe fn noop(_data: *const()) {
1111
}
1212

13-
unsafe fn noop_into_waker(_data: *const()) -> Option<RawWaker> {
14-
Some(noop_raw_waker())
15-
}
16-
1713
const NOOP_WAKER_VTABLE: RawWakerVTable = RawWakerVTable {
1814
clone: noop_clone,
1915
drop_fn: noop,
2016
wake: noop,
21-
into_waker: noop_into_waker,
2217
};
2318

2419
fn noop_raw_waker() -> RawWaker {

futures-util/src/task/waker_ref.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,22 @@ macro_rules! owned_vtable {
6464
/// Creates a reference to a [`Waker`](::std::task::Waker)
6565
/// from a local [`wake`](::std::task::Wake).
6666
///
67-
/// # Safety
68-
///
69-
/// This function requires that `wake` is "local" (created on the current thread).
7067
/// The resulting [`Waker`](::std::task::Waker) will call
71-
/// [`wake.wake_local()`](::std::task::Wake::wake_local)
72-
/// when awoken, and will call [`wake.wake()`](::std::task::Wake::wake) if
73-
/// awoken after being converted to a [`Waker`](::std::task::Waker).
68+
/// [`wake.wake()`](::std::task::Wake::wake) if awoken.
7469
#[inline]
75-
pub unsafe fn waker_ref<W>(wake: &Arc<W>) -> WakerRef<'_>
70+
pub fn waker_ref<W>(wake: &Arc<W>) -> WakerRef<'_>
7671
where
7772
W: ArcWake
7873
{
7974
// This uses the same mechanism as Arc::into_raw, without needing a reference.
8075
// This is potentially not stable
8176
let ptr = &*wake as &W as *const W as *const();
8277

83-
let waker = Waker::new_unchecked(RawWaker{
84-
data: ptr,
85-
vtable: ref_vtable!(W),
86-
});
78+
let waker = unsafe {
79+
Waker::new_unchecked(RawWaker{
80+
data: ptr,
81+
vtable: ref_vtable!(W),
82+
})};
8783
WakerRef::new(waker)
8884
}
8985

futures/src/lib.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,7 @@ pub mod task {
360360
361361
pub use futures_core::task::{
362362
Poll, Spawn, LocalSpawn, SpawnError,
363-
Waker, LocalWaker, RawWaker, RawWakerVTable
364-
};
365-
366-
#[cfg(feature = "std")]
367-
pub use futures_core::task::{
368-
ArcWake,
363+
Waker, RawWaker, RawWakerVTable
369364
};
370365

371366
#[cfg(feature = "std")]

0 commit comments

Comments
 (0)