id stringlengths 22 133 | text stringlengths 40 40.2k | arch stringclasses 1
value | syntax stringclasses 1
value | kind stringclasses 4
values | repo stringclasses 27
values | path stringlengths 5 116 | license stringclasses 6
values | commit stringlengths 40 40 | source_host stringclasses 1
value | category stringclasses 16
values | source_url stringlengths 85 196 | line_start int64 1 4.28k | line_end int64 4 4.31k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tokio-rs/tokio:tokio/src/time/delay_queue.rs:18 | ///
/// # #[tokio::main]
/// # async fn main() {
/// let mut delay_queue = DelayQueue::new();
/// assert!(delay_queue.is_empty());
///
/// delay_queue.insert("hello", Duration::from_secs(5));
/// assert!(!delay_queue.is_empty());
/// # }
/// ```
pub fn is_empty(&s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/time/delay_queue.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:19 | if let Some(idx) = self.wheel.poll(&mut self.poll, &mut self.slab) {
return Poll::Ready(Some(Ok(idx)));
}
if let Some(deadline) = self.next_deadline() {
self.delay = Some(delay_until(deadline));
} else {
return Poll::Ready(None);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/time/delay_queue.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:22 | fn when(item: &Self::Borrowed, store: &Self::Store) -> u64 {
store[*item].when
}
}
impl<T> Default for Stack<T> {
fn default() -> Stack<T> {
Stack {
head: None,
_p: PhantomData,
}
}
}
impl Key {
pub(crate) fn new(index: usize) -> Key {
Key { inde... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/time/delay_queue.rs | 841 | 876 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:5 | key: Key,
}
/// Token to a value stored in a `DelayQueue`.
///
/// Instances of `Key` are returned by [`DelayQueue::insert`]. See [`DelayQueue`]
/// documentation for more details.
///
/// [`DelayQueue`]: struct.DelayQueue.html
/// [`DelayQueue::insert`]: struct.DelayQueue.html#method.insert
#[derive(Debug, Clone)]
pu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 0133bc188327c19ef0834904c46218a0dad58845 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0133bc188327c19ef0834904c46218a0dad58845/tokio/src/time/delay_queue.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:6 | /// Maximum number of entries the queue can handle
const MAX_ENTRIES: usize = (1 << 30) - 1;
impl<T> DelayQueue<T> {
/// Create a new, empty, `DelayQueue`
///
/// The queue will not allocate storage until items are inserted into it.
///
/// # Examples
///
/// ```rust
/// # use tokio::ti... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 0133bc188327c19ef0834904c46218a0dad58845 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0133bc188327c19ef0834904c46218a0dad58845/tokio/src/time/delay_queue.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:8 | /// Basic usage
///
/// ```rust
/// use tokio::time::{DelayQueue, Duration, Instant};
///
/// # #[tokio::main]
/// # async fn main() {
/// let mut delay_queue = DelayQueue::new();
/// let key = delay_queue.insert_at(
/// "foo", Instant::now() + Duration::from_secs(5))... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 0133bc188327c19ef0834904c46218a0dad58845 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0133bc188327c19ef0834904c46218a0dad58845/tokio/src/time/delay_queue.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:9 | let should_set_delay = if let Some(ref delay) = self.delay {
let current_exp = self.normalize_deadline(delay.deadline());
current_exp > when
} else {
true
};
if should_set_delay {
self.delay = Some(delay_until(self.start + Duration::from_millis(wh... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 0133bc188327c19ef0834904c46218a0dad58845 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0133bc188327c19ef0834904c46218a0dad58845/tokio/src/time/delay_queue.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:11 | /// [`poll`]: #method.poll
/// [`remove`]: #method.remove
/// [`reset`]: #method.reset
/// [`Key`]: struct.Key.html
/// [type]: #
pub fn insert(&mut self, value: T, timeout: Duration) -> Key {
self.insert_at(value, Instant::now() + timeout)
}
fn insert_idx(&mut self, when: u64, key:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 0133bc188327c19ef0834904c46218a0dad58845 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0133bc188327c19ef0834904c46218a0dad58845/tokio/src/time/delay_queue.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:17 | /// delay_queue.insert("hello", Duration::from_secs(10));
/// delay_queue.reserve(10);
///
/// assert!(delay_queue.capacity() >= 11);
/// # }
/// ```
pub fn reserve(&mut self, additional: usize) {
self.slab.reserve(additional);
}
/// Returns `true` if there are no it... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 17e424112d53385142aa430641910c384c4cbe5a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17e424112d53385142aa430641910c384c4cbe5a/tokio/src/time/delay_queue.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:18 | let expired = self.expired.pop(&mut self.slab);
if expired.is_some() {
return Poll::Ready(expired.map(Ok));
}
loop {
if let Some(ref mut delay) = self.delay {
if !delay.is_elapsed() {
ready!(Pin::new(&mut *delay).poll(cx));
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 17e424112d53385142aa430641910c384c4cbe5a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17e424112d53385142aa430641910c384c4cbe5a/tokio/src/time/delay_queue.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:19 | }
}
// We never put `T` in a `Pin`...
impl<T> Unpin for DelayQueue<T> {}
impl<T> Default for DelayQueue<T> {
fn default() -> DelayQueue<T> {
DelayQueue::new()
}
}
#[cfg(feature = "stream")]
impl<T> futures_core::Stream for DelayQueue<T> {
// DelayQueue seems much more specific, where a user may c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 17e424112d53385142aa430641910c384c4cbe5a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17e424112d53385142aa430641910c384c4cbe5a/tokio/src/time/delay_queue.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:21 | next = store[idx].next;
}
contains
});
if let Some(next) = store[*item].next {
store[next].prev = store[*item].prev;
}
if let Some(prev) = store[*item].prev {
store[prev].next = store[*item].next;
} else {
self.head =... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 17e424112d53385142aa430641910c384c4cbe5a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17e424112d53385142aa430641910c384c4cbe5a/tokio/src/time/delay_queue.rs | 801 | 856 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:22 | impl<T> Expired<T> {
/// Returns a reference to the inner value.
pub fn get_ref(&self) -> &T {
&self.data
}
/// Returns a mutable reference to the inner value.
pub fn get_mut(&mut self) -> &mut T {
&mut self.data
}
/// Consumes `self` and returns the inner value.
pub fn... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 17e424112d53385142aa430641910c384c4cbe5a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17e424112d53385142aa430641910c384c4cbe5a/tokio/src/time/delay_queue.rs | 841 | 856 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:18 | let expired = self.expired.pop(&mut self.slab);
if expired.is_some() {
return Poll::Ready(expired.map(Ok));
}
loop {
if let Some(ref mut delay) = self.delay {
if !delay.is_elapsed() {
ready!(Pin::new(&mut *delay).poll(cx));
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 942feab040e28d1e1547012a0fb81212299e6596 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/942feab040e28d1e1547012a0fb81212299e6596/tokio/src/time/delay_queue.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:19 | }
}
// We never put `T` in a `Pin`...
impl<T> Unpin for DelayQueue<T> {}
impl<T> Default for DelayQueue<T> {
fn default() -> DelayQueue<T> {
DelayQueue::new()
}
}
impl<T> wheel::Stack for Stack<T> {
type Owned = usize;
type Borrowed = usize;
type Store = Slab<Data<T>>;
fn is_empty(&s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 942feab040e28d1e1547012a0fb81212299e6596 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/942feab040e28d1e1547012a0fb81212299e6596/tokio/src/time/delay_queue.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:20 | if let Some(idx) = self.head {
store[idx].prev = None;
}
store[idx].next = None;
debug_assert!(store[idx].prev.is_none());
Some(idx)
} else {
None
}
}
fn remove(&mut self, item: &Self::Borrowed, store: &mut Self::Stor... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 942feab040e28d1e1547012a0fb81212299e6596 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/942feab040e28d1e1547012a0fb81212299e6596/tokio/src/time/delay_queue.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:21 | store[prev].next = store[*item].next;
} else {
self.head = store[*item].next;
}
store[*item].next = None;
store[*item].prev = None;
}
fn when(item: &Self::Borrowed, store: &Self::Store) -> u64 {
store[*item].when
}
}
impl<T> Default for Stack<T> {
f... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 942feab040e28d1e1547012a0fb81212299e6596 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/942feab040e28d1e1547012a0fb81212299e6596/tokio/src/time/delay_queue.rs | 801 | 845 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:13 | /// # Panics
///
/// This function panics if `when` is too far in the future or if `key` is
/// not contained by the queue.
///
/// # Examples
///
/// Basic usage
///
/// ```rust
/// use tokio::time::{DelayQueue, Duration, Instant};
///
/// # #[tokio::main]
/// # asyn... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 3e643c7b81736a4c2b11387a6f71aba99450270b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3e643c7b81736a4c2b11387a6f71aba99450270b/tokio/src/time/delay_queue.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:6 | /// Maximum number of entries the queue can handle
const MAX_ENTRIES: usize = (1 << 30) - 1;
impl<T> DelayQueue<T> {
/// Create a new, empty, `DelayQueue`
///
/// The queue will not allocate storage until items are inserted into it.
///
/// # Examples
///
/// ```rust
/// # use tokio::ti... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/delay_queue.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:8 | ///
/// let mut delay_queue = DelayQueue::new();
/// let key = delay_queue.insert_at(
/// "foo", Instant::now() + Duration::from_secs(5));
///
/// // Remove the entry
/// let item = delay_queue.remove(&key);
/// assert_eq!(*item.get_ref(), "foo");
/// ```
///
/// [`poll`]: #m... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/delay_queue.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:9 | if should_set_delay {
self.delay = Some(delay_until(self.start + Duration::from_millis(when)));
}
Key::new(key)
}
/// Attempt to pull out the next value of the delay queue, registering the
/// current task for wakeup if the value is not yet available, and returning
/// None... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/delay_queue.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:10 | /// The return value represents the insertion and is used at an argument to
/// [`remove`] and [`reset`]. Note that [`Key`] is token and is reused once
/// `value` is removed from the queue either by calling [`poll`] after
/// `when` is reached or by calling [`remove`]. At this point, the caller
/// mus... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/delay_queue.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:11 | use self::wheel::{InsertError, Stack};
// Register the deadline with the timer wheel
match self.wheel.insert(when, key, &mut self.slab) {
Ok(_) => {}
Err((_, InsertError::Elapsed)) => {
self.slab[key].expired = true;
// The delay is already expire... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/delay_queue.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:12 | use crate::time::wheel::Stack;
// Special case the `expired` queue
if self.slab[key.index].expired {
self.expired.remove(&key.index, &mut self.slab);
} else {
self.wheel.remove(&key.index, &mut self.slab);
}
let data = self.slab.remove(key.index);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/delay_queue.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:13 | /// let key = delay_queue.insert("foo", Duration::from_secs(5));
///
/// // "foo" is scheduled to be returned in 5 seconds
///
/// delay_queue.reset_at(&key, Instant::now() + Duration::from_secs(10));
///
/// // "foo"is now scheduled to be returned in 10 seconds
/// ```
pub fn reset_at(&... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/delay_queue.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:16 | /// The queue may reserve more than `additional` extra space in order to
/// avoid frequent reallocations.
///
/// # Panics
///
/// Panics if the new capacity exceeds the maximum number of entries the
/// queue can contain.
///
/// # Examples
///
/// ```
/// use tokio::time::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/delay_queue.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:17 | /// assert!(!delay_queue.is_empty());
/// ```
pub fn is_empty(&self) -> bool {
self.slab.is_empty()
}
/// Polls the queue, returning the index of the next slot in the slab that
/// should be returned.
///
/// A slot should be returned when the associated deadline has been reached.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/delay_queue.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:18 | }
}
}
fn normalize_deadline(&self, when: Instant) -> u64 {
let when = if when < self.start {
0
} else {
crate::time::ms(when - self.start, crate::time::Round::Up)
};
cmp::max(when, self.wheel.elapsed())
}
}
// We never put `T` in a `Pin`...
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/delay_queue.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:4 | /// [`Stream::poll`]: #method.poll
/// [`Timer`]: ../struct.Timer.html
/// [`slab`]: https://docs.rs/slab
/// [`capacity`]: #method.capacity
/// [`reserve`]: #method.reserve
#[derive(Debug)]
pub struct DelayQueue<T> {
/// Stores data associated with entries
slab: Slab<Data<T>>,
/// Lookup structure trackin... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/time/delay_queue.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:5 | /// The key associated with the entry
key: Key,
}
/// Token to a value stored in a `DelayQueue`.
///
/// Instances of `Key` are returned by [`DelayQueue::insert`]. See [`DelayQueue`]
/// documentation for more details.
///
/// [`DelayQueue`]: struct.DelayQueue.html
/// [`DelayQueue::insert`]: struct.DelayQueue.htm... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/time/delay_queue.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:6 | }
/// Maximum number of entries the queue can handle
const MAX_ENTRIES: usize = (1 << 30) - 1;
impl<T> DelayQueue<T> {
/// Create a new, empty, `DelayQueue`
///
/// The queue will not allocate storage until items are inserted into it.
///
/// # Examples
///
/// ```rust
/// # use tokio:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/time/delay_queue.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:8 | /// use tokio::time::{DelayQueue, Duration, Instant};
///
/// let mut delay_queue = DelayQueue::new();
/// let key = delay_queue.insert_at(
/// "foo", Instant::now() + Duration::from_secs(5));
///
/// // Remove the entry
/// let item = delay_queue.remove(&key);
/// assert_eq!(*item.g... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/time/delay_queue.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:9 | if should_set_delay {
self.delay = Some(Delay::new(self.start + Duration::from_millis(when)));
}
Key::new(key)
}
/// Attempt to pull out the next value of the delay queue, registering the
/// current task for wakeup if the value is not yet available, and returning
/// None ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/time/delay_queue.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:10 | ///
/// The return value represents the insertion and is used at an argument to
/// [`remove`] and [`reset`]. Note that [`Key`] is token and is reused once
/// `value` is removed from the queue either by calling [`poll`] after
/// `when` is reached or by calling [`remove`]. At this point, the caller
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/time/delay_queue.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:11 | fn insert_idx(&mut self, when: u64, key: usize) {
use self::wheel::{InsertError, Stack};
// Register the deadline with the timer wheel
match self.wheel.insert(when, key, &mut self.slab) {
Ok(_) => {}
Err((_, InsertError::Elapsed)) => {
self.slab[key].expi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/time/delay_queue.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:12 | pub fn remove(&mut self, key: &Key) -> Expired<T> {
use crate::time::wheel::Stack;
// Special case the `expired` queue
if self.slab[key.index].expired {
self.expired.remove(&key.index, &mut self.slab);
} else {
self.wheel.remove(&key.index, &mut self.slab);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/time/delay_queue.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:13 | /// let mut delay_queue = DelayQueue::new();
/// let key = delay_queue.insert("foo", Duration::from_secs(5));
///
/// // "foo" is scheduled to be returned in 5 seconds
///
/// delay_queue.reset_at(&key, Instant::now() + Duration::from_secs(10));
///
/// // "foo"is now scheduled to be returne... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/time/delay_queue.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:17 | /// delay_queue.insert("hello", Duration::from_secs(5));
/// assert!(!delay_queue.is_empty());
/// ```
pub fn is_empty(&self) -> bool {
self.slab.is_empty()
}
/// Polls the queue, returning the index of the next slot in the slab that
/// should be returned.
///
/// A slot should... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/time/delay_queue.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:18 | return Poll::Ready(None);
}
}
}
fn normalize_deadline(&self, when: Instant) -> u64 {
let when = if when < self.start {
0
} else {
crate::time::ms(when - self.start, crate::time::Round::Up)
};
cmp::max(when, self.wheel.elapsed())
}... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/time/delay_queue.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:19 | fn is_empty(&self) -> bool {
self.head.is_none()
}
fn push(&mut self, item: Self::Owned, store: &mut Self::Store) {
// Ensure the entry is not already in a stack.
debug_assert!(store[item].next.is_none());
debug_assert!(store[item].prev.is_none());
// Remove the old hea... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/time/delay_queue.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:20 | // Ensure that the entry is in fact contained by the stack
debug_assert!({
// This walks the full linked list even if an entry is found.
let mut next = self.head;
let mut contains = false;
while let Some(idx) = next {
if idx == *item {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/time/delay_queue.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/time/delay_queue.rs:21 | head: None,
_p: PhantomData,
}
}
}
impl Key {
pub(crate) fn new(index: usize) -> Key {
Key { index }
}
}
impl<T> Expired<T> {
/// Returns a reference to the inner value.
pub fn get_ref(&self) -> &T {
&self.data
}
/// Returns a mutable reference to the i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/delay_queue.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/time/delay_queue.rs | 801 | 828 |
tokio-rs/tokio:tokio/src/time/driver/atomic_stack.rs:1 | use crate::time::driver::Entry;
use crate::time::error::Error;
use std::ptr;
use std::sync::atomic::AtomicPtr;
use std::sync::atomic::Ordering::SeqCst;
use std::sync::Arc;
/// A stack of `Entry` nodes
#[derive(Debug)]
pub(crate) struct AtomicStack {
/// Stack head
head: AtomicPtr<Entry>,
}
/// Entries that w... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/atomic_stack.rs | MIT | 0893841f31542b2b04c5050a8a4a3c45cf867e55 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0893841f31542b2b04c5050a8a4a3c45cf867e55/tokio/src/time/driver/atomic_stack.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/driver/atomic_stack.rs:2 | // Already queued, nothing more to do
return Ok(false);
}
let ptr = Arc::into_raw(entry.clone()) as *mut _;
let mut curr = self.head.load(SeqCst);
loop {
if curr == SHUTDOWN {
// Don't leak the entry node
let _ = unsafe { Arc::fr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/atomic_stack.rs | MIT | 0893841f31542b2b04c5050a8a4a3c45cf867e55 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0893841f31542b2b04c5050a8a4a3c45cf867e55/tokio/src/time/driver/atomic_stack.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/driver/atomic_stack.rs:3 | /// Drains all remaining nodes in the stack and prevent any new nodes from
/// being pushed onto the stack.
pub(crate) fn shutdown(&self) {
// Shutdown the processing queue
let ptr = self.head.swap(SHUTDOWN, SeqCst);
// Let the drop fn of `AtomicStackEntries` handle draining the stack
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/atomic_stack.rs | MIT | 0893841f31542b2b04c5050a8a4a3c45cf867e55 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0893841f31542b2b04c5050a8a4a3c45cf867e55/tokio/src/time/driver/atomic_stack.rs | 81 | 124 |
tokio-rs/tokio:tokio/src/time/driver/atomic_stack.rs:1 | use crate::time::driver::Entry;
use crate::time::Error;
use std::ptr;
use std::sync::atomic::AtomicPtr;
use std::sync::atomic::Ordering::SeqCst;
use std::sync::Arc;
/// A stack of `Entry` nodes
#[derive(Debug)]
pub(crate) struct AtomicStack {
/// Stack head
head: AtomicPtr<Entry>,
}
/// Entries that were rem... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/atomic_stack.rs | MIT | 646fbae76535e397ef79dbcaacb945d4c829f666 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/646fbae76535e397ef79dbcaacb945d4c829f666/tokio/src/time/driver/atomic_stack.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/driver/atomic_stack.rs:2 | // Already queued, nothing more to do
return Ok(false);
}
let ptr = Arc::into_raw(entry.clone()) as *mut _;
let mut curr = self.head.load(SeqCst);
loop {
if curr == SHUTDOWN {
// Don't leak the entry node
let _ = unsafe { Arc::fr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/atomic_stack.rs | MIT | d1744bf260384838e00311230faf7787a97f477b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1744bf260384838e00311230faf7787a97f477b/tokio/src/time/driver/atomic_stack.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/driver/atomic_stack.rs:3 | /// Drains all remaining nodes in the stack and prevent any new nodes from
/// being pushed onto the stack.
pub(crate) fn shutdown(&self) {
// Shutdown the processing queue
let ptr = self.head.swap(SHUTDOWN, SeqCst);
// Let the drop fn of `AtomicStackEntries` handle draining the stack
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/atomic_stack.rs | MIT | d1744bf260384838e00311230faf7787a97f477b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1744bf260384838e00311230faf7787a97f477b/tokio/src/time/driver/atomic_stack.rs | 81 | 124 |
tokio-rs/tokio:tokio/src/time/driver/atomic_stack.rs:3 | /// Drains all remaining nodes in the stack and prevent any new nodes from
/// being pushed onto the stack.
pub(crate) fn shutdown(&self) {
// Shutdown the processing queue
let ptr = self.head.swap(SHUTDOWN, SeqCst);
// Let the drop fn of `AtomicStackEntries` handle draining the stack
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/atomic_stack.rs | MIT | 71c47fabf4a8a450c3b41d58de304a6a49fb4061 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/71c47fabf4a8a450c3b41d58de304a6a49fb4061/tokio/src/time/driver/atomic_stack.rs | 81 | 124 |
tokio-rs/tokio:tokio/src/time/driver/atomic_stack.rs:3 | /// Drains all remaining nodes in the stack and prevent any new nodes from
/// being pushed onto the stack.
pub(crate) fn shutdown(&self) {
// Shutdown the processing queue
let ptr = self.head.swap(SHUTDOWN, SeqCst);
// Let the drop fn of `AtomicStackEntries` handle draining the stack
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/atomic_stack.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/time/driver/atomic_stack.rs | 81 | 124 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:2 | //! walking lists of timers), it checks this "true when" value, and reschedules
//! based on it.
//!
//! We do, however, also need to track what the expiration time was when we
//! originally registered the timer; this is used to locate the right linked
//! list when the timer is being cancelled. This is referred to as... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | f3e340a35b306e926e78537a0dd65b2e9b9cdc89 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f3e340a35b306e926e78537a0dd65b2e9b9cdc89/tokio/src/time/driver/entry.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:3 | /// Generally, the StateCell is only permitted to be accessed from two contexts:
/// Either a thread holding the corresponding &mut TimerEntry, or a thread
/// holding the timer driver lock. The write actions on the StateCell amount to
/// passing "ownership" of the StateCell between these contexts; moving a timer
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | f3e340a35b306e926e78537a0dd65b2e9b9cdc89 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f3e340a35b306e926e78537a0dd65b2e9b9cdc89/tokio/src/time/driver/entry.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:5 | /// Marks this timer as being moved to the pending list, if its scheduled
/// time is not after `not_after`.
///
/// If the timer is scheduled for a time after not_after, returns an Err
/// containing the current scheduled time.
///
/// SAFETY: Must hold the driver lock.
unsafe fn mark_pendi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | f3e340a35b306e926e78537a0dd65b2e9b9cdc89 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f3e340a35b306e926e78537a0dd65b2e9b9cdc89/tokio/src/time/driver/entry.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:6 | /// * `Some(waker) - if fired and a waker needs to be invoked once the
/// driver lock is released
/// * `None` - if fired and a waker does not need to be invoked, or if
/// already fired
///
/// SAFETY: The driver lock must be held.
unsafe fn fire(&self, result: TimerResult) -> Option<Waker... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | f3e340a35b306e926e78537a0dd65b2e9b9cdc89 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f3e340a35b306e926e78537a0dd65b2e9b9cdc89/tokio/src/time/driver/entry.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:7 | /// Attempts to adjust the timer to a new timestamp.
///
/// If the timer has already been fired, is pending firing, or the new
/// timestamp is earlier than the old timestamp, (or occasionally
/// spuriously) returns Err without changing the timer's state. In this
/// case, the timer must be deregi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | f3e340a35b306e926e78537a0dd65b2e9b9cdc89 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f3e340a35b306e926e78537a0dd65b2e9b9cdc89/tokio/src/time/driver/entry.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:8 | ///
/// This is the handle to a timer that is controlled by the requester of the
/// timer. As this participates in intrusive data structures, it must be pinned
/// before polling.
#[derive(Debug)]
pub(super) struct TimerEntry {
/// Arc reference to the driver. We can only free the driver after
/// deregisterin... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | f3e340a35b306e926e78537a0dd65b2e9b9cdc89 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f3e340a35b306e926e78537a0dd65b2e9b9cdc89/tokio/src/time/driver/entry.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:9 | pub(super) type EntryList = crate::util::linked_list::LinkedList<TimerShared, TimerShared>;
/// The shared state structure of a timer. This structure is shared between the
/// frontend (`Entry`) and driver backend.
///
/// Note that this structure is located inside the `TimerEntry` structure.
#[derive(Debug)]
#[repr(C... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | f3e340a35b306e926e78537a0dd65b2e9b9cdc89 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f3e340a35b306e926e78537a0dd65b2e9b9cdc89/tokio/src/time/driver/entry.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:10 | // Cached-when is only accessed under the driver lock, so we can use relaxed
self.driver_state.0.cached_when.load(Ordering::Relaxed)
}
/// Gets the true time-of-expiration value, and copies it into the cached
/// time-of-expiration value.
///
/// SAFETY: Must be called with the driver lock ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | f3e340a35b306e926e78537a0dd65b2e9b9cdc89 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f3e340a35b306e926e78537a0dd65b2e9b9cdc89/tokio/src/time/driver/entry.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:11 | /// in the timer wheel.
pub(super) unsafe fn set_expiration(&self, t: u64) {
self.state.set_expiration(t);
self.driver_state.0.cached_when.store(t, Ordering::Relaxed);
}
/// Sets the true time-of-expiration only if it is after the current.
pub(super) fn extend_expiration(&self, t: u64) ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | f3e340a35b306e926e78537a0dd65b2e9b9cdc89 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f3e340a35b306e926e78537a0dd65b2e9b9cdc89/tokio/src/time/driver/entry.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:12 | /// registered.
cached_when: AtomicU64,
/// The true expiration time. Set by the timer future, read by the driver.
true_when: AtomicU64,
}
impl std::fmt::Debug for TimerSharedPadded {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("TimerSharedPadded")
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | f3e340a35b306e926e78537a0dd65b2e9b9cdc89 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f3e340a35b306e926e78537a0dd65b2e9b9cdc89/tokio/src/time/driver/entry.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:13 | }
unsafe fn pointers(
target: NonNull<Self::Target>,
) -> NonNull<linked_list::Pointers<Self::Target>> {
TimerShared::addr_of_pointers(target)
}
}
// ===== impl Entry =====
impl TimerEntry {
pub(crate) fn new(handle: &Handle, deadline: Instant) -> Self {
let driver = handle.cl... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | f3e340a35b306e926e78537a0dd65b2e9b9cdc89 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f3e340a35b306e926e78537a0dd65b2e9b9cdc89/tokio/src/time/driver/entry.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:14 | // something else).
//
// It is critical to ensure that, from the point of view of the driver,
// those future non-timer writes happen-after the timer is fully fired,
// and from the purpose of this thread, the driver's writes all
// happen-before we drop the timer. This in turn ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | f3e340a35b306e926e78537a0dd65b2e9b9cdc89 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f3e340a35b306e926e78537a0dd65b2e9b9cdc89/tokio/src/time/driver/entry.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:15 | if let Some(deadline) = self.initial_deadline {
self.as_mut().reset(deadline);
}
let this = unsafe { self.get_unchecked_mut() };
this.inner().state.poll(cx.waker())
}
}
impl TimerHandle {
pub(super) unsafe fn cached_when(&self) -> u64 {
unsafe { self.inner.as_ref()... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | f3e340a35b306e926e78537a0dd65b2e9b9cdc89 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f3e340a35b306e926e78537a0dd65b2e9b9cdc89/tokio/src/time/driver/entry.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:16 | pub(super) unsafe fn mark_pending(&self, not_after: u64) -> Result<(), u64> {
match self.inner.as_ref().state.mark_pending(not_after) {
Ok(()) => {
// mark this as being on the pending queue in cached_when
self.inner.as_ref().set_cached_when(u64::MAX);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | f3e340a35b306e926e78537a0dd65b2e9b9cdc89 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f3e340a35b306e926e78537a0dd65b2e9b9cdc89/tokio/src/time/driver/entry.rs | 601 | 640 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:8 | ///
/// This is the handle to a timer that is controlled by the requester of the
/// timer. As this participates in intrusive data structures, it must be pinned
/// before polling.
#[derive(Debug)]
pub(super) struct TimerEntry {
/// Arc reference to the driver. We can only free the driver after
/// deregisterin... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 1be8e9dfb7b1140568ac10ac34f5f8171a89e40d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1be8e9dfb7b1140568ac10ac34f5f8171a89e40d/tokio/src/time/driver/entry.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:9 | pub(super) type EntryList = crate::util::linked_list::LinkedList<TimerShared, TimerShared>;
/// The shared state structure of a timer. This structure is shared between the
/// frontend (`Entry`) and driver backend.
///
/// Note that this structure is located inside the `TimerEntry` structure.
#[derive(Debug)]
#[repr(C... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 1be8e9dfb7b1140568ac10ac34f5f8171a89e40d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1be8e9dfb7b1140568ac10ac34f5f8171a89e40d/tokio/src/time/driver/entry.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:10 | /// not in any timer wheel lists.
pub(super) unsafe fn sync_when(&self) -> u64 {
let true_when = self.true_when();
self.driver_state
.0
.cached_when
.store(true_when, Ordering::Relaxed);
true_when
}
/// Sets the cached time-of-expiration value.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 1be8e9dfb7b1140568ac10ac34f5f8171a89e40d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1be8e9dfb7b1140568ac10ac34f5f8171a89e40d/tokio/src/time/driver/entry.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:11 | self.state.extend_expiration(t)
}
/// Returns a TimerHandle for this timer.
pub(super) fn handle(&self) -> TimerHandle {
TimerHandle {
inner: NonNull::from(self),
}
}
/// Returns true if the state of this timer indicates that the timer might
/// be registered with t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 1be8e9dfb7b1140568ac10ac34f5f8171a89e40d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1be8e9dfb7b1140568ac10ac34f5f8171a89e40d/tokio/src/time/driver/entry.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:12 | impl std::fmt::Debug for TimerSharedPadded {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("TimerSharedPadded")
.field("when", &self.true_when.load(Ordering::Relaxed))
.field("cached_when", &self.cached_when.load(Ordering::Relaxed))
.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 1be8e9dfb7b1140568ac10ac34f5f8171a89e40d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1be8e9dfb7b1140568ac10ac34f5f8171a89e40d/tokio/src/time/driver/entry.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:13 | }
// ===== impl Entry =====
impl TimerEntry {
pub(crate) fn new(handle: &Handle, deadline: Instant) -> Self {
let driver = handle.clone();
Self {
driver,
inner: StdUnsafeCell::new(TimerShared::new()),
initial_deadline: Some(deadline),
_m: std::marke... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 1be8e9dfb7b1140568ac10ac34f5f8171a89e40d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1be8e9dfb7b1140568ac10ac34f5f8171a89e40d/tokio/src/time/driver/entry.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:14 | // and dropping thread.
//
// The lock acquisition in clear_entry serves this purpose. All of the
// driver manipulations happen with the lock held, so we can just take
// the lock and be sure that this drop happens-after everything the
// driver did so far and happens-before eve... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 1be8e9dfb7b1140568ac10ac34f5f8171a89e40d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1be8e9dfb7b1140568ac10ac34f5f8171a89e40d/tokio/src/time/driver/entry.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:15 | }
}
impl TimerHandle {
pub(super) unsafe fn cached_when(&self) -> u64 {
unsafe { self.inner.as_ref().cached_when() }
}
pub(super) unsafe fn sync_when(&self) -> u64 {
unsafe { self.inner.as_ref().sync_when() }
}
pub(super) unsafe fn is_pending(&self) -> bool {
unsafe { self... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 1be8e9dfb7b1140568ac10ac34f5f8171a89e40d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1be8e9dfb7b1140568ac10ac34f5f8171a89e40d/tokio/src/time/driver/entry.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:16 | Err(tick) => {
self.inner.as_ref().set_cached_when(tick);
Err(tick)
}
}
}
/// Attempts to transition to a terminal state. If the state is already a
/// terminal state, does nothing.
///
/// Because the entry might be dropped after the state is mov... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 1be8e9dfb7b1140568ac10ac34f5f8171a89e40d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1be8e9dfb7b1140568ac10ac34f5f8171a89e40d/tokio/src/time/driver/entry.rs | 601 | 633 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:8 | ///
/// This is the handle to a timer that is controlled by the requester of the
/// timer. As this participates in intrusive data structures, it must be pinned
/// before polling.
#[derive(Debug)]
pub(super) struct TimerEntry {
/// Arc reference to the driver. We can only free the driver after
/// deregisterin... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 64da914d1798190bbfc82c2f8548bba5a5098538 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/64da914d1798190bbfc82c2f8548bba5a5098538/tokio/src/time/driver/entry.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:9 | pub(super) type EntryList = crate::util::linked_list::LinkedList<TimerShared, TimerShared>;
/// The shared state structure of a timer. This structure is shared between the
/// frontend (`Entry`) and driver backend.
///
/// Note that this structure is located inside the `TimerEntry` structure.
#[derive(Debug)]
pub(crat... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 64da914d1798190bbfc82c2f8548bba5a5098538 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/64da914d1798190bbfc82c2f8548bba5a5098538/tokio/src/time/driver/entry.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:10 | pub(super) unsafe fn sync_when(&self) -> u64 {
let true_when = self.true_when();
self.driver_state
.0
.cached_when
.store(true_when, Ordering::Relaxed);
true_when
}
/// Sets the cached time-of-expiration value.
///
/// SAFETY: Must be called... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 64da914d1798190bbfc82c2f8548bba5a5098538 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/64da914d1798190bbfc82c2f8548bba5a5098538/tokio/src/time/driver/entry.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:11 | }
/// Returns a TimerHandle for this timer.
pub(super) fn handle(&self) -> TimerHandle {
TimerHandle {
inner: NonNull::from(self),
}
}
/// Returns true if the state of this timer indicates that the timer might
/// be registered with the driver. This check is performed w... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 64da914d1798190bbfc82c2f8548bba5a5098538 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/64da914d1798190bbfc82c2f8548bba5a5098538/tokio/src/time/driver/entry.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:12 | f.debug_struct("TimerSharedPadded")
.field("when", &self.true_when.load(Ordering::Relaxed))
.field("cached_when", &self.cached_when.load(Ordering::Relaxed))
.finish()
}
}
impl TimerSharedPadded {
fn new() -> Self {
Self {
cached_when: AtomicU64::new(0),
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 64da914d1798190bbfc82c2f8548bba5a5098538 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/64da914d1798190bbfc82c2f8548bba5a5098538/tokio/src/time/driver/entry.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:13 | // ===== impl Entry =====
impl TimerEntry {
pub(crate) fn new(handle: &Handle, deadline: Instant) -> Self {
let driver = handle.clone();
Self {
driver,
inner: StdUnsafeCell::new(TimerShared::new()),
initial_deadline: Some(deadline),
_m: std::marker::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 64da914d1798190bbfc82c2f8548bba5a5098538 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/64da914d1798190bbfc82c2f8548bba5a5098538/tokio/src/time/driver/entry.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:14 | // The lock acquisition in clear_entry serves this purpose. All of the
// driver manipulations happen with the lock held, so we can just take
// the lock and be sure that this drop happens-after everything the
// driver did so far and happens-before everything the driver does in
// the f... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 64da914d1798190bbfc82c2f8548bba5a5098538 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/64da914d1798190bbfc82c2f8548bba5a5098538/tokio/src/time/driver/entry.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:15 | impl TimerHandle {
pub(super) unsafe fn cached_when(&self) -> u64 {
unsafe { self.inner.as_ref().cached_when() }
}
pub(super) unsafe fn sync_when(&self) -> u64 {
unsafe { self.inner.as_ref().sync_when() }
}
pub(super) unsafe fn is_pending(&self) -> bool {
unsafe { self.inne... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 64da914d1798190bbfc82c2f8548bba5a5098538 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/64da914d1798190bbfc82c2f8548bba5a5098538/tokio/src/time/driver/entry.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:16 | Err(tick)
}
}
}
/// Attempts to transition to a terminal state. If the state is already a
/// terminal state, does nothing.
///
/// Because the entry might be dropped after the state is moved to a
/// terminal state, this function consumes the handle to ensure we don't
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 64da914d1798190bbfc82c2f8548bba5a5098538 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/64da914d1798190bbfc82c2f8548bba5a5098538/tokio/src/time/driver/entry.rs | 601 | 631 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:2 | //! walking lists of timers), it checks this "true when" value, and reschedules
//! based on it.
//!
//! We do, however, also need to track what the expiration time was when we
//! originally registered the timer; this is used to locate the right linked
//! list when the timer is being cancelled. This is referred to as... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/time/driver/entry.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:3 | /// holding the timer driver lock. The write actions on the StateCell amount to
/// passing "ownership" of the StateCell between these contexts; moving a timer
/// from the TimerEntry to the driver requires _both_ holding the &mut
/// TimerEntry and the driver lock, while moving it back (firing the timer)
/// requires ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/time/driver/entry.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:4 | self.state.load(Ordering::Relaxed) == STATE_PENDING_FIRE
}
/// Returns the current expiration time, or None if not currently scheduled.
fn when(&self) -> Option<u64> {
let cur_state = self.state.load(Ordering::Relaxed);
if cur_state == u64::MAX {
None
} else {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/time/driver/entry.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:5 | ///
/// If the timer is scheduled for a time after not_after, returns an Err
/// containing the current scheduled time.
///
/// SAFETY: Must hold the driver lock.
unsafe fn mark_pending(&self, not_after: u64) -> Result<(), u64> {
// Quick initial debug check to see if the timer is already fi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/time/driver/entry.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:6 | /// * `None` - if fired and a waker does not need to be invoked, or if
/// already fired
///
/// SAFETY: The driver lock must be held.
unsafe fn fire(&self, result: TimerResult) -> Option<Waker> {
// Quick initial check to see if the timer is already fired. Since
// firing the timer ca... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/time/driver/entry.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:7 | ///
/// If the timer has already been fired, is pending firing, or the new
/// timestamp is earlier than the old timestamp, (or occasionally
/// spuriously) returns Err without changing the timer's state. In this
/// case, the timer must be deregistered and re-registered.
fn extend_expiration(&self,... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/time/driver/entry.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:8 | /// timer. As this participates in intrusive data structures, it must be pinned
/// before polling.
#[derive(Debug)]
pub(super) struct TimerEntry {
/// Arc reference to the driver. We can only free the driver after
/// deregistering everything from their respective timer wheels.
driver: Handle,
/// Shar... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/time/driver/entry.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:9 | /// The shared state structure of a timer. This structure is shared between the
/// frontend (`Entry`) and driver backend.
///
/// Note that this structure is located inside the `TimerEntry` structure.
#[derive(Debug)]
pub(crate) struct TimerShared {
/// Current state. This records whether the timer entry is curren... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/time/driver/entry.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:10 | self.driver_state
.0
.cached_when
.store(true_when, Ordering::Relaxed);
true_when
}
/// Sets the cached time-of-expiration value.
///
/// SAFETY: Must be called with the driver lock held, and when this entry is
/// not in any timer wheel lists.
unsaf... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/time/driver/entry.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:11 | /// Returns a TimerHandle for this timer.
pub(super) fn handle(&self) -> TimerHandle {
TimerHandle {
inner: NonNull::from(self),
}
}
/// Returns true if the state of this timer indicates that the timer might
/// be registered with the driver. This check is performed with rel... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/time/driver/entry.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:12 | .field("cached_when", &self.cached_when.load(Ordering::Relaxed))
.finish()
}
}
impl TimerSharedPadded {
fn new() -> Self {
Self {
cached_when: AtomicU64::new(0),
true_when: AtomicU64::new(0),
pointers: StdUnsafeCell::new(linked_list::Pointers::new()),
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/time/driver/entry.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:13 | impl TimerEntry {
pub(crate) fn new(handle: &Handle, deadline: Instant) -> Self {
let driver = handle.clone();
Self {
driver,
inner: StdUnsafeCell::new(TimerShared::new()),
initial_deadline: Some(deadline),
_m: std::marker::PhantomPinned,
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/time/driver/entry.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:14 | // the lock and be sure that this drop happens-after everything the
// driver did so far and happens-before everything the driver does in
// the future. While we have the lock held, we also go ahead and
// deregister the entry if necessary.
unsafe { self.driver.clear_entry(NonNull::from(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/time/driver/entry.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:15 | pub(super) unsafe fn cached_when(&self) -> u64 {
unsafe { self.inner.as_ref().cached_when() }
}
pub(super) unsafe fn sync_when(&self) -> u64 {
unsafe { self.inner.as_ref().sync_when() }
}
pub(super) unsafe fn is_pending(&self) -> bool {
unsafe { self.inner.as_ref().state.is_pen... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/time/driver/entry.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:16 | }
}
/// Attempts to transition to a terminal state. If the state is already a
/// terminal state, does nothing.
///
/// Because the entry might be dropped after the state is moved to a
/// terminal state, this function consumes the handle to ensure we don't
/// access the entry afterwards.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/time/driver/entry.rs | 601 | 629 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:9 | /// The shared state structure of a timer. This structure is shared between the
/// frontend (`Entry`) and driver backend.
///
/// Note that this structure is located inside the `TimerEntry` structure.
#[derive(Debug)]
pub(crate) struct TimerShared {
/// Current state. This records whether the timer entry is curren... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | f3ed064a269fd72711e40121dad1a9fd9f16bdc0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f3ed064a269fd72711e40121dad1a9fd9f16bdc0/tokio/src/time/driver/entry.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:2 | //! walking lists of timers), it checks this "true when" value, and reschedules
//! based on it.
//!
//! We do, however, also need to track what the expiration time was when we
//! originally registered the timer; this is used to locate the right linked
//! list when the timer is being cancelled. This is referred to as... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | a08ce0d3e06d650361283dc87c8fe14b146df15d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a08ce0d3e06d650361283dc87c8fe14b146df15d/tokio/src/time/driver/entry.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/driver/entry.rs:3 | /// holding the timer driver lock. The write actions on the StateCell amount to
/// passing "ownership" of the StateCell between these contexts; moving a timer
/// from the TimerEntry to the driver requires _both_ holding the &mut
/// TimerEntry and the driver lock, while moving it back (firing the timer)
/// requires ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/driver/entry.rs | MIT | a08ce0d3e06d650361283dc87c8fe14b146df15d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a08ce0d3e06d650361283dc87c8fe14b146df15d/tokio/src/time/driver/entry.rs | 81 | 140 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.