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/runtime/time/entry.rs:8 | /// A timer entry.
///
/// 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(crate) struct TimerEntry {
/// Arc reference to the runtime handle. We can only free the driver... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 159a3b2c8587cd12ad54eb16489dad6eb674d4ca | github | async-runtime | https://github.com/tokio-rs/tokio/blob/159a3b2c8587cd12ad54eb16489dad6eb674d4ca/tokio/src/runtime/time/entry.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:9 | pub(crate) struct TimerHandle {
inner: NonNull<TimerShared>,
}
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 ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 159a3b2c8587cd12ad54eb16489dad6eb674d4ca | github | async-runtime | https://github.com/tokio-rs/tokio/blob/159a3b2c8587cd12ad54eb16489dad6eb674d4ca/tokio/src/runtime/time/entry.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:10 | .finish()
}
}
generate_addr_of_methods! {
impl<> TimerShared {
unsafe fn addr_of_pointers(self: NonNull<Self>) -> NonNull<linked_list::Pointers<TimerShared>> {
&self.pointers
}
}
}
impl TimerShared {
pub(super) fn new(shard_id: u32) -> Self {
Self {
shar... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 159a3b2c8587cd12ad54eb16489dad6eb674d4ca | github | async-runtime | https://github.com/tokio-rs/tokio/blob/159a3b2c8587cd12ad54eb16489dad6eb674d4ca/tokio/src/runtime/time/entry.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:11 | }
/// 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.
unsafe fn set_cached_when(&self, when: u64) {
self.cached_when.store(when, Ordering::Relaxed);
}
/// Returns the true t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 159a3b2c8587cd12ad54eb16489dad6eb674d4ca | github | async-runtime | https://github.com/tokio-rs/tokio/blob/159a3b2c8587cd12ad54eb16489dad6eb674d4ca/tokio/src/runtime/time/entry.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:12 | /// definitely _not_ registered.
pub(super) fn might_be_registered(&self) -> bool {
self.state.might_be_registered()
}
/// Gets the shard id.
pub(super) fn shard_id(&self) -> u32 {
self.shard_id
}
}
unsafe impl linked_list::Link for TimerShared {
type Handle = TimerHandle;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 159a3b2c8587cd12ad54eb16489dad6eb674d4ca | github | async-runtime | https://github.com/tokio-rs/tokio/blob/159a3b2c8587cd12ad54eb16489dad6eb674d4ca/tokio/src/runtime/time/entry.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:13 | driver: handle,
inner: StdUnsafeCell::new(None),
deadline,
registered: false,
_m: std::marker::PhantomPinned,
}
}
fn is_inner_init(&self) -> bool {
unsafe { &*self.inner.get() }.is_some()
}
// This lazy initialization is for performance p... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 159a3b2c8587cd12ad54eb16489dad6eb674d4ca | github | async-runtime | https://github.com/tokio-rs/tokio/blob/159a3b2c8587cd12ad54eb16489dad6eb674d4ca/tokio/src/runtime/time/entry.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:14 | // simplest way to do so is to grab the driver lock.
//
// Why is this necessary? We're about to release this timer's memory for
// some other non-timer use. However, we've been doing a bunch of
// relaxed (or even non-atomic) writes from the driver thread, and we'll
// be doing ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 159a3b2c8587cd12ad54eb16489dad6eb674d4ca | github | async-runtime | https://github.com/tokio-rs/tokio/blob/159a3b2c8587cd12ad54eb16489dad6eb674d4ca/tokio/src/runtime/time/entry.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:15 | }
}
pub(crate) fn poll_elapsed(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), super::Error>> {
assert!(
!self.driver().is_shutdown(),
"{}",
crate::util::error::RUNTIME_SHUTTING_DOWN_ERROR
);
if !self.registe... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 159a3b2c8587cd12ad54eb16489dad6eb674d4ca | github | async-runtime | https://github.com/tokio-rs/tokio/blob/159a3b2c8587cd12ad54eb16489dad6eb674d4ca/tokio/src/runtime/time/entry.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:16 | pub(super) unsafe fn is_pending(&self) -> bool {
unsafe { self.inner.as_ref().state.is_pending() }
}
/// Forcibly sets the true and cached expiration times to the given tick.
///
/// SAFETY: The caller must ensure that the handle remains valid, the driver
/// lock is held, and that the time... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 159a3b2c8587cd12ad54eb16489dad6eb674d4ca | github | async-runtime | https://github.com/tokio-rs/tokio/blob/159a3b2c8587cd12ad54eb16489dad6eb674d4ca/tokio/src/runtime/time/entry.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:17 | /// access the entry afterwards.
///
/// Returns the last-registered waker, if any.
///
/// SAFETY: The driver lock must be held while invoking this function, and
/// the entry must not be in any wheel linked lists.
pub(super) unsafe fn fire(self, completed_state: TimerResult) -> Option<Waker> {... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 159a3b2c8587cd12ad54eb16489dad6eb674d4ca | github | async-runtime | https://github.com/tokio-rs/tokio/blob/159a3b2c8587cd12ad54eb16489dad6eb674d4ca/tokio/src/runtime/time/entry.rs | 641 | 676 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:17 | /// access the entry afterwards.
///
/// Returns the last-registered waker, if any.
///
/// SAFETY: The driver lock must be held while invoking this function, and
/// the entry must not be in any wheel linked lists.
pub(super) unsafe fn fire(self, completed_state: TimerResult) -> Option<Waker> {... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 47210a8e6eeb82b51aa778074fdc4d757b953b8c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/47210a8e6eeb82b51aa778074fdc4d757b953b8c/tokio/src/runtime/time/entry.rs | 641 | 678 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:2 | //! 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 the "cached
//! when" internally.
//!
//! There is of course a race condition b... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 8480a180e6ffdd0ec0ec213a9bebcda2445fc541 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8480a180e6ffdd0ec0ec213a9bebcda2445fc541/tokio/src/runtime/time/entry.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:3 | /// time (if registered), or otherwise the result of the timer completing, as
/// well as the registered waker.
///
/// 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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 8480a180e6ffdd0ec0ec213a9bebcda2445fc541 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8480a180e6ffdd0ec0ec213a9bebcda2445fc541/tokio/src/runtime/time/entry.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:4 | waker: AtomicWaker::new(),
}
}
/// 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 == STATE_DEREGISTERED {
None
} else {
Some(cu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 8480a180e6ffdd0ec0ec213a9bebcda2445fc541 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8480a180e6ffdd0ec0ec213a9bebcda2445fc541/tokio/src/runtime/time/entry.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/time/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_firing(&self, not_after: u64) -> Result<(), u64> {
// Quick initial debug check to see if the timer is already f... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 8480a180e6ffdd0ec0ec213a9bebcda2445fc541 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8480a180e6ffdd0ec0ec213a9bebcda2445fc541/tokio/src/runtime/time/entry.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:6 | ///
/// Returns:
/// * `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: Ti... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 8480a180e6ffdd0ec0ec213a9bebcda2445fc541 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8480a180e6ffdd0ec0ec213a9bebcda2445fc541/tokio/src/runtime/time/entry.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:7 | self.state.store(timestamp, Ordering::Relaxed);
}
/// 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 ti... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 8480a180e6ffdd0ec0ec213a9bebcda2445fc541 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8480a180e6ffdd0ec0ec213a9bebcda2445fc541/tokio/src/runtime/time/entry.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:8 | /// timer. As this participates in intrusive data structures, it must be pinned
/// before polling.
#[derive(Debug)]
pub(crate) struct TimerEntry {
/// Arc reference to the runtime handle. We can only free the driver after
/// deregistering everything from their respective timer wheels.
driver: scheduler::H... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 8480a180e6ffdd0ec0ec213a9bebcda2445fc541 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8480a180e6ffdd0ec0ec213a9bebcda2445fc541/tokio/src/runtime/time/entry.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/time/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.
pub(crate) struct TimerSh... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 8480a180e6ffdd0ec0ec213a9bebcda2445fc541 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8480a180e6ffdd0ec0ec213a9bebcda2445fc541/tokio/src/runtime/time/entry.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:10 | }
}
impl TimerShared {
pub(super) fn new(shard_id: u32) -> Self {
Self {
shard_id,
pointers: linked_list::Pointers::new(),
state: StateCell::default(),
_p: PhantomPinned,
}
}
/// Returns the true time-of-expiration value, with relaxed memory ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 8480a180e6ffdd0ec0ec213a9bebcda2445fc541 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8480a180e6ffdd0ec0ec213a9bebcda2445fc541/tokio/src/runtime/time/entry.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:11 | /// be registered with the driver. This check is performed with relaxed
/// ordering, but is conservative - if it returns false, the timer is
/// definitely _not_ registered.
pub(super) fn might_be_registered(&self) -> bool {
self.state.might_be_registered()
}
/// Gets the shard id.
pub... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 8480a180e6ffdd0ec0ec213a9bebcda2445fc541 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8480a180e6ffdd0ec0ec213a9bebcda2445fc541/tokio/src/runtime/time/entry.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:12 | Self {
driver: handle,
inner: StdUnsafeCell::new(None),
deadline,
registered: false,
_m: std::marker::PhantomPinned,
}
}
fn is_inner_init(&self) -> bool {
unsafe { &*self.inner.get() }.is_some()
}
// This lazy initialization i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 8480a180e6ffdd0ec0ec213a9bebcda2445fc541 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8480a180e6ffdd0ec0ec213a9bebcda2445fc541/tokio/src/runtime/time/entry.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:13 | }
// We need to perform an acq/rel fence with the driver thread, and the
// simplest way to do so is to grab the driver lock.
//
// Why is this necessary? We're about to release this timer's memory for
// some other non-timer use. However, we've been doing a bunch of
// r... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 8480a180e6ffdd0ec0ec213a9bebcda2445fc541 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8480a180e6ffdd0ec0ec213a9bebcda2445fc541/tokio/src/runtime/time/entry.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:14 | .reregister(&self.driver.driver().io, tick, self.inner().into());
}
}
}
pub(crate) fn poll_elapsed(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), super::Error>> {
assert!(
!self.driver().is_shutdown(),
"{}",
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 8480a180e6ffdd0ec0ec213a9bebcda2445fc541 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8480a180e6ffdd0ec0ec213a9bebcda2445fc541/tokio/src/runtime/time/entry.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:15 | /// SAFETY: The caller must ensure that the handle remains valid, the driver
/// lock is held, and that the timer is not in any wheel linked lists.
pub(super) unsafe fn set_expiration(&self, tick: u64) {
self.inner.as_ref().set_expiration(tick);
}
/// Attempts to mark this entry as firing. If t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 8480a180e6ffdd0ec0ec213a9bebcda2445fc541 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8480a180e6ffdd0ec0ec213a9bebcda2445fc541/tokio/src/runtime/time/entry.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:16 | // Generates a shard id. If current thread is a worker thread, we use its worker index as a shard id.
// Otherwise, we use a random number generator to obtain the shard id.
cfg_rt! {
fn generate_shard_id(shard_size: u32) -> u32 {
let id = context::with_scheduler(|ctx| match ctx {
Some(scheduler:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 8480a180e6ffdd0ec0ec213a9bebcda2445fc541 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8480a180e6ffdd0ec0ec213a9bebcda2445fc541/tokio/src/runtime/time/entry.rs | 601 | 621 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:9 | inner: NonNull<TimerShared>,
}
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` stru... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | f6eb1ee19687bfd6cc7bf5c675d946970854013e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f6eb1ee19687bfd6cc7bf5c675d946970854013e/tokio/src/runtime/time/entry.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:10 | .field("state", &self.state)
.finish()
}
}
generate_addr_of_methods! {
impl<> TimerShared {
unsafe fn addr_of_pointers(self: NonNull<Self>) -> NonNull<linked_list::Pointers<TimerShared>> {
&self.pointers
}
}
}
impl TimerShared {
pub(super) fn new() -> Self {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | f6eb1ee19687bfd6cc7bf5c675d946970854013e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f6eb1ee19687bfd6cc7bf5c675d946970854013e/tokio/src/runtime/time/entry.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:11 | 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.
unsafe fn set_cached_when(&self, when: u64) {
self.cached_when.store(when, Ordering::Relaxed);
}
/// Retu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | f6eb1ee19687bfd6cc7bf5c675d946970854013e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f6eb1ee19687bfd6cc7bf5c675d946970854013e/tokio/src/runtime/time/entry.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:12 | /// ordering, but is conservative - if it returns false, the timer is
/// definitely _not_ registered.
pub(super) fn might_be_registered(&self) -> bool {
self.state.might_be_registered()
}
}
unsafe impl linked_list::Link for TimerShared {
type Handle = TimerHandle;
type Target = TimerShare... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | f6eb1ee19687bfd6cc7bf5c675d946970854013e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f6eb1ee19687bfd6cc7bf5c675d946970854013e/tokio/src/runtime/time/entry.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:13 | _m: std::marker::PhantomPinned,
}
}
fn is_inner_init(&self) -> bool {
unsafe { &*self.inner.get() }.is_some()
}
// This lazy initialization is for performance purposes.
fn inner(&self) -> &TimerShared {
let inner = unsafe { &*self.inner.get() };
if inner.is_none() {... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | f6eb1ee19687bfd6cc7bf5c675d946970854013e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f6eb1ee19687bfd6cc7bf5c675d946970854013e/tokio/src/runtime/time/entry.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/time/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/runtime/time/entry.rs | MIT | f6eb1ee19687bfd6cc7bf5c675d946970854013e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f6eb1ee19687bfd6cc7bf5c675d946970854013e/tokio/src/runtime/time/entry.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:15 | ) -> Poll<Result<(), super::Error>> {
assert!(
!self.driver().is_shutdown(),
"{}",
crate::util::error::RUNTIME_SHUTTING_DOWN_ERROR
);
if !self.registered {
let deadline = self.deadline;
self.as_mut().reset(deadline, true);
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | f6eb1ee19687bfd6cc7bf5c675d946970854013e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f6eb1ee19687bfd6cc7bf5c675d946970854013e/tokio/src/runtime/time/entry.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:16 | /// SAFETY: The caller must ensure that the handle remains valid, the driver
/// lock is held, and that the timer is not in any wheel linked lists.
pub(super) unsafe fn set_expiration(&self, tick: u64) {
self.inner.as_ref().set_expiration(tick);
}
/// Attempts to mark this entry as pending. If ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | f6eb1ee19687bfd6cc7bf5c675d946970854013e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f6eb1ee19687bfd6cc7bf5c675d946970854013e/tokio/src/runtime/time/entry.rs | 601 | 650 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:17 | pub(super) unsafe fn fire(self, completed_state: TimerResult) -> Option<Waker> {
self.inner.as_ref().state.fire(completed_state)
}
}
impl Drop for TimerEntry {
fn drop(&mut self) {
unsafe { Pin::new_unchecked(self) }.as_mut().cancel();
}
} | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | f6eb1ee19687bfd6cc7bf5c675d946970854013e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f6eb1ee19687bfd6cc7bf5c675d946970854013e/tokio/src/runtime/time/entry.rs | 641 | 650 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:7 | // We can use relaxed ordering because we hold the driver lock and will
// fence when we release the lock.
self.state.store(timestamp, Ordering::Relaxed);
}
/// Attempts to adjust the timer to a new timestamp.
///
/// If the timer has already been fired, is pending firing, or the new
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 28439e2269f2696a5009f2f05ce8f39b7fa13217 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/28439e2269f2696a5009f2f05ce8f39b7fa13217/tokio/src/runtime/time/entry.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/time/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(crate) struct TimerEntry {
/// Arc reference to the runtime handle. We can only free the driver after
/// dere... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 28439e2269f2696a5009f2f05ce8f39b7fa13217 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/28439e2269f2696a5009f2f05ce8f39b7fa13217/tokio/src/runtime/time/entry.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:12 | /// ordering, but is conservative - if it returns false, the timer is
/// definitely _not_ registered.
pub(super) fn might_be_registered(&self) -> bool {
self.state.might_be_registered()
}
}
unsafe impl linked_list::Link for TimerShared {
type Handle = TimerHandle;
type Target = TimerShare... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 28439e2269f2696a5009f2f05ce8f39b7fa13217 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/28439e2269f2696a5009f2f05ce8f39b7fa13217/tokio/src/runtime/time/entry.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:13 | deadline,
registered: false,
_m: std::marker::PhantomPinned,
}
}
fn inner(&self) -> &TimerShared {
unsafe { &*self.inner.get() }
}
pub(crate) fn deadline(&self) -> Instant {
self.deadline
}
pub(crate) fn is_elapsed(&self) -> bool {
!self... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 28439e2269f2696a5009f2f05ce8f39b7fa13217 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/28439e2269f2696a5009f2f05ce8f39b7fa13217/tokio/src/runtime/time/entry.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:14 | // 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(self.inner())) };
}
pub(crate) fn reset(mut self: Pin<&mut Self>, new_time: Instant, reregister: bool) {
unsafe { self.as_mut().get_unc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 28439e2269f2696a5009f2f05ce8f39b7fa13217 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/28439e2269f2696a5009f2f05ce8f39b7fa13217/tokio/src/runtime/time/entry.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:15 | pub(crate) fn driver(&self) -> &super::Handle {
self.driver.driver().time()
}
#[cfg(all(tokio_unstable, feature = "tracing"))]
pub(crate) fn clock(&self) -> &super::Clock {
self.driver.driver().clock()
}
}
impl TimerHandle {
pub(super) unsafe fn cached_when(&self) -> u64 {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 28439e2269f2696a5009f2f05ce8f39b7fa13217 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/28439e2269f2696a5009f2f05ce8f39b7fa13217/tokio/src/runtime/time/entry.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:16 | /// After returning Ok, the entry must be added to the pending list.
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
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 28439e2269f2696a5009f2f05ce8f39b7fa13217 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/28439e2269f2696a5009f2f05ce8f39b7fa13217/tokio/src/runtime/time/entry.rs | 601 | 636 |
tokio-rs/tokio:tokio/src/runtime/time/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/runtime/time/entry.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/time/entry.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/time/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.
unsaf... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/time/entry.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:6 | }
}
}
}
/// Fires the timer, setting the result to the provided result.
///
/// Returns:
/// * `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
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/time/entry.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:7 | /// context holding both `&mut TimerEntry` and the driver lock.
fn set_expiration(&self, timestamp: u64) {
debug_assert!(timestamp < STATE_MIN_VALUE);
// We can use relaxed ordering because we hold the driver lock and will
// fence when we release the lock.
self.state.store(timestam... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/time/entry.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:8 | /// ordering, but is conservative - if it returns false, the timer is
/// definitely _not_ registered.
pub(super) fn might_be_registered(&self) -> bool {
self.state.load(Ordering::Relaxed) != u64::MAX
}
}
/// A timer entry.
///
/// This is the handle to a timer that is controlled by the requester o... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/time/entry.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:9 | /// SAFETY: An `TimerHandle` is essentially a raw pointer, and the usual caveats
/// of pointer safety apply. In particular, `TimerHandle` does not itself enforce
/// that the timer does still exist; however, normally an `TimerHandle` is created
/// immediately before registering the timer, and is consumed when firing ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/time/entry.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:10 | unsafe impl Send for TimerShared {}
unsafe impl Sync for TimerShared {}
impl std::fmt::Debug for TimerShared {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("TimerShared")
.field("when", &self.true_when.load(Ordering::Relaxed))
.field("cached_wh... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/time/entry.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:11 | ///
/// SAFETY: Must be called with the driver lock held, and when this entry is
/// not in any timer wheel lists.
pub(super) unsafe fn sync_when(&self) -> u64 {
let true_when = self.true_when();
self.cached_when.store(true_when, Ordering::Relaxed);
true_when
}
/// Sets th... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/time/entry.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:12 | 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 relaxed
/// ordering, but is conservative - i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/time/entry.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:13 | // Panic if the time driver is not enabled
let _ = handle.driver().time();
let driver = handle.clone();
Self {
driver,
inner: StdUnsafeCell::new(TimerShared::new()),
deadline,
registered: false,
_m: std::marker::PhantomPinned,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/time/entry.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:14 | // happen-before we drop the timer. This in turn requires us to perform
// an acquire-release barrier in _both_ directions between the driver
// and dropping thread.
//
// The lock acquisition in clear_entry serves this purpose. All of the
// driver manipulations happen with the ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/time/entry.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:15 | if !self.registered {
let deadline = self.deadline;
self.as_mut().reset(deadline, true);
}
let this = unsafe { self.get_unchecked_mut() };
this.inner().state.poll(cx.waker())
}
pub(crate) fn driver(&self) -> &super::Handle {
self.driver.driver().time()
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/time/entry.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:16 | }
/// Attempts to mark this entry as pending. If the expiration time is after
/// `not_after`, however, returns an Err with the current expiration time.
///
/// If an `Err` is returned, the `cached_when` value will be updated to this
/// new expiration time.
///
/// SAFETY: The caller must ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/time/entry.rs | 601 | 646 |
tokio-rs/tokio:tokio/src/runtime/time/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/runtime/time/entry.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/runtime/time/entry.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:3 | /// time (if registered), or otherwise the result of the timer completing, as
/// well as the registered waker.
///
/// 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 act... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/runtime/time/entry.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:4 | waker: AtomicWaker::new(),
}
}
fn is_pending(&self) -> bool {
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::Re... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/runtime/time/entry.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/time/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 ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/runtime/time/entry.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:8 | /// ordering, but is conservative - if it returns false, the timer is
/// definitely _not_ registered.
pub(super) fn might_be_registered(&self) -> bool {
self.state.load(Ordering::Relaxed) != u64::MAX
}
}
/// A timer entry.
///
/// This is the handle to a timer that is controlled by the requester o... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/runtime/time/entry.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:9 | /// SAFETY: An TimerHandle is essentially a raw pointer, and the usual caveats
/// of pointer safety apply. In particular, TimerHandle does not itself enforce
/// that the timer does still exist; however, normally an TimerHandle is created
/// immediately before registering the timer, and is consumed when firing the
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/runtime/time/entry.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:11 | ///
/// SAFETY: Must be called with the driver lock held, and when this entry is
/// not in any timer wheel lists.
pub(super) unsafe fn sync_when(&self) -> u64 {
let true_when = self.true_when();
self.cached_when.store(true_when, Ordering::Relaxed);
true_when
}
/// Sets th... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/runtime/time/entry.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/time/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 ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 2a54ad01d0945c851a093849c83019de69e98dee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2a54ad01d0945c851a093849c83019de69e98dee/tokio/src/runtime/time/entry.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:6 | }
}
}
}
/// Fires the timer, setting the result to the provided result.
///
/// Returns:
/// * `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
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 2a54ad01d0945c851a093849c83019de69e98dee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2a54ad01d0945c851a093849c83019de69e98dee/tokio/src/runtime/time/entry.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:14 | // happen-before we drop the timer. This in turn requires us to perform
// an acquire-release barrier in _both_ directions between the driver
// and dropping thread.
//
// The lock acquisition in clear_entry serves this purpose. All of the
// driver manipulations happen with the ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 2a54ad01d0945c851a093849c83019de69e98dee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2a54ad01d0945c851a093849c83019de69e98dee/tokio/src/runtime/time/entry.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:15 | let deadline = self.deadline;
self.as_mut().reset(deadline, true);
}
let this = unsafe { self.get_unchecked_mut() };
this.inner().state.poll(cx.waker())
}
pub(crate) fn driver(&self) -> &super::Handle {
self.driver.driver().time()
}
#[cfg(all(tokio_unstabl... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 2a54ad01d0945c851a093849c83019de69e98dee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2a54ad01d0945c851a093849c83019de69e98dee/tokio/src/runtime/time/entry.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:16 | /// Attempts to mark this entry as pending. If the expiration time is after
/// `not_after`, however, returns an Err with the current expiration time.
///
/// If an `Err` is returned, the `cached_when` value will be updated to this
/// new expiration time.
///
/// SAFETY: The caller must ensure ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 2a54ad01d0945c851a093849c83019de69e98dee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2a54ad01d0945c851a093849c83019de69e98dee/tokio/src/runtime/time/entry.rs | 601 | 644 |
tokio-rs/tokio:tokio/src/runtime/time/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/runtime/time/entry.rs | MIT | 68b02db1543880cb95ceccc39f453f8dd2223f04 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/68b02db1543880cb95ceccc39f453f8dd2223f04/tokio/src/runtime/time/entry.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:3 | /// 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
/// from the TimerEntry to the driver requires _both_ holding the &mut
/// TimerEntry... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 68b02db1543880cb95ceccc39f453f8dd2223f04 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/68b02db1543880cb95ceccc39f453f8dd2223f04/tokio/src/runtime/time/entry.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:4 | fn is_pending(&self) -> bool {
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 {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 68b02db1543880cb95ceccc39f453f8dd2223f04 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/68b02db1543880cb95ceccc39f453f8dd2223f04/tokio/src/runtime/time/entry.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:5 | /// 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_pending(&self, not_after: u64) -> Result<(), u64> {
// Quick initial debug ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 68b02db1543880cb95ceccc39f453f8dd2223f04 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/68b02db1543880cb95ceccc39f453f8dd2223f04/tokio/src/runtime/time/entry.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:6 | /// Fires the timer, setting the result to the provided result.
///
/// Returns:
/// * `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:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 68b02db1543880cb95ceccc39f453f8dd2223f04 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/68b02db1543880cb95ceccc39f453f8dd2223f04/tokio/src/runtime/time/entry.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:7 | // We can use relaxed ordering because we hold the driver lock and will
// fence when we release the lock.
self.state.store(timestamp, Ordering::Relaxed);
}
/// Attempts to adjust the timer to a new timestamp.
///
/// If the timer has already been fired, is pending firing, or the new
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 68b02db1543880cb95ceccc39f453f8dd2223f04 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/68b02db1543880cb95ceccc39f453f8dd2223f04/tokio/src/runtime/time/entry.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:8 | }
}
/// A timer entry.
///
/// 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(crate) struct TimerEntry {
/// Arc reference to the runtime handle. We can only free the d... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 68b02db1543880cb95ceccc39f453f8dd2223f04 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/68b02db1543880cb95ceccc39f453f8dd2223f04/tokio/src/runtime/time/entry.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:9 | /// timer, to help minimize mistakes. Still, because TimerHandle cannot enforce
/// memory safety, all operations are unsafe.
#[derive(Debug)]
pub(crate) struct TimerHandle {
inner: NonNull<TimerShared>,
}
pub(super) type EntryList = crate::util::linked_list::LinkedList<TimerShared, TimerShared>;
/// The shared s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 68b02db1543880cb95ceccc39f453f8dd2223f04 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/68b02db1543880cb95ceccc39f453f8dd2223f04/tokio/src/runtime/time/entry.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:10 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("TimerShared")
.field("when", &self.true_when.load(Ordering::Relaxed))
.field("cached_when", &self.cached_when.load(Ordering::Relaxed))
.field("state", &self.state)
.finish()
}... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 68b02db1543880cb95ceccc39f453f8dd2223f04 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/68b02db1543880cb95ceccc39f453f8dd2223f04/tokio/src/runtime/time/entry.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:11 | let true_when = self.true_when();
self.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.
unsafe fn set_ca... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 68b02db1543880cb95ceccc39f453f8dd2223f04 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/68b02db1543880cb95ceccc39f453f8dd2223f04/tokio/src/runtime/time/entry.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:12 | }
/// Returns true if the state of this timer indicates that the timer might
/// be registered with the driver. This check is performed with relaxed
/// ordering, but is conservative - if it returns false, the timer is
/// definitely _not_ registered.
pub(super) fn might_be_registered(&self) -> boo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 68b02db1543880cb95ceccc39f453f8dd2223f04 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/68b02db1543880cb95ceccc39f453f8dd2223f04/tokio/src/runtime/time/entry.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:13 | Self {
driver,
inner: StdUnsafeCell::new(TimerShared::new()),
deadline,
registered: false,
_m: std::marker::PhantomPinned,
}
}
fn inner(&self) -> &TimerShared {
unsafe { &*self.inner.get() }
}
pub(crate) fn deadline(&self) -> ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 68b02db1543880cb95ceccc39f453f8dd2223f04 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/68b02db1543880cb95ceccc39f453f8dd2223f04/tokio/src/runtime/time/entry.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/time/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/runtime/time/entry.rs | MIT | 68b02db1543880cb95ceccc39f453f8dd2223f04 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/68b02db1543880cb95ceccc39f453f8dd2223f04/tokio/src/runtime/time/entry.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:15 | let this = unsafe { self.get_unchecked_mut() };
this.inner().state.poll(cx.waker())
}
pub(crate) fn driver(&self) -> &super::Handle {
self.driver.driver().time()
}
#[cfg(all(tokio_unstable, feature = "tracing"))]
pub(crate) fn clock(&self) -> &super::Clock {
self.driver.dr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 68b02db1543880cb95ceccc39f453f8dd2223f04 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/68b02db1543880cb95ceccc39f453f8dd2223f04/tokio/src/runtime/time/entry.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:16 | /// new expiration time.
///
/// SAFETY: The caller must ensure that the handle remains valid, the driver
/// lock is held, and that the timer is not in any wheel linked lists.
/// After returning Ok, the entry must be added to the pending list.
pub(super) unsafe fn mark_pending(&self, not_after: u6... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 68b02db1543880cb95ceccc39f453f8dd2223f04 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/68b02db1543880cb95ceccc39f453f8dd2223f04/tokio/src/runtime/time/entry.rs | 601 | 640 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:13 | Self {
driver,
inner: StdUnsafeCell::new(TimerShared::new()),
deadline,
registered: false,
_m: std::marker::PhantomPinned,
}
}
fn inner(&self) -> &TimerShared {
unsafe { &*self.inner.get() }
}
pub(crate) fn deadline(&self) -> ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 0dc1b71e6e53782ed2314935a70631b667686805 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc1b71e6e53782ed2314935a70631b667686805/tokio/src/runtime/time/entry.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/time/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/runtime/time/entry.rs | MIT | 0dc1b71e6e53782ed2314935a70631b667686805 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc1b71e6e53782ed2314935a70631b667686805/tokio/src/runtime/time/entry.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:15 | this.inner().state.poll(cx.waker())
}
pub(crate) fn driver(&self) -> &super::Handle {
self.driver.driver().time()
}
#[cfg(all(tokio_unstable, feature = "tracing"))]
pub(crate) fn clock(&self) -> &super::Clock {
self.driver.driver().clock()
}
}
impl TimerHandle {
pub(super)... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 0dc1b71e6e53782ed2314935a70631b667686805 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc1b71e6e53782ed2314935a70631b667686805/tokio/src/runtime/time/entry.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:16 | /// SAFETY: The caller must ensure that the handle remains valid, the driver
/// lock is held, and that the timer is not in any wheel linked lists.
/// After returning Ok, the entry must be added to the pending list.
pub(super) unsafe fn mark_pending(&self, not_after: u64) -> Result<(), u64> {
match... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | 0dc1b71e6e53782ed2314935a70631b667686805 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0dc1b71e6e53782ed2314935a70631b667686805/tokio/src/runtime/time/entry.rs | 601 | 638 |
tokio-rs/tokio:tokio/src/runtime/time/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/runtime/time/entry.rs | MIT | d96bbf04655bc7e40f87967996f0ae8976fe5aae | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d96bbf04655bc7e40f87967996f0ae8976fe5aae/tokio/src/runtime/time/entry.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:3 | /// 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
/// from the TimerEntry to the driver requires _both_ holding the &mut
/// TimerEntry... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | d96bbf04655bc7e40f87967996f0ae8976fe5aae | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d96bbf04655bc7e40f87967996f0ae8976fe5aae/tokio/src/runtime/time/entry.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:4 | fn is_pending(&self) -> bool {
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 {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | d96bbf04655bc7e40f87967996f0ae8976fe5aae | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d96bbf04655bc7e40f87967996f0ae8976fe5aae/tokio/src/runtime/time/entry.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:6 | /// Fires the timer, setting the result to the provided result.
///
/// Returns:
/// * `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:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | d96bbf04655bc7e40f87967996f0ae8976fe5aae | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d96bbf04655bc7e40f87967996f0ae8976fe5aae/tokio/src/runtime/time/entry.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:8 | }
}
/// A timer entry.
///
/// 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(crate) struct TimerEntry {
/// Arc reference to the runtime handle. We can only free the d... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | d96bbf04655bc7e40f87967996f0ae8976fe5aae | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d96bbf04655bc7e40f87967996f0ae8976fe5aae/tokio/src/runtime/time/entry.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:9 | /// timer, to help minimize mistakes. Still, because TimerHandle cannot enforce
/// memory safety, all operations are unsafe.
#[derive(Debug)]
pub(crate) struct TimerHandle {
inner: NonNull<TimerShared>,
}
pub(super) type EntryList = crate::util::linked_list::LinkedList<TimerShared, TimerShared>;
/// The shared s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | d96bbf04655bc7e40f87967996f0ae8976fe5aae | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d96bbf04655bc7e40f87967996f0ae8976fe5aae/tokio/src/runtime/time/entry.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:10 | _p: PhantomPinned,
}
}
/// Gets the cached time-of-expiration value.
pub(super) fn cached_when(&self) -> u64 {
// 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-ex... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | d96bbf04655bc7e40f87967996f0ae8976fe5aae | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d96bbf04655bc7e40f87967996f0ae8976fe5aae/tokio/src/runtime/time/entry.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:11 | }
/// Sets the true time-of-expiration value, even if it is less than the
/// current expiration or the timer is deregistered.
///
/// SAFETY: Must only be called with the driver lock held and the entry not
/// in the timer wheel.
pub(super) unsafe fn set_expiration(&self, t: u64) {
sel... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | d96bbf04655bc7e40f87967996f0ae8976fe5aae | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d96bbf04655bc7e40f87967996f0ae8976fe5aae/tokio/src/runtime/time/entry.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:12 | ///
/// Only accessed under the entry lock.
pointers: linked_list::Pointers<TimerShared>,
/// The expiration time for which this entry is currently registered.
/// Generally owned by the driver, but is accessed by the entry when not
/// registered.
cached_when: AtomicU64,
/// The true expi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | d96bbf04655bc7e40f87967996f0ae8976fe5aae | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d96bbf04655bc7e40f87967996f0ae8976fe5aae/tokio/src/runtime/time/entry.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:13 | fn as_raw(handle: &Self::Handle) -> NonNull<Self::Target> {
handle.inner
}
unsafe fn from_raw(ptr: NonNull<Self::Target>) -> Self::Handle {
TimerHandle { inner: ptr }
}
unsafe fn pointers(
target: NonNull<Self::Target>,
) -> NonNull<linked_list::Pointers<Self::Target>> {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | d96bbf04655bc7e40f87967996f0ae8976fe5aae | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d96bbf04655bc7e40f87967996f0ae8976fe5aae/tokio/src/runtime/time/entry.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:14 | }
pub(crate) fn is_elapsed(&self) -> bool {
!self.inner().state.might_be_registered() && self.registered
}
/// Cancels and deregisters the timer. This operation is irreversible.
pub(crate) fn cancel(self: Pin<&mut Self>) {
// We need to perform an acq/rel fence with the driver thread, ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | d96bbf04655bc7e40f87967996f0ae8976fe5aae | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d96bbf04655bc7e40f87967996f0ae8976fe5aae/tokio/src/runtime/time/entry.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:15 | return;
}
unsafe {
self.driver()
.reregister(&self.driver.driver().io, tick, self.inner().into());
}
}
pub(crate) fn poll_elapsed(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), super::Error>> {
if self.drive... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | d96bbf04655bc7e40f87967996f0ae8976fe5aae | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d96bbf04655bc7e40f87967996f0ae8976fe5aae/tokio/src/runtime/time/entry.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:16 | }
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_pending() }
}
/// Forcibly sets the true and cached expiration times to the given tick.
///
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/time/entry.rs | MIT | d96bbf04655bc7e40f87967996f0ae8976fe5aae | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d96bbf04655bc7e40f87967996f0ae8976fe5aae/tokio/src/runtime/time/entry.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/time/entry.rs:17 | /// 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/runtime/time/entry.rs | MIT | d96bbf04655bc7e40f87967996f0ae8976fe5aae | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d96bbf04655bc7e40f87967996f0ae8976fe5aae/tokio/src/runtime/time/entry.rs | 641 | 700 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.