Use a scalable RW lock in tokio-reactor (#517)

This commit is contained in:
Stjepan Glavina
2018-08-09 11:23:45 -07:00
committed by Carl Lerche
parent 89d6bfc5cb
commit fd36054ae4
5 changed files with 283 additions and 8 deletions
+45
View File
@@ -0,0 +1,45 @@
extern crate futures;
extern crate mio;
extern crate tokio;
extern crate tokio_reactor;
use futures::Async;
use mio::Ready;
use tokio::prelude::*;
use tokio_reactor::Registration;
const NUM_FUTURES: usize = 1000;
const NUM_STEPS: usize = 1000;
fn main() {
tokio::run(future::lazy(|| {
for _ in 0..NUM_FUTURES {
let (r, s) = mio::Registration::new2();
let registration = Registration::new();
registration.register(&r).unwrap();
let mut r = Some(r);
let mut step = 0;
tokio::spawn(future::poll_fn(move || {
loop {
let is_ready = registration.poll_read_ready().unwrap().is_ready();
if is_ready {
step += 1;
if step == NUM_STEPS {
r.take().unwrap();
return Ok(Async::Ready(()));
}
} else {
s.set_readiness(Ready::readable()).unwrap();
return Ok(Async::NotReady);
}
}
}));
}
Ok(())
}));
}