Skip to content

Commit

Permalink
Sleep trait (#665)
Browse files Browse the repository at this point in the history
This enables customizing executor sleeping strategies.

Currently, it is not possible to run a Tokio reactor and a 
`CurrentThread` executor on the same thread. The executor is
hard coded to use condvars for sleeping and the Tokio reactor
requires calling `epoll_wait` (or equivalent) for blocking the
current thread.

The `Sleep` trait is added to abstract over this sleeping strategy.

Beyond just supporting the Tokio reactor, adding a `Sleep` trait is
useful for integrating any logic that requires hooking into the sleep
strategy (e.g. timers).

`executor::CurrentThread` is then modified to accept a `Sleep` value
that allows specifying a custom sleep strategy.
  • Loading branch information
carllerche authored Dec 6, 2017
1 parent 3826530 commit a26e594
Show file tree
Hide file tree
Showing 9 changed files with 463 additions and 316 deletions.
6 changes: 3 additions & 3 deletions benches/current_thread_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn execute_oneshot(b: &mut Bencher) {
b.iter(move || {
let cnt = Rc::new(Cell::new(0));

CurrentThread::block_with_init(|_| {
CurrentThread::run(|_| {
for _ in 0..ITER {
let cnt = cnt.clone();
CurrentThread::execute(lazy(move || {
Expand All @@ -41,7 +41,7 @@ fn execute_yield_many(b: &mut Bencher) {
b.iter(move || {
let cnt = Rc::new(Cell::new(0));

CurrentThread::block_with_init(|_| {
CurrentThread::run(|_| {
for _ in 0..TASKS {
let cnt = cnt.clone();
let mut rem = YIELDS;
Expand Down Expand Up @@ -83,7 +83,7 @@ fn execute_daisy(b: &mut Bencher) {
b.iter(move || {
cnt.set(0);

CurrentThread::block_with_init(|_| {
CurrentThread::run(|_| {
daisy(DEPTH, cnt.clone());
});

Expand Down
Loading

0 comments on commit a26e594

Please sign in to comment.