Skip to content

Commit a26e594

Browse files
authored
Sleep trait (#665)
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.
1 parent 3826530 commit a26e594

File tree

9 files changed

+463
-316
lines changed

9 files changed

+463
-316
lines changed

benches/current_thread_executor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn execute_oneshot(b: &mut Bencher) {
1919
b.iter(move || {
2020
let cnt = Rc::new(Cell::new(0));
2121

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

44-
CurrentThread::block_with_init(|_| {
44+
CurrentThread::run(|_| {
4545
for _ in 0..TASKS {
4646
let cnt = cnt.clone();
4747
let mut rem = YIELDS;
@@ -83,7 +83,7 @@ fn execute_daisy(b: &mut Bencher) {
8383
b.iter(move || {
8484
cnt.set(0);
8585

86-
CurrentThread::block_with_init(|_| {
86+
CurrentThread::run(|_| {
8787
daisy(DEPTH, cnt.clone());
8888
});
8989

0 commit comments

Comments
 (0)