Skip to content

Commit

Permalink
Rename Task to TaskContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
MajorBreakfast committed Jun 20, 2018
1 parent f00f4e5 commit 79eec05
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
14 changes: 7 additions & 7 deletions futures-executor/src/local_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use thread::ThreadNotify;
use enter;
use ThreadPool;

struct Task {
fut: TaskObj,
struct TaskContainer {
task: TaskObj,
}

/// A single-threaded task pool.
Expand All @@ -31,7 +31,7 @@ struct Task {
/// single-threaded, it supports a special form of task spawning for non-`Send`
/// futures, via [`spawn_local`](LocalExecutor::spawn_local).
pub struct LocalPool {
pool: FuturesUnordered<Task>,
pool: FuturesUnordered<TaskContainer>,
incoming: Rc<Incoming>,
}

Expand All @@ -42,7 +42,7 @@ pub struct LocalExecutor {
incoming: Weak<Incoming>,
}

type Incoming = RefCell<Vec<Task>>;
type Incoming = RefCell<Vec<TaskContainer>>;

// Set up and run a basic single-threaded executor loop, invocing `f` on each
// turn.
Expand Down Expand Up @@ -236,7 +236,7 @@ impl<S: Stream + Unpin> Iterator for BlockingStream<S> {
impl Executor for LocalExecutor {
fn spawn_obj(&mut self, task: TaskObj) -> Result<(), SpawnObjError> {
if let Some(incoming) = self.incoming.upgrade() {
incoming.borrow_mut().push(Task { fut: task });
incoming.borrow_mut().push(TaskContainer { task });
Ok(())
} else {
Err(SpawnObjError{ task, kind: SpawnErrorKind::shutdown() })
Expand Down Expand Up @@ -266,10 +266,10 @@ impl LocalExecutor {
*/
}

impl Future for Task {
impl Future for TaskContainer {
type Output = ();

fn poll(mut self: PinMut<Self>, cx: &mut Context) -> Poll<()> {
self.fut.poll_task(cx)
self.task.poll_task(cx)
}
}
32 changes: 16 additions & 16 deletions futures-executor/src/thread_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl fmt::Debug for ThreadPoolBuilder {
}

enum Message {
Run(Task),
Run(TaskContainer),
Close,
}

Expand Down Expand Up @@ -102,16 +102,16 @@ impl ThreadPool {
}

impl Executor for ThreadPool {
fn spawn_obj(&mut self, f: TaskObj) -> Result<(), SpawnObjError> {
let task = Task {
spawn: f,
fn spawn_obj(&mut self, task: TaskObj) -> Result<(), SpawnObjError> {
let task_container = TaskContainer {
task,
wake_handle: Arc::new(WakeHandle {
exec: self.clone(),
mutex: UnparkMutex::new(),
}),
exec: self.clone(),
};
self.state.send(Message::Run(task));
self.state.send(Message::Run(task_container));
Ok(())
}
}
Expand Down Expand Up @@ -264,22 +264,22 @@ impl ThreadPoolBuilder {

/// Units of work submitted to an `Executor`, currently only created
/// internally.
struct Task {
spawn: TaskObj,
struct TaskContainer {
task: TaskObj,
exec: ThreadPool,
wake_handle: Arc<WakeHandle>,
}

struct WakeHandle {
mutex: UnparkMutex<Task>,
mutex: UnparkMutex<TaskContainer>,
exec: ThreadPool,
}

impl Task {
impl TaskContainer {
/// Actually run the task (invoking `poll` on its future) on the current
/// thread.
pub fn run(self) {
let Task { mut spawn, wake_handle, mut exec } = self;
let TaskContainer { mut task, wake_handle, mut exec } = self;
let waker = Waker::from(wake_handle.clone());

// SAFETY: the ownership of this `Task` object is evidence that
Expand All @@ -290,21 +290,21 @@ impl Task {
loop {
let res = {
let mut cx = task::Context::new(&waker, &mut exec);
spawn.poll_task(&mut cx)
task.poll_task(&mut cx)
};
match res {
Poll::Pending => {}
Poll::Ready(()) => return wake_handle.mutex.complete(),
}
let task = Task {
spawn,
let task_container = TaskContainer {
task,
wake_handle: wake_handle.clone(),
exec: exec
};
match wake_handle.mutex.wait(task) {
match wake_handle.mutex.wait(task_container) {
Ok(()) => return, // we've waited
Err(r) => { // someone's notified us
spawn = r.spawn;
task = r.task;
exec = r.exec;
}
}
Expand All @@ -313,7 +313,7 @@ impl Task {
}
}

impl fmt::Debug for Task {
impl fmt::Debug for TaskContainer {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Task")
.field("contents", &"...")
Expand Down

0 comments on commit 79eec05

Please sign in to comment.