Skip to content

Commit 60aa11d

Browse files
Rename Executor trait to Spawn
1 parent aa1e6db commit 60aa11d

File tree

6 files changed

+54
-50
lines changed

6 files changed

+54
-50
lines changed

src/liballoc/boxed.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ use core::marker::{Unpin, Unsize};
6767
use core::mem::{self, PinMut};
6868
use core::ops::{CoerceUnsized, Deref, DerefMut, Generator, GeneratorState};
6969
use core::ptr::{self, NonNull, Unique};
70-
use core::task::{Context, Poll, Executor, SpawnErrorKind, SpawnObjError};
70+
use core::task::{Context, Poll, Spawn, SpawnErrorKind, SpawnObjError};
7171

7272
use raw_vec::RawVec;
7373
use str::from_boxed_utf8_unchecked;
@@ -973,11 +973,14 @@ unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for PinBox<F>
973973
}
974974

975975
#[unstable(feature = "futures_api", issue = "50547")]
976-
impl<E> Executor for Box<E>
977-
where E: Executor + ?Sized
976+
impl<Sp> Spawn for Box<Sp>
977+
where Sp: Spawn + ?Sized
978978
{
979-
fn spawn_obj(&mut self, task: FutureObj<'static, ()>) -> Result<(), SpawnObjError> {
980-
(**self).spawn_obj(task)
979+
fn spawn_obj(
980+
&mut self,
981+
future: FutureObj<'static, ()>,
982+
) -> Result<(), SpawnObjError> {
983+
(**self).spawn_obj(future)
981984
}
982985

983986
fn status(&self) -> Result<(), SpawnErrorKind> {

src/libcore/task/context.rs

+25-19
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
issue = "50547")]
1414

1515
use fmt;
16-
use super::{Executor, Waker, LocalWaker};
16+
use super::{Spawn, Waker, LocalWaker};
1717

1818
/// Information about the currently-running task.
1919
///
2020
/// Contexts are always tied to the stack, since they are set up specifically
2121
/// when performing a single `poll` step on a task.
2222
pub struct Context<'a> {
2323
local_waker: &'a LocalWaker,
24-
executor: &'a mut dyn Executor,
24+
spawner: &'a mut dyn Spawn,
2525
}
2626

2727
impl<'a> fmt::Debug for Context<'a> {
@@ -32,13 +32,14 @@ impl<'a> fmt::Debug for Context<'a> {
3232
}
3333

3434
impl<'a> Context<'a> {
35-
/// Create a new task `Context` with the provided `local_waker`, `waker`, and `executor`.
35+
/// Create a new task `Context` with the provided `local_waker`, `waker`,
36+
/// and `spawner`.
3637
#[inline]
37-
pub fn new(local_waker: &'a LocalWaker, executor: &'a mut dyn Executor) -> Context<'a> {
38-
Context {
39-
local_waker,
40-
executor,
41-
}
38+
pub fn new(
39+
local_waker: &'a LocalWaker,
40+
spawner: &'a mut dyn Spawn,
41+
) -> Context<'a> {
42+
Context { local_waker, spawner }
4243
}
4344

4445
/// Get the `LocalWaker` associated with the current task.
@@ -53,40 +54,45 @@ impl<'a> Context<'a> {
5354
unsafe { &*(self.local_waker as *const LocalWaker as *const Waker) }
5455
}
5556

56-
/// Get the default executor associated with this task.
57+
/// Get the spawner associated with this task.
5758
///
5859
/// This method is useful primarily if you want to explicitly handle
5960
/// spawn failures.
6061
#[inline]
61-
pub fn executor(&mut self) -> &mut dyn Executor {
62-
self.executor
62+
pub fn spawner(&mut self) -> &mut dyn Spawn {
63+
self.spawner
6364
}
6465

65-
/// Produce a context like the current one, but using the given waker instead.
66+
/// Produce a context like the current one, but using the given waker
67+
/// instead.
6668
///
6769
/// This advanced method is primarily used when building "internal
6870
/// schedulers" within a task, where you want to provide some customized
6971
/// wakeup logic.
7072
#[inline]
71-
pub fn with_waker<'b>(&'b mut self, local_waker: &'b LocalWaker) -> Context<'b> {
73+
pub fn with_waker<'b>(
74+
&'b mut self,
75+
local_waker: &'b LocalWaker,
76+
) -> Context<'b> {
7277
Context {
7378
local_waker,
74-
executor: self.executor,
79+
spawner: self.spawner,
7580
}
7681
}
7782

78-
/// Produce a context like the current one, but using the given executor
83+
/// Produce a context like the current one, but using the given spawner
7984
/// instead.
8085
///
8186
/// This advanced method is primarily used when building "internal
8287
/// schedulers" within a task.
8388
#[inline]
84-
pub fn with_executor<'b, E>(&'b mut self, executor: &'b mut E) -> Context<'b>
85-
where E: Executor
86-
{
89+
pub fn with_spawner<'b, Sp: Spawn>(
90+
&'b mut self,
91+
spawner: &'b mut Sp,
92+
) -> Context<'b> {
8793
Context {
8894
local_waker: self.local_waker,
89-
executor,
95+
spawner,
9096
}
9197
}
9298
}

src/libcore/task/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
mod context;
1818
pub use self::context::Context;
1919

20-
mod executor;
21-
pub use self::executor::{
22-
Executor, SpawnErrorKind, SpawnObjError, SpawnLocalObjError
23-
};
20+
mod spawn;
21+
pub use self::spawn::{Spawn, SpawnErrorKind, SpawnObjError, SpawnLocalObjError};
2422

2523
mod poll;
2624
pub use self::poll::Poll;

src/libcore/task/executor.rs renamed to src/libcore/task/spawn.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@
1515
use fmt;
1616
use future::{FutureObj, LocalFutureObj};
1717

18-
/// A task executor.
18+
/// Spawns tasks that poll futures to completion onto its associated task
19+
/// executor.
1920
///
20-
/// Futures are polled until completion by tasks, a kind of lightweight
21-
/// "thread". A *task executor* is responsible for the creation of these tasks
22-
/// and the coordination of their execution on real operating system threads. In
23-
/// particular, whenever a task signals that it can make further progress via a
24-
/// wake-up notification, it is the responsibility of the task executor to put
25-
/// the task into a queue to continue executing it, i.e. polling the future in
26-
/// it, later.
27-
pub trait Executor {
21+
/// The term "task" refers to a kind of lightweight "thread". Task executors
22+
/// are responsible for scheduling the execution of tasks on operating system
23+
/// threads.
24+
pub trait Spawn {
2825
/// Spawns a new task with the given future. The future will be polled until
2926
/// completion.
3027
///

src/test/run-pass/async-await.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::sync::{
2222
use std::future::FutureObj;
2323
use std::task::{
2424
Context, Poll, Wake,
25-
Executor, SpawnObjError,
25+
Spawn, SpawnObjError,
2626
local_waker_from_nonlocal,
2727
};
2828

@@ -36,8 +36,8 @@ impl Wake for Counter {
3636
}
3737
}
3838

39-
struct NoopExecutor;
40-
impl Executor for NoopExecutor {
39+
struct NoopSpawner;
40+
impl Spawn for NoopSpawner {
4141
fn spawn_obj(&mut self, _: FutureObj<'static, ()>) -> Result<(), SpawnObjError> {
4242
Ok(())
4343
}
@@ -127,8 +127,8 @@ where
127127
let mut fut = PinBox::new(f(9));
128128
let counter = Arc::new(Counter { wakes: AtomicUsize::new(0) });
129129
let waker = local_waker_from_nonlocal(counter.clone());
130-
let executor = &mut NoopExecutor;
131-
let cx = &mut Context::new(&waker, executor);
130+
let spawner = &mut NoopSpawner;
131+
let cx = &mut Context::new(&waker, spawner);
132132

133133
assert_eq!(0, counter.wakes.load(atomic::Ordering::SeqCst));
134134
assert_eq!(Poll::Pending, fut.as_pin_mut().poll(cx));

src/test/run-pass/futures-api.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::future::FutureObj;
2323
use std::task::{
2424
Context, Poll,
2525
Wake, Waker, LocalWaker,
26-
Executor, SpawnObjError,
26+
Spawn, SpawnObjError,
2727
local_waker, local_waker_from_nonlocal,
2828
};
2929

@@ -42,9 +42,9 @@ impl Wake for Counter {
4242
}
4343
}
4444

45-
struct NoopExecutor;
45+
struct NoopSpawner;
4646

47-
impl Executor for NoopExecutor {
47+
impl Spawn for NoopSpawner {
4848
fn spawn_obj(&mut self, _: FutureObj<'static, ()>) -> Result<(), SpawnObjError> {
4949
Ok(())
5050
}
@@ -59,7 +59,7 @@ impl Future for MyFuture {
5959
cx.waker().wake();
6060
cx.waker().wake();
6161
cx.local_waker().wake();
62-
cx.executor().spawn_obj(PinBox::new(MyFuture).into()).unwrap();
62+
cx.spawner().spawn_obj(PinBox::new(MyFuture).into()).unwrap();
6363
Poll::Ready(())
6464
}
6565
}
@@ -70,8 +70,8 @@ fn test_local_waker() {
7070
nonlocal_wakes: AtomicUsize::new(0),
7171
});
7272
let waker = unsafe { local_waker(counter.clone()) };
73-
let executor = &mut NoopExecutor;
74-
let cx = &mut Context::new(&waker, executor);
73+
let spawner = &mut NoopSpawner;
74+
let cx = &mut Context::new(&waker, spawner);
7575
assert_eq!(Poll::Ready(()), PinMut::new(&mut MyFuture).poll(cx));
7676
assert_eq!(1, counter.local_wakes.load(atomic::Ordering::SeqCst));
7777
assert_eq!(2, counter.nonlocal_wakes.load(atomic::Ordering::SeqCst));
@@ -83,8 +83,8 @@ fn test_local_as_nonlocal_waker() {
8383
nonlocal_wakes: AtomicUsize::new(0),
8484
});
8585
let waker: LocalWaker = local_waker_from_nonlocal(counter.clone());
86-
let executor = &mut NoopExecutor;
87-
let cx = &mut Context::new(&waker, executor);
86+
let spawner = &mut NoopSpawner;
87+
let cx = &mut Context::new(&waker, spawner);
8888
assert_eq!(Poll::Ready(()), PinMut::new(&mut MyFuture).poll(cx));
8989
assert_eq!(0, counter.local_wakes.load(atomic::Ordering::SeqCst));
9090
assert_eq!(3, counter.nonlocal_wakes.load(atomic::Ordering::SeqCst));

0 commit comments

Comments
 (0)