mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-23 00:00:10 +02:00
Track Slab changes
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@ futures = { git = "https://github.com/alexcrichton/futures-rs" }
|
||||
log = "0.3"
|
||||
mio = { git = "https://github.com/carllerche/mio" }
|
||||
scoped-tls = "0.1.0"
|
||||
slab = "0.2.0"
|
||||
slab = { git = "https://github.com/carllerche/slab" }
|
||||
|
||||
[dev-dependencies]
|
||||
env_logger = "0.3"
|
||||
|
||||
@@ -147,9 +147,9 @@ impl Loop {
|
||||
events: mio::Events::with_capacity(1024),
|
||||
tx: Arc::new(tx),
|
||||
rx: rx,
|
||||
io_dispatch: RefCell::new(Slab::new_starting_at(0, SLAB_CAPACITY)),
|
||||
task_dispatch: RefCell::new(Slab::new_starting_at(0, SLAB_CAPACITY)),
|
||||
timeouts: RefCell::new(Slab::new_starting_at(0, SLAB_CAPACITY)),
|
||||
io_dispatch: RefCell::new(Slab::with_capacity(SLAB_CAPACITY)),
|
||||
task_dispatch: RefCell::new(Slab::with_capacity(SLAB_CAPACITY)),
|
||||
timeouts: RefCell::new(Slab::with_capacity(SLAB_CAPACITY)),
|
||||
timer_wheel: RefCell::new(TimerWheel::new()),
|
||||
_future_registration: future_pair.0,
|
||||
future_readiness: Arc::new(MySetReadiness(future_pair.1)),
|
||||
@@ -388,8 +388,8 @@ impl Loop {
|
||||
};
|
||||
let mut dispatch = self.io_dispatch.borrow_mut();
|
||||
if dispatch.vacant_entry().is_none() {
|
||||
let amt = dispatch.count();
|
||||
dispatch.grow(amt);
|
||||
let amt = dispatch.len();
|
||||
dispatch.reserve_exact(amt);
|
||||
}
|
||||
let entry = dispatch.vacant_entry().unwrap();
|
||||
try!(self.io.register(source,
|
||||
@@ -430,8 +430,8 @@ impl Loop {
|
||||
fn add_timeout(&self, at: Instant) -> io::Result<(usize, Instant)> {
|
||||
let mut timeouts = self.timeouts.borrow_mut();
|
||||
if timeouts.vacant_entry().is_none() {
|
||||
let len = timeouts.count();
|
||||
timeouts.grow(len);
|
||||
let len = timeouts.len();
|
||||
timeouts.reserve_exact(len);
|
||||
}
|
||||
let entry = timeouts.vacant_entry().unwrap();
|
||||
let timeout = self.timer_wheel.borrow_mut().insert(at, entry.index());
|
||||
@@ -461,8 +461,8 @@ impl Loop {
|
||||
let unpark = {
|
||||
let mut dispatch = self.task_dispatch.borrow_mut();
|
||||
if dispatch.vacant_entry().is_none() {
|
||||
let len = dispatch.count();
|
||||
dispatch.grow(len);
|
||||
let len = dispatch.len();
|
||||
dispatch.reserve_exact(len);
|
||||
}
|
||||
let entry = dispatch.vacant_entry().unwrap();
|
||||
let token = TOKEN_START + 2 * entry.index() + 1;
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
//! A timer wheel implementation
|
||||
|
||||
use std::mem;
|
||||
use std::{mem, usize};
|
||||
use std::time::{Instant, Duration};
|
||||
|
||||
use slab::Slab;
|
||||
@@ -74,7 +74,7 @@ pub struct Timeout {
|
||||
slab_idx: usize,
|
||||
}
|
||||
|
||||
const EMPTY: usize = 0;
|
||||
const EMPTY: usize = usize::MAX;
|
||||
const LEN: usize = 256;
|
||||
const MASK: usize = LEN - 1;
|
||||
const TICK_MS: u64 = 100;
|
||||
@@ -88,7 +88,7 @@ impl<T> TimerWheel<T> {
|
||||
pub fn new() -> TimerWheel<T> {
|
||||
TimerWheel {
|
||||
wheel: vec![Slot { head: EMPTY, next_timeout: None }; LEN],
|
||||
slab: Slab::new_starting_at(1, 256),
|
||||
slab: Slab::with_capacity(256),
|
||||
start: Instant::now(),
|
||||
cur_wheel_tick: 0,
|
||||
cur_slab_idx: EMPTY,
|
||||
@@ -129,8 +129,8 @@ impl<T> TimerWheel<T> {
|
||||
|
||||
// Next, make sure there's enough space in the slab for the timeout.
|
||||
if self.slab.vacant_entry().is_none() {
|
||||
let amt = self.slab.count();
|
||||
self.slab.grow(amt);
|
||||
let amt = self.slab.len();
|
||||
self.slab.reserve_exact(amt);
|
||||
}
|
||||
|
||||
// Insert ourselves at the head of the linked list in the wheel.
|
||||
|
||||
Reference in New Issue
Block a user