Skip to content

Refactor the task module #421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
6 commits merged into from Nov 1, 2019
Merged

Refactor the task module #421

6 commits merged into from Nov 1, 2019

Conversation

ghost
Copy link

@ghost ghost commented Oct 30, 2019

Okay, this is a big PR. Sorry 😅

Nothing is fundamentally different from the previous implementation - I mostly reorganized the modules so that it becomes clearer what is where and what is what. While this doesn't really change our task executor, some small tweaks and the nature of cleaning things up made it a bit more efficient.

My primary motive here was to clearly separate what is the public API (what is visible in the generated docs for async_std::task) and what is the task executor, i.e. the "machine" driving the module.

The executor now lives in the crate::task::driver module, and everything else is an implementation of the high-level API that really has nothing to do with the executor. For example, task_local! and block_on() have meaty implementations, but are not a part of the executor itself and therefore that code does not live in the driver module.

There is also additional documentation and comments now, which should help contributors navigate the code more easily. In particular, I want people not interested in low-level details to not be lost in the codebase and people who are interested to be able to effortlessly play with the executor implementation without having to mess with anything that is unrelated to task execution.

This is the task module: https://github.com/stjepang/async-std/tree/refactor-task/src/task

This is the task::driver module: https://github.com/stjepang/async-std/tree/refactor-task/src/task/driver

The scheduler is less than 150 lines of code and this is its main part: https://github.com/stjepang/async-std/blob/refactor-task/src/task/driver/pool.rs

@yoshuawuyts yoshuawuyts changed the title Refactor the task module Replace select!/try_select! with Future::{race,try_race} Nov 1, 2019
@yoshuawuyts yoshuawuyts changed the title Replace select!/try_select! with Future::{race,try_race} Refactor the task module Nov 1, 2019
// chosen point.
pool.stealers
.iter()
.chain(pool.stealers.iter())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, so how does this work? The chaining of pool.stealers with itself kind of confuses me.

Copy link
Author

@ghost ghost Nov 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's a bit weird. :) I changed the code to:

// Try stealing a batch of tasks from each local queue starting from the
// chosen point.
let (l, r) = pool.stealers.split_at(start);
let rotated = r.iter().chain(l.iter());
rotated.map(|s| s.steal_batch_and_pop(&local)).collect()

Hopefully now it's a bit clearer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see now. Yeah that's better. Thank you!

Copy link
Contributor

@yoshuawuyts yoshuawuyts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@ghost ghost merged commit 3dd59d7 into async-rs:master Nov 1, 2019
@ghost ghost deleted the refactor-task branch November 1, 2019 01:45
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant