mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-22 00:00:11 +02:00
time: avoid stack overflow in runtime constructor (#8093)
This commit is contained in:
@@ -5,7 +5,7 @@ mod level;
|
||||
pub(crate) use self::level::Expiration;
|
||||
use self::level::Level;
|
||||
|
||||
use std::{array, ptr::NonNull};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
use super::entry::STATE_DEREGISTERED;
|
||||
use super::EntryList;
|
||||
@@ -50,9 +50,13 @@ pub(super) const MAX_DURATION: u64 = (1 << (6 * NUM_LEVELS)) - 1;
|
||||
impl Wheel {
|
||||
/// Creates a new timing wheel.
|
||||
pub(crate) fn new() -> Wheel {
|
||||
let mut levels = Vec::with_capacity(NUM_LEVELS);
|
||||
for i in 0..NUM_LEVELS {
|
||||
levels.push(Level::new(i));
|
||||
}
|
||||
Wheel {
|
||||
elapsed: 0,
|
||||
levels: Box::new(array::from_fn(Level::new)),
|
||||
levels: levels.into_boxed_slice().try_into().unwrap(),
|
||||
pending: EntryList::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ use self::level::Level;
|
||||
use super::cancellation_queue::Sender;
|
||||
use super::{EntryHandle, EntryList, WakeQueue};
|
||||
|
||||
use std::array;
|
||||
|
||||
/// Hashed timing wheel implementation.
|
||||
///
|
||||
/// See [`Driver`] documentation for some implementation notes.
|
||||
@@ -41,9 +39,13 @@ pub(super) const MAX_DURATION: u64 = (1 << (6 * NUM_LEVELS)) - 1;
|
||||
impl Wheel {
|
||||
/// Creates a new timing wheel.
|
||||
pub(crate) fn new() -> Wheel {
|
||||
let mut levels = Vec::with_capacity(NUM_LEVELS);
|
||||
for i in 0..NUM_LEVELS {
|
||||
levels.push(Level::new(i));
|
||||
}
|
||||
Wheel {
|
||||
elapsed: 0,
|
||||
levels: Box::new(array::from_fn(Level::new)),
|
||||
levels: levels.into_boxed_slice().try_into().unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user