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/context.rs:1 | use crate::loom::thread::AccessError;
use crate::task::coop;
use std::cell::Cell;
#[cfg(any(feature = "rt", feature = "macros", feature = "time"))]
use crate::util::rand::FastRand;
cfg_rt! {
mod blocking;
pub(crate) use blocking::{disallow_block_in_place, try_enter_blocking_region, BlockingRegionGuard};
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 605ef578df04f12a951060dc3b2fb930f6f379fe | github | async-runtime | https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | /// Handle to the runtime scheduler running on the current thread.
#[cfg(feature = "rt")]
current: current::HandleCell,
/// Handle to the scheduler's internal "context"
#[cfg(feature = "rt")]
scheduler: Scoped<scheduler::Context>,
#[cfg(feature = "rt")]
current_task_id: Cell<Option<Id>>,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 605ef578df04f12a951060dc3b2fb930f6f379fe | github | async-runtime | https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | thread_id: Cell::new(None),
// Tracks the current runtime handle to use when spawning,
// accessing drivers, etc...
#[cfg(feature = "rt")]
current: current::HandleCell::new(),
// Tracks the current scheduler internal context
#[cfg(feature = "rt")... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 605ef578df04f12a951060dc3b2fb930f6f379fe | github | async-runtime | https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/runtime/context.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/context.rs:4 | }
}
#[cfg(any(
feature = "time",
feature = "macros",
all(feature = "sync", feature = "rt")
))]
pub(crate) fn thread_rng_n(n: u32) -> u32 {
CONTEXT.with(|ctx| {
let mut rng = ctx.rng.get().unwrap_or_else(FastRand::new);
let ret = rng.fastrand_n(n);
ctx.rng.set(Some(rng));
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 605ef578df04f12a951060dc3b2fb930f6f379fe | github | async-runtime | https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/runtime/context.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/context.rs:5 | pub(crate) fn current_task_id() -> Option<Id> {
CONTEXT.try_with(|ctx| ctx.current_task_id.get()).unwrap_or(None)
}
#[track_caller]
pub(crate) fn defer(waker: &Waker) {
with_scheduler(|maybe_scheduler| {
if let Some(scheduler) = maybe_scheduler {
scheduler.defer(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 605ef578df04f12a951060dc3b2fb930f6f379fe | github | async-runtime | https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/runtime/context.rs | 161 | 204 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | use crate::loom::thread::AccessError;
use crate::runtime::coop;
use std::cell::Cell;
#[cfg(any(feature = "rt", feature = "macros", feature = "time"))]
use crate::util::rand::FastRand;
cfg_rt! {
mod blocking;
pub(crate) use blocking::{disallow_block_in_place, try_enter_blocking_region, BlockingRegionGuard};
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | f8948ea021bd4b5626bbd8dee89bee51ba766326 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f8948ea021bd4b5626bbd8dee89bee51ba766326/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | thread_id: Cell::new(None),
// Tracks the current runtime handle to use when spawning,
// accessing drivers, etc...
#[cfg(feature = "rt")]
current: current::HandleCell::new(),
// Tracks the current scheduler internal context
#[cfg(feature = "rt")... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | f8948ea021bd4b5626bbd8dee89bee51ba766326 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f8948ea021bd4b5626bbd8dee89bee51ba766326/tokio/src/runtime/context.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/context.rs:4 | }
}
#[cfg(any(
feature = "time",
feature = "macros",
all(feature = "sync", feature = "rt")
))]
pub(crate) fn thread_rng_n(n: u32) -> u32 {
CONTEXT.with(|ctx| {
let mut rng = ctx.rng.get().unwrap_or_else(FastRand::new);
let ret = rng.fastrand_n(n);
ctx.rng.set(Some(rng));
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | f8948ea021bd4b5626bbd8dee89bee51ba766326 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f8948ea021bd4b5626bbd8dee89bee51ba766326/tokio/src/runtime/context.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/context.rs:5 | pub(crate) fn current_task_id() -> Option<Id> {
CONTEXT.try_with(|ctx| ctx.current_task_id.get()).unwrap_or(None)
}
#[track_caller]
pub(crate) fn defer(waker: &Waker) {
with_scheduler(|maybe_scheduler| {
if let Some(scheduler) = maybe_scheduler {
scheduler.defer(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 1914e1e4b9bfe6ea2d61970ec3fcf2b5d7bb0210 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1914e1e4b9bfe6ea2d61970ec3fcf2b5d7bb0210/tokio/src/runtime/context.rs | 161 | 197 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | use crate::loom::thread::AccessError;
use crate::runtime::coop;
use std::cell::Cell;
#[cfg(any(feature = "rt", feature = "macros"))]
use crate::util::rand::FastRand;
cfg_rt! {
mod blocking;
pub(crate) use blocking::{disallow_block_in_place, try_enter_blocking_region, BlockingRegionGuard};
mod current;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | thread_id: Cell::new(None),
// Tracks the current runtime handle to use when spawning,
// accessing drivers, etc...
#[cfg(feature = "rt")]
current: current::HandleCell::new(),
// Tracks the current scheduler internal context
#[cfg(feature = "rt")... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/context.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/context.rs:4 | }
}
#[cfg(any(feature = "macros", all(feature = "sync", feature = "rt")))]
pub(crate) fn thread_rng_n(n: u32) -> u32 {
CONTEXT.with(|ctx| {
let mut rng = ctx.rng.get().unwrap_or_else(FastRand::new);
let ret = rng.fastrand_n(n);
ctx.rng.set(Some(rng));
ret
})
}
pub(super) fn bud... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/context.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/context.rs:5 | #[track_caller]
pub(crate) fn defer(waker: &Waker) {
with_scheduler(|maybe_scheduler| {
if let Some(scheduler) = maybe_scheduler {
scheduler.defer(waker);
} else {
// Called from outside of the runtime, immediately wake the
// task.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/context.rs | 161 | 193 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | use crate::loom::thread::AccessError;
use crate::runtime::coop;
use std::cell::Cell;
#[cfg(any(feature = "rt", feature = "macros"))]
use crate::util::rand::{FastRand, RngSeed};
cfg_rt! {
use crate::runtime::{scheduler, task::Id, Defer};
use std::cell::RefCell;
use std::marker::PhantomData;
use std::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | ab7313ff6b9107c8b9c6a068c620ac56935b80e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ab7313ff6b9107c8b9c6a068c620ac56935b80e7/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | #[cfg(any(feature = "rt", feature = "macros"))]
rng: FastRand,
/// Tracks the amount of "work" a task may still do before yielding back to
/// the sheduler
budget: Cell<coop::Budget>,
}
tokio_thread_local! {
static CONTEXT: Context = {
Context {
#[cfg(feature = "rt")]
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | ab7313ff6b9107c8b9c6a068c620ac56935b80e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ab7313ff6b9107c8b9c6a068c620ac56935b80e7/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | #[cfg(feature = "macros")]
pub(crate) fn thread_rng_n(n: u32) -> u32 {
CONTEXT.with(|ctx| ctx.rng.fastrand_n(n))
}
pub(super) fn budget<R>(f: impl FnOnce(&Cell<coop::Budget>) -> R) -> Result<R, AccessError> {
CONTEXT.try_with(|ctx| f(&ctx.budget))
}
cfg_rt! {
use crate::runtime::{ThreadId, TryCurrentError... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | ab7313ff6b9107c8b9c6a068c620ac56935b80e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ab7313ff6b9107c8b9c6a068c620ac56935b80e7/tokio/src/runtime/context.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/context.rs:4 | #[must_use]
pub(crate) struct SetCurrentGuard {
old_handle: Option<scheduler::Handle>,
old_seed: RngSeed,
}
/// Guard tracking that a caller has entered a runtime context.
#[must_use]
pub(crate) struct EnterRuntimeGuard {
/// Tracks that the current thread has entered a bloc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | ab7313ff6b9107c8b9c6a068c620ac56935b80e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ab7313ff6b9107c8b9c6a068c620ac56935b80e7/tokio/src/runtime/context.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/context.rs:5 | Ok(Some(handle)) => Ok(handle),
Ok(None) => Err(TryCurrentError::new_no_context()),
Err(_access_error) => Err(TryCurrentError::new_thread_local_destroyed()),
}
}
/// Sets this [`Handle`] as the current active [`Handle`].
///
/// [`Handle`]: crate::runtime::scheduler::Han... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | ab7313ff6b9107c8b9c6a068c620ac56935b80e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ab7313ff6b9107c8b9c6a068c620ac56935b80e7/tokio/src/runtime/context.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/context.rs:6 | // Initialize queue to track yielded tasks
let mut defer = c.defer.borrow_mut();
let is_root = if defer.is_none() {
*defer = Some(Defer::new());
true
} else {
false
};
Some(Enter... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | ab7313ff6b9107c8b9c6a068c620ac56935b80e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ab7313ff6b9107c8b9c6a068c620ac56935b80e7/tokio/src/runtime/context.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/context.rs:7 | c.runtime.set(EnterRuntime::Entered {
allow_block_in_place: false,
});
true
} else {
false
}
});
DisallowBlockInPlaceGuard(reset)
}
pub(crate) fn with_defer<R>(f: impl FnOnce(&mut Defer) -> R) -> Option... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | ab7313ff6b9107c8b9c6a068c620ac56935b80e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ab7313ff6b9107c8b9c6a068c620ac56935b80e7/tokio/src/runtime/context.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/context.rs:8 | }
impl fmt::Debug for EnterRuntimeGuard {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Enter").finish()
}
}
impl Drop for EnterRuntimeGuard {
fn drop(&mut self) {
CONTEXT.with(|c| {
assert!(c.runtime.get().is_ent... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | ab7313ff6b9107c8b9c6a068c620ac56935b80e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ab7313ff6b9107c8b9c6a068c620ac56935b80e7/tokio/src/runtime/context.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/context.rs:9 | /// `timeout` elapses, then `Err` is returned.
pub(crate) fn block_on_timeout<F>(&mut self, f: F, timeout: Duration) -> Result<F::Output, ()>
where
F: std::future::Future,
{
use crate::runtime::park::CachedParkThread;
use std::task::Context;
use st... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | ab7313ff6b9107c8b9c6a068c620ac56935b80e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ab7313ff6b9107c8b9c6a068c620ac56935b80e7/tokio/src/runtime/context.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/context.rs:10 | // XXX: Do we want some kind of assertion here, or is "best effort" okay?
CONTEXT.with(|c| {
if let EnterRuntime::Entered {
allow_block_in_place: false,
} = c.runtime.get()
{
c.runtime.set(EnterRu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | ab7313ff6b9107c8b9c6a068c620ac56935b80e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ab7313ff6b9107c8b9c6a068c620ac56935b80e7/tokio/src/runtime/context.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/context.rs:11 | fn drop(&mut self) {
CONTEXT.with(|c| {
assert!(!c.runtime.get().is_entered(), "closure claimed permanent executor");
c.runtime.set(self.0);
});
}
}
let was = CONTEXT.with(|c| {
let e = c.runtime.get();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | ab7313ff6b9107c8b9c6a068c620ac56935b80e7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ab7313ff6b9107c8b9c6a068c620ac56935b80e7/tokio/src/runtime/context.rs | 401 | 420 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | /// Handle to the runtime scheduler running on the current thread.
#[cfg(feature = "rt")]
current: current::HandleCell,
/// Handle to the scheduler's internal "context"
#[cfg(feature = "rt")]
scheduler: Scoped<scheduler::Context>,
#[cfg(feature = "rt")]
current_task_id: Cell<Option<Id>>,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 2e5773a6fef7444e8959a992c7ed7d32f97af284 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2e5773a6fef7444e8959a992c7ed7d32f97af284/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:5 | #[track_caller]
pub(crate) fn defer(waker: &Waker) {
with_scheduler(|maybe_scheduler| {
if let Some(scheduler) = maybe_scheduler {
scheduler.defer(waker);
} else {
// Called from outside of the runtime, immediately wake the
// task.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 6b010ac80f408960aec5b5ace36c94e9a76b9600 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6b010ac80f408960aec5b5ace36c94e9a76b9600/tokio/src/runtime/context.rs | 161 | 191 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | /// Handle to the runtime scheduler running on the current thread.
#[cfg(feature = "rt")]
current: current::HandleCell,
/// Handle to the scheduler's internal "context"
#[cfg(feature = "rt")]
scheduler: Scoped<scheduler::Context>,
#[cfg(feature = "rt")]
current_task_id: Cell<Option<Id>>,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | cbb3c155dd416f6e6a26be5e3b2ebc02853e4b62 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cbb3c155dd416f6e6a26be5e3b2ebc02853e4b62/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | thread_id: Cell::new(None),
/// Tracks the current runtime handle to use when spawning,
/// accessing drivers, etc...
#[cfg(feature = "rt")]
current: current::HandleCell::new(),
/// Tracks the current scheduler internal context
#[cfg(feature = "r... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | cbb3c155dd416f6e6a26be5e3b2ebc02853e4b62 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cbb3c155dd416f6e6a26be5e3b2ebc02853e4b62/tokio/src/runtime/context.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | use crate::loom::thread::AccessError;
use crate::runtime::coop;
use std::cell::Cell;
#[cfg(any(feature = "rt", feature = "macros"))]
use crate::util::rand::FastRand;
cfg_rt! {
mod blocking;
pub(crate) use blocking::{disallow_block_in_place, try_enter_blocking_region, BlockingRegionGuard};
mod current;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 1204da730000f2eab19d2c05eea12ee3071b3f31 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1204da730000f2eab19d2c05eea12ee3071b3f31/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | /// Handle to the runtime scheduler running on the current thread.
#[cfg(feature = "rt")]
handle: RefCell<Option<scheduler::Handle>>,
/// Handle to the scheduler's internal "context"
#[cfg(feature = "rt")]
scheduler: Scoped<scheduler::Context>,
#[cfg(feature = "rt")]
current_task_id: Cell<... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 1204da730000f2eab19d2c05eea12ee3071b3f31 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1204da730000f2eab19d2c05eea12ee3071b3f31/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | #[cfg(feature = "rt")]
thread_id: Cell::new(None),
/// Tracks the current runtime handle to use when spawning,
/// accessing drivers, etc...
#[cfg(feature = "rt")]
handle: RefCell::new(None),
/// Tracks the current scheduler internal context
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 1204da730000f2eab19d2c05eea12ee3071b3f31 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1204da730000f2eab19d2c05eea12ee3071b3f31/tokio/src/runtime/context.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/context.rs:4 | }
}
}
#[cfg(any(feature = "macros", all(feature = "sync", feature = "rt")))]
pub(crate) fn thread_rng_n(n: u32) -> u32 {
CONTEXT.with(|ctx| {
let mut rng = ctx.rng.get().unwrap_or_else(FastRand::new);
let ret = rng.fastrand_n(n);
ctx.rng.set(Some(rng));
ret
})
}
pub(super) ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 1204da730000f2eab19d2c05eea12ee3071b3f31 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1204da730000f2eab19d2c05eea12ee3071b3f31/tokio/src/runtime/context.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/context.rs:5 | }
#[track_caller]
pub(crate) fn defer(waker: &Waker) {
with_scheduler(|maybe_scheduler| {
if let Some(scheduler) = maybe_scheduler {
scheduler.defer(waker);
} else {
// Called from outside of the runtime, immediately wake the
// ta... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 1204da730000f2eab19d2c05eea12ee3071b3f31 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1204da730000f2eab19d2c05eea12ee3071b3f31/tokio/src/runtime/context.rs | 161 | 192 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | use crate::loom::thread::AccessError;
use crate::runtime::coop;
use std::cell::Cell;
#[cfg(any(feature = "rt", feature = "macros"))]
use crate::util::rand::FastRand;
cfg_rt! {
mod scoped;
use scoped::Scoped;
use crate::runtime::{scheduler, task::Id};
use std::cell::RefCell;
use std::marker::Pha... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | /// Tracks if the current thread is currently driving a runtime.
/// Note, that if this is set to "entered", the current scheduler
/// handle may not reference the runtime currently executing. This
/// is because other runtime handles may be set to current from
/// within a runtime.
#[cfg(feature = ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | #[cfg(feature = "rt")]
current_task_id: Cell::new(None),
/// Tracks if the current thread is currently driving a runtime.
/// Note, that if this is set to "entered", the current scheduler
/// handle may not reference the runtime currently executing. This
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78/tokio/src/runtime/context.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/context.rs:4 | }
pub(super) fn budget<R>(f: impl FnOnce(&Cell<coop::Budget>) -> R) -> Result<R, AccessError> {
CONTEXT.try_with(|ctx| f(&ctx.budget))
}
cfg_rt! {
use crate::runtime::{ThreadId, TryCurrentError};
use crate::util::rand::RngSeed;
use std::fmt;
pub(crate) fn thread_id() -> Result<ThreadId, AccessEr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78/tokio/src/runtime/context.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/context.rs:5 | old_seed: RngSeed,
// Should not be `Send` since it must be *dropped* on the same thread as
// created, but there is no issue with sync access.
_p: PhantomData<crate::util::markers::SyncNotSend>,
}
/// Guard tracking that a caller has entered a runtime context.
#[must_use]
pub(c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78/tokio/src/runtime/context.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/context.rs:6 | Err(_access_error) => Err(TryCurrentError::new_thread_local_destroyed()),
}
}
/// Sets this [`Handle`] as the current active [`Handle`].
///
/// [`Handle`]: crate::runtime::scheduler::Handle
pub(crate) fn try_set_current(handle: &scheduler::Handle) -> Option<SetCurrentGuard> {
CONTE... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78/tokio/src/runtime/context.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/context.rs:7 | handle: c.set_current(handle),
})
}
})
}
pub(crate) fn try_enter_blocking_region() -> Option<BlockingRegionGuard> {
CONTEXT.try_with(|c| {
if c.runtime.get().is_entered() {
None
} else {
Some(BlockingRegionGuard... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78/tokio/src/runtime/context.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/context.rs:8 | pub(crate) fn defer(waker: &Waker) {
with_scheduler(|maybe_scheduler| {
if let Some(scheduler) = maybe_scheduler {
scheduler.defer(waker);
} else {
// Called from outside of the runtime, immediately wake the
// task.
waker.w... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78/tokio/src/runtime/context.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/context.rs:9 | CONTEXT.with(|ctx| {
*ctx.handle.borrow_mut() = self.old_handle.take();
let mut rng = ctx.rng.get().unwrap_or_else(FastRand::new);
rng.replace_seed(self.old_seed.clone());
ctx.rng.set(Some(rng));
});
}
}
impl fmt::Debug for En... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78/tokio/src/runtime/context.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/context.rs:10 | }
/// Blocks the thread on the specified future for **at most** `timeout`
///
/// If the future completes before `timeout`, the result is returned. If
/// `timeout` elapses, then `Err` is returned.
pub(crate) fn block_on_timeout<F>(&mut self, f: F, timeout: Duration) -> Result<F... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78/tokio/src/runtime/context.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/context.rs:11 | if self.0 {
// XXX: Do we want some kind of assertion here, or is "best effort" okay?
CONTEXT.with(|c| {
if let EnterRuntime::Entered {
allow_block_in_place: false,
} = c.runtime.get()
{
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78/tokio/src/runtime/context.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/context.rs:12 | pub(crate) fn current_enter_context() -> EnterRuntime {
CONTEXT.with(|c| c.runtime.get())
}
pub(crate) fn exit_runtime<F: FnOnce() -> R, R>(f: F) -> R {
// Reset in case the closure panics
struct Reset(EnterRuntime);
impl Drop for Reset {
fn drop(&mut self) {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e75ca93d30e6d2f7a165882d46d8b55fa3e8cb78/tokio/src/runtime/context.rs | 441 | 469 |
tokio-rs/tokio:tokio/src/runtime/context.rs:4 | }
pub(super) fn budget<R>(f: impl FnOnce(&Cell<coop::Budget>) -> R) -> Result<R, AccessError> {
CONTEXT.try_with(|ctx| f(&ctx.budget))
}
cfg_rt! {
use crate::runtime::{ThreadId, TryCurrentError};
use crate::util::rand::RngSeed;
use std::fmt;
pub(crate) fn thread_id() -> Result<ThreadId, AccessEr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 8f0103f6c5fd300fee15888fc15ec9dd86248690 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8f0103f6c5fd300fee15888fc15ec9dd86248690/tokio/src/runtime/context.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/context.rs:5 | old_seed: RngSeed,
}
/// Guard tracking that a caller has entered a runtime context.
#[must_use]
pub(crate) struct EnterRuntimeGuard {
/// Tracks that the current thread has entered a blocking function call.
pub(crate) blocking: BlockingRegionGuard,
#[allow(dead_code)] // Only ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 8f0103f6c5fd300fee15888fc15ec9dd86248690 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8f0103f6c5fd300fee15888fc15ec9dd86248690/tokio/src/runtime/context.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/context.rs:6 | /// Sets this [`Handle`] as the current active [`Handle`].
///
/// [`Handle`]: crate::runtime::scheduler::Handle
pub(crate) fn try_set_current(handle: &scheduler::Handle) -> Option<SetCurrentGuard> {
CONTEXT.try_with(|ctx| ctx.set_current(handle)).ok()
}
/// Marks the current thread as bei... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 8f0103f6c5fd300fee15888fc15ec9dd86248690 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8f0103f6c5fd300fee15888fc15ec9dd86248690/tokio/src/runtime/context.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/context.rs:7 | })
}
pub(crate) fn try_enter_blocking_region() -> Option<BlockingRegionGuard> {
CONTEXT.try_with(|c| {
if c.runtime.get().is_entered() {
None
} else {
Some(BlockingRegionGuard::new())
}
// If accessing the thread-local fail... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 8f0103f6c5fd300fee15888fc15ec9dd86248690 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8f0103f6c5fd300fee15888fc15ec9dd86248690/tokio/src/runtime/context.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/context.rs:8 | scheduler.defer(waker);
} else {
// Called from outside of the runtime, immediately wake the
// task.
waker.wake_by_ref();
}
});
}
pub(super) fn set_scheduler<R>(v: &scheduler::Context, f: impl FnOnce() -> R) -> R {
CONTEXT... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 8f0103f6c5fd300fee15888fc15ec9dd86248690 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8f0103f6c5fd300fee15888fc15ec9dd86248690/tokio/src/runtime/context.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/context.rs:9 | rng.replace_seed(self.old_seed.clone());
ctx.rng.set(Some(rng));
});
}
}
impl fmt::Debug for EnterRuntimeGuard {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Enter").finish()
}
}
impl Drop for EnterRuntimeGua... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 8f0103f6c5fd300fee15888fc15ec9dd86248690 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8f0103f6c5fd300fee15888fc15ec9dd86248690/tokio/src/runtime/context.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/context.rs:10 | /// If the future completes before `timeout`, the result is returned. If
/// `timeout` elapses, then `Err` is returned.
pub(crate) fn block_on_timeout<F>(&mut self, f: F, timeout: Duration) -> Result<F::Output, ()>
where
F: std::future::Future,
{
use crate::runtim... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 8f0103f6c5fd300fee15888fc15ec9dd86248690 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8f0103f6c5fd300fee15888fc15ec9dd86248690/tokio/src/runtime/context.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/context.rs:11 | allow_block_in_place: false,
} = c.runtime.get()
{
c.runtime.set(EnterRuntime::Entered {
allow_block_in_place: true,
});
}
})
}
}
}
impl En... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 8f0103f6c5fd300fee15888fc15ec9dd86248690 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8f0103f6c5fd300fee15888fc15ec9dd86248690/tokio/src/runtime/context.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/context.rs:12 | pub(crate) fn exit_runtime<F: FnOnce() -> R, R>(f: F) -> R {
// Reset in case the closure panics
struct Reset(EnterRuntime);
impl Drop for Reset {
fn drop(&mut self) {
CONTEXT.with(|c| {
assert!(!c.runtime.get().is_entered(), "closure claimed perm... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 8f0103f6c5fd300fee15888fc15ec9dd86248690 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8f0103f6c5fd300fee15888fc15ec9dd86248690/tokio/src/runtime/context.rs | 441 | 465 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | use crate::loom::thread::AccessError;
use crate::runtime::coop;
use std::cell::Cell;
#[cfg(any(feature = "rt", feature = "macros"))]
use crate::util::rand::{FastRand, RngSeed};
cfg_rt! {
mod scoped;
use scoped::Scoped;
use crate::runtime::{scheduler, task::Id};
use std::cell::RefCell;
use std::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | c748f4965eae883a2291945116d84cab5d657100 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c748f4965eae883a2291945116d84cab5d657100/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | /// Tracks if the current thread is currently driving a runtime.
/// Note, that if this is set to "entered", the current scheduler
/// handle may not reference the runtime currently executing. This
/// is because other runtime handles may be set to current from
/// within a runtime.
#[cfg(feature = ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | c748f4965eae883a2291945116d84cab5d657100 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c748f4965eae883a2291945116d84cab5d657100/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | #[cfg(feature = "rt")]
current_task_id: Cell::new(None),
/// Tracks if the current thread is currently driving a runtime.
/// Note, that if this is set to "entered", the current scheduler
/// handle may not reference the runtime currently executing. This
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | c748f4965eae883a2291945116d84cab5d657100 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c748f4965eae883a2291945116d84cab5d657100/tokio/src/runtime/context.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/context.rs:4 | cfg_rt! {
use crate::runtime::{ThreadId, TryCurrentError};
use std::fmt;
pub(crate) fn thread_id() -> Result<ThreadId, AccessError> {
CONTEXT.try_with(|ctx| {
match ctx.thread_id.get() {
Some(id) => id,
None => {
let id = ThreadId::ne... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | c748f4965eae883a2291945116d84cab5d657100 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c748f4965eae883a2291945116d84cab5d657100/tokio/src/runtime/context.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/context.rs:5 | /// Tracks that the current thread has entered a blocking function call.
pub(crate) blocking: BlockingRegionGuard,
#[allow(dead_code)] // Only tracking the guard.
pub(crate) handle: SetCurrentGuard,
}
/// Guard tracking that a caller has entered a blocking region.
#[must_use]
p... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | c748f4965eae883a2291945116d84cab5d657100 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c748f4965eae883a2291945116d84cab5d657100/tokio/src/runtime/context.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/context.rs:6 | }
/// Marks the current thread as being within the dynamic extent of an
/// executor.
#[track_caller]
pub(crate) fn enter_runtime(handle: &scheduler::Handle, allow_block_in_place: bool) -> EnterRuntimeGuard {
if let Some(enter) = try_enter_runtime(handle, allow_block_in_place) {
re... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | c748f4965eae883a2291945116d84cab5d657100 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c748f4965eae883a2291945116d84cab5d657100/tokio/src/runtime/context.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/context.rs:7 | None
} else {
Some(BlockingRegionGuard::new())
}
// If accessing the thread-local fails, the thread is terminating
// and thread-locals are being destroyed. Because we don't know if
// we are currently in a runtime or not, we default to being
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | c748f4965eae883a2291945116d84cab5d657100 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c748f4965eae883a2291945116d84cab5d657100/tokio/src/runtime/context.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/context.rs:8 | });
}
pub(super) fn set_scheduler<R>(v: &scheduler::Context, f: impl FnOnce() -> R) -> R {
CONTEXT.with(|c| c.scheduler.set(v, f))
}
#[track_caller]
pub(super) fn with_scheduler<R>(f: impl FnOnce(Option<&scheduler::Context>) -> R) -> R {
CONTEXT.with(|c| c.scheduler.with(f))
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | c748f4965eae883a2291945116d84cab5d657100 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c748f4965eae883a2291945116d84cab5d657100/tokio/src/runtime/context.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/context.rs:9 | impl Drop for EnterRuntimeGuard {
fn drop(&mut self) {
CONTEXT.with(|c| {
assert!(c.runtime.get().is_entered());
c.runtime.set(EnterRuntime::NotEntered);
});
}
}
impl BlockingRegionGuard {
fn new() -> BlockingRegionGuard {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | c748f4965eae883a2291945116d84cab5d657100 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c748f4965eae883a2291945116d84cab5d657100/tokio/src/runtime/context.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/context.rs:10 | let mut park = CachedParkThread::new();
let waker = park.waker().map_err(|_| ())?;
let mut cx = Context::from_waker(&waker);
pin!(f);
let when = Instant::now() + timeout;
loop {
if let Ready(v) = crate::runtime::coop::budget(|| f.as_mut().pol... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | c748f4965eae883a2291945116d84cab5d657100 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c748f4965eae883a2291945116d84cab5d657100/tokio/src/runtime/context.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/context.rs:11 | impl EnterRuntime {
pub(crate) fn is_entered(self) -> bool {
matches!(self, EnterRuntime::Entered { .. })
}
}
cfg_taskdump! {
/// SAFETY: Callers of this function must ensure that trace frames always
/// form a valid linked list.
pub(crate) unsafe fn with_tra... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | c748f4965eae883a2291945116d84cab5d657100 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c748f4965eae883a2291945116d84cab5d657100/tokio/src/runtime/context.rs | 401 | 454 |
tokio-rs/tokio:tokio/src/runtime/context.rs:12 | }
let was = CONTEXT.with(|c| {
let e = c.runtime.get();
assert!(e.is_entered(), "asked to exit when not entered");
c.runtime.set(EnterRuntime::NotEntered);
e
});
let _reset = Reset(was);
// dropping _reset after f() will reset ENTERED
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | c748f4965eae883a2291945116d84cab5d657100 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c748f4965eae883a2291945116d84cab5d657100/tokio/src/runtime/context.rs | 441 | 454 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | use crate::loom::thread::AccessError;
use crate::runtime::coop;
use std::cell::Cell;
#[cfg(any(feature = "rt", feature = "macros"))]
use crate::util::rand::{FastRand, RngSeed};
cfg_rt! {
mod scoped;
use scoped::Scoped;
use crate::runtime::{scheduler, task::Id, Defer};
use std::cell::RefCell;
us... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | /// Note, that if this is set to "entered", the current scheduler
/// handle may not reference the runtime currently executing. This
/// is because other runtime handles may be set to current from
/// within a runtime.
#[cfg(feature = "rt")]
runtime: Cell<EnterRuntime>,
/// Yielded task wakers ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | /// Tracks the current scheduler internal context
#[cfg(feature = "rt")]
scheduler: Scoped::new(),
#[cfg(feature = "rt")]
current_task_id: Cell::new(None),
/// Tracks if the current thread is currently driving a runtime.
/// Note, that if this is... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/runtime/context.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/context.rs:4 | pub(crate) fn thread_rng_n(n: u32) -> u32 {
CONTEXT.with(|ctx| ctx.rng.fastrand_n(n))
}
pub(super) fn budget<R>(f: impl FnOnce(&Cell<coop::Budget>) -> R) -> Result<R, AccessError> {
CONTEXT.try_with(|ctx| f(&ctx.budget))
}
cfg_rt! {
use crate::runtime::{ThreadId, TryCurrentError};
use std::fmt;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/runtime/context.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/context.rs:5 | old_handle: Option<scheduler::Handle>,
old_seed: RngSeed,
}
/// Guard tracking that a caller has entered a runtime context.
#[must_use]
pub(crate) struct EnterRuntimeGuard {
/// Tracks that the current thread has entered a blocking function call.
pub(crate) blocking: BlockingReg... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/runtime/context.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/context.rs:6 | match CONTEXT.try_with(|ctx| ctx.handle.borrow().as_ref().map(f)) {
Ok(Some(ret)) => Ok(ret),
Ok(None) => Err(TryCurrentError::new_no_context()),
Err(_access_error) => Err(TryCurrentError::new_thread_local_destroyed()),
}
}
/// Sets this [`Handle`] as the current act... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/runtime/context.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/context.rs:7 | c.runtime.set(EnterRuntime::Entered { allow_block_in_place });
// Initialize queue to track yielded tasks
let mut defer = c.defer.borrow_mut();
let is_root = if defer.is_none() {
*defer = Some(Defer::new());
true
}... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/runtime/context.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/context.rs:8 | } = c.runtime.get()
{
c.runtime.set(EnterRuntime::Entered {
allow_block_in_place: false,
});
true
} else {
false
}
});
DisallowBlockInPlaceGuard(reset)
}
pub(crate) fn with_d... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/runtime/context.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/context.rs:9 | }
}
}
impl Drop for SetCurrentGuard {
fn drop(&mut self) {
CONTEXT.with(|ctx| {
*ctx.handle.borrow_mut() = self.old_handle.take();
ctx.rng.replace_seed(self.old_seed.clone());
});
}
}
impl fmt::Debug for EnterRuntimeGuard ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/runtime/context.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/context.rs:10 | F: std::future::Future,
{
use crate::runtime::park::CachedParkThread;
let mut park = CachedParkThread::new();
park.block_on(f)
}
/// Blocks the thread on the specified future for **at most** `timeout`
///
/// If the future completes before `t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/runtime/context.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/context.rs:11 | // blocking.
with_defer(|defer| defer.wake());
park.park_timeout(when - now);
}
}
}
impl Drop for DisallowBlockInPlaceGuard {
fn drop(&mut self) {
if self.0 {
// XXX: Do we want some kind of assertion here, or is "best eff... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/runtime/context.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/context.rs:12 | // Forces the current "entered" state to be cleared while the closure
// is executed.
//
// # Warning
//
// This is hidden for a reason. Do not use without fully understanding
// executors. Misusing can easily cause your program to deadlock.
cfg_rt_multi_thread! {
/// Returns true if in a runtime context.
pub(c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 7a99f87df203d589d9a8ad042a64b105a954f9fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7a99f87df203d589d9a8ad042a64b105a954f9fb/tokio/src/runtime/context.rs | 441 | 479 |
tokio-rs/tokio:tokio/src/runtime/context.rs:11 | // blocking.
with_defer(|defer| defer.wake());
park.park_timeout(when - now);
}
}
}
impl Drop for DisallowBlockInPlaceGuard {
fn drop(&mut self) {
if self.0 {
// XXX: Do we want some kind of assertion here, or is "best eff... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 9f9db7da6340a76938427425c57fe781276d4299 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9f9db7da6340a76938427425c57fe781276d4299/tokio/src/runtime/context.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | use crate::loom::thread::AccessError;
use crate::runtime::coop;
use std::cell::Cell;
#[cfg(any(feature = "rt", feature = "macros"))]
use crate::util::rand::{FastRand, RngSeed};
cfg_rt! {
use crate::runtime::{scheduler, task::Id, Defer};
use std::cell::RefCell;
use std::marker::PhantomData;
use std::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d274ef3748b82d7d7eccc39a8482586a4d8a5cc1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d274ef3748b82d7d7eccc39a8482586a4d8a5cc1/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | /// Yielded task wakers are stored here and notified after resource drivers
/// are polled.
#[cfg(feature = "rt")]
defer: RefCell<Option<Defer>>,
#[cfg(any(feature = "rt", feature = "macros"))]
rng: FastRand,
/// Tracks the amount of "work" a task may still do before yielding back to
/// t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d274ef3748b82d7d7eccc39a8482586a4d8a5cc1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d274ef3748b82d7d7eccc39a8482586a4d8a5cc1/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | #[cfg(feature = "rt")]
runtime: Cell::new(EnterRuntime::NotEntered),
#[cfg(feature = "rt")]
defer: RefCell::new(None),
#[cfg(any(feature = "rt", feature = "macros"))]
rng: FastRand::new(RngSeed::new()),
budget: Cell::new(coop::Budget::unconstrai... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d274ef3748b82d7d7eccc39a8482586a4d8a5cc1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d274ef3748b82d7d7eccc39a8482586a4d8a5cc1/tokio/src/runtime/context.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/context.rs:4 | pub(crate) fn thread_id() -> Result<ThreadId, AccessError> {
CONTEXT.try_with(|ctx| {
match ctx.thread_id.get() {
Some(id) => id,
None => {
let id = ThreadId::next();
ctx.thread_id.set(Some(id));
id
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d274ef3748b82d7d7eccc39a8482586a4d8a5cc1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d274ef3748b82d7d7eccc39a8482586a4d8a5cc1/tokio/src/runtime/context.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/context.rs:5 | /// If true, then this is the root runtime guard. It is possible to nest
/// runtime guards by using `block_in_place` between the calls. We need
/// to track the root guard as this is the guard responsible for freeing
/// the deferred task queue.
is_root: bool,
}
/// Guard track... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d274ef3748b82d7d7eccc39a8482586a4d8a5cc1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d274ef3748b82d7d7eccc39a8482586a4d8a5cc1/tokio/src/runtime/context.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/context.rs:6 | CONTEXT.try_with(|ctx| ctx.set_current(handle)).ok()
}
/// Marks the current thread as being within the dynamic extent of an
/// executor.
#[track_caller]
pub(crate) fn enter_runtime(handle: &scheduler::Handle, allow_block_in_place: bool) -> EnterRuntimeGuard {
if let Some(enter) = try_ent... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d274ef3748b82d7d7eccc39a8482586a4d8a5cc1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d274ef3748b82d7d7eccc39a8482586a4d8a5cc1/tokio/src/runtime/context.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/context.rs:7 | Some(EnterRuntimeGuard {
blocking: BlockingRegionGuard::new(),
handle: c.set_current(handle),
is_root,
})
}
})
}
pub(crate) fn try_enter_blocking_region() -> Option<BlockingRegionGuard> {
CONTEXT.try_with(|c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d274ef3748b82d7d7eccc39a8482586a4d8a5cc1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d274ef3748b82d7d7eccc39a8482586a4d8a5cc1/tokio/src/runtime/context.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/context.rs:8 | }
pub(crate) fn with_defer<R>(f: impl FnOnce(&mut Defer) -> R) -> Option<R> {
CONTEXT.with(|c| {
let mut defer = c.defer.borrow_mut();
defer.as_mut().map(f)
})
}
impl Context {
fn set_current(&self, handle: &scheduler::Handle) -> SetCurrentGuard {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d274ef3748b82d7d7eccc39a8482586a4d8a5cc1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d274ef3748b82d7d7eccc39a8482586a4d8a5cc1/tokio/src/runtime/context.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/context.rs:9 | CONTEXT.with(|c| {
assert!(c.runtime.get().is_entered());
c.runtime.set(EnterRuntime::NotEntered);
if self.is_root {
*c.defer.borrow_mut() = None;
}
});
}
}
impl BlockingRegionGuard {
fn new() -> Bl... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d274ef3748b82d7d7eccc39a8482586a4d8a5cc1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d274ef3748b82d7d7eccc39a8482586a4d8a5cc1/tokio/src/runtime/context.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/context.rs:10 | let mut park = CachedParkThread::new();
let waker = park.waker().map_err(|_| ())?;
let mut cx = Context::from_waker(&waker);
pin!(f);
let when = Instant::now() + timeout;
loop {
if let Ready(v) = crate::runtime::coop::budget(|| f.as_mut().pol... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d274ef3748b82d7d7eccc39a8482586a4d8a5cc1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d274ef3748b82d7d7eccc39a8482586a4d8a5cc1/tokio/src/runtime/context.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/context.rs:11 | })
}
}
}
impl EnterRuntime {
pub(crate) fn is_entered(self) -> bool {
matches!(self, EnterRuntime::Entered { .. })
}
}
cfg_taskdump! {
/// SAFETY: Callers of this function must ensure that trace frames always
/// form a valid linked list.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d274ef3748b82d7d7eccc39a8482586a4d8a5cc1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d274ef3748b82d7d7eccc39a8482586a4d8a5cc1/tokio/src/runtime/context.rs | 401 | 458 |
tokio-rs/tokio:tokio/src/runtime/context.rs:12 | assert!(!c.runtime.get().is_entered(), "closure claimed permanent executor");
c.runtime.set(self.0);
});
}
}
let was = CONTEXT.with(|c| {
let e = c.runtime.get();
assert!(e.is_entered(), "asked to exit when not entered");
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d274ef3748b82d7d7eccc39a8482586a4d8a5cc1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d274ef3748b82d7d7eccc39a8482586a4d8a5cc1/tokio/src/runtime/context.rs | 441 | 458 |
tokio-rs/tokio:tokio/src/runtime/context.rs:5 | /// If true, then this is the root runtime guard. It is possible to nest
/// runtime guards by using `block_in_place` between the calls. We need
/// to track the root guard as this is the guard responsible for freeing
/// the deferred task queue.
is_root: bool,
}
/// Guard track... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f/tokio/src/runtime/context.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/context.rs:6 | /// Marks the current thread as being within the dynamic extent of an
/// executor.
#[track_caller]
pub(crate) fn enter_runtime(handle: &scheduler::Handle, allow_block_in_place: bool) -> EnterRuntimeGuard {
if let Some(enter) = try_enter_runtime(handle, allow_block_in_place) {
return ent... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f/tokio/src/runtime/context.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/context.rs:7 | })
}
})
}
pub(crate) fn try_enter_blocking_region() -> Option<BlockingRegionGuard> {
CONTEXT.try_with(|c| {
if c.runtime.get().is_entered() {
None
} else {
Some(BlockingRegionGuard::new())
}
// If access... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f/tokio/src/runtime/context.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/context.rs:8 | let mut defer = c.defer.borrow_mut();
defer.as_mut().map(f)
})
}
impl Context {
fn set_current(&self, handle: &scheduler::Handle) -> SetCurrentGuard {
let rng_seed = handle.seed_generator().next_seed();
let old_handle = self.handle.borrow_mut().replace(handl... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f/tokio/src/runtime/context.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/context.rs:9 | if self.is_root {
*c.defer.borrow_mut() = None;
}
});
}
}
impl BlockingRegionGuard {
fn new() -> BlockingRegionGuard {
BlockingRegionGuard { _p: PhantomData }
}
/// Blocks the thread on the specified future, returning t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f/tokio/src/runtime/context.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/context.rs:10 | pin!(f);
let when = Instant::now() + timeout;
loop {
if let Ready(v) = crate::runtime::coop::budget(|| f.as_mut().poll(&mut cx)) {
return Ok(v);
}
let now = Instant::now();
if now >= when {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f/tokio/src/runtime/context.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/context.rs:11 | impl EnterRuntime {
pub(crate) fn is_entered(self) -> bool {
matches!(self, EnterRuntime::Entered { .. })
}
}
cfg_taskdump! {
/// SAFETY: Callers of this function must ensure that trace frames always
/// form a valid linked list.
pub(crate) unsafe fn with_tra... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f/tokio/src/runtime/context.rs | 401 | 454 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | use crate::loom::thread::AccessError;
use crate::runtime::coop;
use std::cell::Cell;
#[cfg(any(feature = "rt", feature = "macros"))]
use crate::util::rand::{FastRand, RngSeed};
cfg_rt! {
use crate::runtime::{scheduler, task::Id, Defer};
use std::cell::RefCell;
use std::marker::PhantomData;
use std::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | b921fe45ac9fc49e18bc6e834065b61d246f56e0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b921fe45ac9fc49e18bc6e834065b61d246f56e0/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | #[cfg(any(feature = "rt", feature = "macros"))]
rng: FastRand,
/// Tracks the amount of "work" a task may still do before yielding back to
/// the sheduler
budget: Cell<coop::Budget>,
}
tokio_thread_local! {
static CONTEXT: Context = {
Context {
#[cfg(feature = "rt")]
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | b921fe45ac9fc49e18bc6e834065b61d246f56e0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b921fe45ac9fc49e18bc6e834065b61d246f56e0/tokio/src/runtime/context.rs | 41 | 100 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.