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:3 | #[cfg(any(feature = "macros", all(feature = "sync", feature = "rt")))]
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! {
us... | 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 | 81 | 140 |
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 | c6552c5680fa14105547cfbbc26b26d67197b64e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6552c5680fa14105547cfbbc26b26d67197b64e/tokio/src/runtime/context.rs | 41 | 100 |
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 | d1b789f33aa9d2bbca84f24b810235a10b149e92 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1b789f33aa9d2bbca84f24b810235a10b149e92/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | /// 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 {
/// Tracks the current runtime handle to use when spawning,
/// accessing drivers, etc...
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d1b789f33aa9d2bbca84f24b810235a10b149e92 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1b789f33aa9d2bbca84f24b810235a10b149e92/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | CONTEXT.try_with(|ctx| f(&ctx.budget))
}
cfg_rt! {
use crate::runtime::TryCurrentError;
use std::fmt;
#[derive(Debug, Clone, Copy)]
#[must_use]
pub(crate) enum EnterRuntime {
/// Currently in a runtime context.
#[cfg_attr(not(feature = "rt"), allow(dead_code))]
Entered { a... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d1b789f33aa9d2bbca84f24b810235a10b149e92 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1b789f33aa9d2bbca84f24b810235a10b149e92/tokio/src/runtime/context.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/context.rs:4 | }
/// Guard tracking that a caller has entered a blocking region.
#[must_use]
pub(crate) struct BlockingRegionGuard {
_p: PhantomData<RefCell<()>>,
}
pub(crate) struct DisallowBlockInPlaceGuard(bool);
pub(crate) fn set_current_task_id(id: Option<Id>) -> Option<Id> {
CONTEXT.tr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d1b789f33aa9d2bbca84f24b810235a10b149e92 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1b789f33aa9d2bbca84f24b810235a10b149e92/tokio/src/runtime/context.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/context.rs:5 | }
panic!(
"Cannot start a runtime from within a runtime. This happens \
because a function (like `block_on`) attempted to block the \
current thread while the thread is being used to drive \
asynchronous tasks."
);
}
/// Tries to enter a runtime ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d1b789f33aa9d2bbca84f24b810235a10b149e92 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1b789f33aa9d2bbca84f24b810235a10b149e92/tokio/src/runtime/context.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/context.rs:6 | CONTEXT.try_with(|c| {
if c.runtime.get().is_entered() {
None
} else {
Some(BlockingRegionGuard::new())
}
// If accessing the thread-local fails, the thread is terminating
// and thread-locals are being destroyed. Because we don... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d1b789f33aa9d2bbca84f24b810235a10b149e92 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1b789f33aa9d2bbca84f24b810235a10b149e92/tokio/src/runtime/context.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/context.rs:7 | fn set_current(&self, handle: &scheduler::Handle) -> SetCurrentGuard {
let rng_seed = handle.seed_generator().next_seed();
let old_handle = self.handle.borrow_mut().replace(handle.clone());
let old_seed = self.rng.replace_seed(rng_seed);
SetCurrentGuard {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d1b789f33aa9d2bbca84f24b810235a10b149e92 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1b789f33aa9d2bbca84f24b810235a10b149e92/tokio/src/runtime/context.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/context.rs:8 | impl BlockingRegionGuard {
fn new() -> BlockingRegionGuard {
BlockingRegionGuard { _p: PhantomData }
}
/// Blocks the thread on the specified future, returning the value with
/// which that future completes.
pub(crate) fn block_on<F>(&mut self, f: F) -> Result<F::Outp... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d1b789f33aa9d2bbca84f24b810235a10b149e92 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1b789f33aa9d2bbca84f24b810235a10b149e92/tokio/src/runtime/context.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/context.rs:9 | }
let now = Instant::now();
if now >= when {
return Err(());
}
// Wake any yielded tasks before parking in order to avoid
// blocking.
with_defer(|defer| defer.wake());
park.park_timeo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d1b789f33aa9d2bbca84f24b810235a10b149e92 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1b789f33aa9d2bbca84f24b810235a10b149e92/tokio/src/runtime/context.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/context.rs:10 | }
// 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.
pu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d1b789f33aa9d2bbca84f24b810235a10b149e92 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1b789f33aa9d2bbca84f24b810235a10b149e92/tokio/src/runtime/context.rs | 361 | 400 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | CONTEXT.try_with(|ctx| f(&ctx.budget))
}
cfg_rt! {
use crate::runtime::TryCurrentError;
use std::fmt;
#[derive(Debug, Clone, Copy)]
#[must_use]
pub(crate) enum EnterRuntime {
/// Currently in a runtime context.
#[cfg_attr(not(feature = "rt"), allow(dead_code))]
Entered { a... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/context.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/context.rs:4 | pub(crate) struct DisallowBlockInPlaceGuard(bool);
pub(crate) fn set_current_task_id(id: Option<Id>) -> Option<Id> {
CONTEXT.try_with(|ctx| ctx.current_task_id.replace(id)).unwrap_or(None)
}
pub(crate) fn current_task_id() -> Option<Id> {
CONTEXT.try_with(|ctx| ctx.current_task_id.get()).u... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/context.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/context.rs:5 | }
/// Tries to enter a runtime context, returns `None` if already in a runtime
/// context.
fn try_enter_runtime(handle: &scheduler::Handle, allow_block_in_place: bool) -> Option<EnterRuntimeGuard> {
CONTEXT.with(|c| {
if c.runtime.get().is_entered() {
None
}... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/context.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/context.rs:6 | if let EnterRuntime::Entered {
allow_block_in_place: true,
} = c.runtime.get()
{
c.runtime.set(EnterRuntime::Entered {
allow_block_in_place: false,
});
true
} else {
false
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/context.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/context.rs:7 | CONTEXT.with(|ctx| {
*ctx.handle.borrow_mut() = self.old_handle.take();
ctx.rng.replace_seed(self.old_seed.clone());
});
}
}
impl fmt::Debug for EnterRuntimeGuard {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/context.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/context.rs:8 | ///
/// 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 c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/context.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/context.rs:9 | fn drop(&mut self) {
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 | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/context.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/context.rs:10 | impl Drop for Reset {
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| {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/context.rs | 361 | 382 |
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;
use crate::runtime::task::Id;
use std::cell::RefCell;
use std::marker::PhantomData... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 71bd49e146ac5288fd4cb327dd3f86eb71b3a865 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/71bd49e146ac5288fd4cb327dd3f86eb71b3a865/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | tokio_thread_local! {
static CONTEXT: Context = {
Context {
/// Tracks the current runtime handle to use when spawning,
/// accessing drivers, etc...
#[cfg(feature = "rt")]
handle: RefCell::new(None),
#[cfg(feature = "rt")]
current_task... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 71bd49e146ac5288fd4cb327dd3f86eb71b3a865 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/71bd49e146ac5288fd4cb327dd3f86eb71b3a865/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | #[derive(Debug, Clone, Copy)]
#[must_use]
pub(crate) enum EnterRuntime {
/// Currently in a runtime context.
#[cfg_attr(not(feature = "rt"), allow(dead_code))]
Entered { allow_block_in_place: bool },
/// Not in a runtime context **or** a blocking region.
NotEntered,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 71bd49e146ac5288fd4cb327dd3f86eb71b3a865 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/71bd49e146ac5288fd4cb327dd3f86eb71b3a865/tokio/src/runtime/context.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/context.rs:4 | }
pub(crate) fn try_current() -> Result<scheduler::Handle, TryCurrentError> {
match CONTEXT.try_with(|ctx| ctx.handle.borrow().clone()) {
Ok(Some(handle)) => Ok(handle),
Ok(None) => Err(TryCurrentError::new_no_context()),
Err(_access_error) => Err(TryCurrentError::new_th... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 71bd49e146ac5288fd4cb327dd3f86eb71b3a865 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/71bd49e146ac5288fd4cb327dd3f86eb71b3a865/tokio/src/runtime/context.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/context.rs:5 | } else {
c.runtime.set(EnterRuntime::Entered { allow_block_in_place });
Some(EnterRuntimeGuard {
blocking: BlockingRegionGuard::new(),
handle: c.set_current(handle),
})
}
})
}
pub(crate) fn try_enter_blo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 71bd49e146ac5288fd4cb327dd3f86eb71b3a865 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/71bd49e146ac5288fd4cb327dd3f86eb71b3a865/tokio/src/runtime/context.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/context.rs:6 | DisallowBlockInPlaceGuard(reset)
}
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(handle.clone());
let old_seed = self.rng.re... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 71bd49e146ac5288fd4cb327dd3f86eb71b3a865 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/71bd49e146ac5288fd4cb327dd3f86eb71b3a865/tokio/src/runtime/context.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/context.rs:7 | impl BlockingRegionGuard {
fn new() -> BlockingRegionGuard {
BlockingRegionGuard { _p: PhantomData }
}
/// Blocks the thread on the specified future, returning the value with
/// which that future completes.
pub(crate) fn block_on<F>(&mut self, f: F) -> Result<F::Outp... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 71bd49e146ac5288fd4cb327dd3f86eb71b3a865 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/71bd49e146ac5288fd4cb327dd3f86eb71b3a865/tokio/src/runtime/context.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/context.rs:8 | }
let now = Instant::now();
if now >= when {
return Err(());
}
park.park_timeout(when - now);
}
}
}
impl Drop for DisallowBlockInPlaceGuard {
fn drop(&mut self) {
if self.0 {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 71bd49e146ac5288fd4cb327dd3f86eb71b3a865 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/71bd49e146ac5288fd4cb327dd3f86eb71b3a865/tokio/src/runtime/context.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/context.rs:9 | //
// # 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(crate) fn current_enter_context() -> EnterRuntime {
CONTEXT.with(|c| c.runtime.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 71bd49e146ac5288fd4cb327dd3f86eb71b3a865 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/71bd49e146ac5288fd4cb327dd3f86eb71b3a865/tokio/src/runtime/context.rs | 321 | 356 |
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;
use std::cell::RefCell;
use std::marker::PhantomData;
use std::time::Duration;
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | b7812c85ca2d051d47cec023b880cbf8cdcbc313 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7812c85ca2d051d47cec023b880cbf8cdcbc313/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | /// Tracks the current runtime handle to use when spawning,
/// accessing drivers, etc...
#[cfg(feature = "rt")]
handle: RefCell::new(None),
/// Tracks if the current thread is currently driving a runtime.
/// Note, that if this is set to "entered", the curre... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | b7812c85ca2d051d47cec023b880cbf8cdcbc313 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7812c85ca2d051d47cec023b880cbf8cdcbc313/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | Entered { allow_block_in_place: bool },
/// Not in a runtime context **or** a blocking region.
NotEntered,
}
#[derive(Debug)]
#[must_use]
pub(crate) struct SetCurrentGuard {
old_handle: Option<scheduler::Handle>,
old_seed: RngSeed,
}
/// Guard tracking that a c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | b7812c85ca2d051d47cec023b880cbf8cdcbc313 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7812c85ca2d051d47cec023b880cbf8cdcbc313/tokio/src/runtime/context.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/context.rs:4 | 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 being within the dynamic extent of an
/// executor.
#[track_caller]
pub(crate) fn enter_runtime(handle: &scheduler::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | b7812c85ca2d051d47cec023b880cbf8cdcbc313 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7812c85ca2d051d47cec023b880cbf8cdcbc313/tokio/src/runtime/context.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/context.rs:5 | 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 | b7812c85ca2d051d47cec023b880cbf8cdcbc313 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7812c85ca2d051d47cec023b880cbf8cdcbc313/tokio/src/runtime/context.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/context.rs:6 | }
}
}
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 | b7812c85ca2d051d47cec023b880cbf8cdcbc313 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7812c85ca2d051d47cec023b880cbf8cdcbc313/tokio/src/runtime/context.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/context.rs:7 | 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 `timeout`, the result is returned. If
/// `timeout` elapses, then `Err` is returned.
pub(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | b7812c85ca2d051d47cec023b880cbf8cdcbc313 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7812c85ca2d051d47cec023b880cbf8cdcbc313/tokio/src/runtime/context.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/context.rs:8 | impl Drop for DisallowBlockInPlaceGuard {
fn drop(&mut self) {
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: fal... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | b7812c85ca2d051d47cec023b880cbf8cdcbc313 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7812c85ca2d051d47cec023b880cbf8cdcbc313/tokio/src/runtime/context.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/context.rs:9 | struct Reset(EnterRuntime);
impl Drop for Reset {
fn drop(&mut self) {
CONTEXT.with(|c| {
assert!(!c.runtime.get().is_entered(), "closure claimed permanent executor");
c.runtime.set(self.0);
});
}
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | b7812c85ca2d051d47cec023b880cbf8cdcbc313 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7812c85ca2d051d47cec023b880cbf8cdcbc313/tokio/src/runtime/context.rs | 321 | 343 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | 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;
use std::cell::RefCell;
use std::marker::PhantomData;
use std::time::Duration;
}
struct Context {
/// Handle to the... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 53cba023dac45c2ab697bd1ead6c86cf4da3561c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/53cba023dac45c2ab697bd1ead6c86cf4da3561c/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | /// accessing drivers, etc...
#[cfg(feature = "rt")]
handle: RefCell::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 curren... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 53cba023dac45c2ab697bd1ead6c86cf4da3561c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/53cba023dac45c2ab697bd1ead6c86cf4da3561c/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | /// accessing drivers, etc...
#[cfg(feature = "rt")]
handle: RefCell::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 curren... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 236d02666765bc3a37ad8286983300854ab0f8a4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/236d02666765bc3a37ad8286983300854ab0f8a4/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | /// Not in a runtime context **or** a blocking region.
NotEntered,
}
#[derive(Debug)]
pub(crate) struct SetCurrentGuard {
old_handle: Option<scheduler::Handle>,
old_seed: RngSeed,
}
/// Guard tracking that a caller has entered a runtime context.
pub(crate) struct EnterR... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 236d02666765bc3a37ad8286983300854ab0f8a4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/236d02666765bc3a37ad8286983300854ab0f8a4/tokio/src/runtime/context.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/context.rs:4 | /// executor.
#[track_caller]
pub(crate) fn enter_runtime(handle: &scheduler::Handle, allow_block_in_place: bool) -> EnterRuntimeGuard {
if let Some(enter) = try_enter_runtime(allow_block_in_place) {
// Set the current runtime handle. This should not fail. A later
// cleanup will... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 236d02666765bc3a37ad8286983300854ab0f8a4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/236d02666765bc3a37ad8286983300854ab0f8a4/tokio/src/runtime/context.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/context.rs:5 | // 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
// permissive.
}).unwrap_or_else(|_| Some(BlockingRegionGuard::new()))
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 236d02666765bc3a37ad8286983300854ab0f8a4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/236d02666765bc3a37ad8286983300854ab0f8a4/tokio/src/runtime/context.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/context.rs:6 | 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 {
fn fmt(&self,... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 236d02666765bc3a37ad8286983300854ab0f8a4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/236d02666765bc3a37ad8286983300854ab0f8a4/tokio/src/runtime/context.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/context.rs:7 | /// 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::Output, (... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 236d02666765bc3a37ad8286983300854ab0f8a4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/236d02666765bc3a37ad8286983300854ab0f8a4/tokio/src/runtime/context.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/context.rs:8 | CONTEXT.with(|c| {
if let EnterRuntime::Entered {
allow_block_in_place: false,
} = c.runtime.get()
{
c.runtime.set(EnterRuntime::Entered {
allow_block_in_place: true,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 236d02666765bc3a37ad8286983300854ab0f8a4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/236d02666765bc3a37ad8286983300854ab0f8a4/tokio/src/runtime/context.rs | 281 | 339 |
tokio-rs/tokio:tokio/src/runtime/context.rs:9 | 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();
assert!(e.is_entered(), "aske... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 236d02666765bc3a37ad8286983300854ab0f8a4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/236d02666765bc3a37ad8286983300854ab0f8a4/tokio/src/runtime/context.rs | 321 | 339 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | 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;
use std::cell::RefCell;
use std::marker::PhantomData;
use std::time::Duration;
}
struct Context {
/// Handle to the... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | #[cfg(feature = "rt")]
tokio_thread_local!(static ENTERED: Cell<EnterRuntime> = const { Cell::new(EnterRuntime::NotEntered) });
#[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) -> R ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | /// Guard tracking that a caller has entered a blocking region.
pub(crate) struct BlockingRegionGuard {
_p: PhantomData<RefCell<()>>,
}
pub(crate) struct DisallowBlockInPlaceGuard(bool);
pub(crate) fn try_current() -> Result<scheduler::Handle, TryCurrentError> {
match CONTEXT.try_with(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/context.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/context.rs:4 | try_set_current(handle).unwrap();
return enter;
}
panic!(
"Cannot start a runtime from within a runtime. This happens \
because a function (like `block_on`) attempted to block the \
current thread while the thread is being used to drive \
asyn... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/context.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/context.rs:5 | if let EnterRuntime::Entered {
allow_block_in_place: true,
} = c.get()
{
c.set(EnterRuntime::Entered {
allow_block_in_place: false,
});
true
} else {
false
}
});
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/context.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/context.rs:6 | fn new() -> BlockingRegionGuard {
BlockingRegionGuard { _p: PhantomData }
}
/// Blocks the thread on the specified future, returning the value with
/// which that future completes.
pub(crate) fn block_on<F>(&mut self, f: F) -> Result<F::Output, AccessError>
where
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/context.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/context.rs:7 | let now = Instant::now();
if now >= when {
return Err(());
}
park.park_timeout(when - now);
}
}
}
impl Drop for DisallowBlockInPlaceGuard {
fn drop(&mut self) {
if self.0 {
// XXX: Do w... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/context.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/context.rs:8 | //
// 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(crate) fn current_enter_context() -> EnterRuntime {
ENTERED.with(|c| c.get())
}
pub(cr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/context.rs | 281 | 314 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | 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;
use std::cell::RefCell;
}
struct Context {
/// Handle to the runtime scheduler running on the current thread.
#[cfg(feat... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d8ee2055304e4fcd875d5cec4ed27e8070cc0306 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d8ee2055304e4fcd875d5cec4ed27e8070cc0306/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | }
pub(super) fn budget<R>(f: impl FnOnce(&Cell<coop::Budget>) -> R) -> R {
CONTEXT.with(|ctx| f(&ctx.budget))
}
cfg_rt! {
use crate::runtime::TryCurrentError;
#[derive(Debug)]
pub(crate) struct SetCurrentGuard {
old_handle: Option<scheduler::Handle>,
old_seed: RngSeed,
}
pub(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | d8ee2055304e4fcd875d5cec4ed27e8070cc0306 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d8ee2055304e4fcd875d5cec4ed27e8070cc0306/tokio/src/runtime/context.rs | 41 | 89 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | use crate::util::rand::{FastRand, RngSeed};
cfg_rt! {
use crate::runtime::scheduler;
use std::cell::RefCell;
}
struct Context {
/// Handle to the runtime scheduler running on the current thread.
#[cfg(feature = "rt")]
scheduler: RefCell<Option<scheduler::Handle>>,
rng: FastRand,
}
tokio_threa... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | b1f40f4356c7f7be0e1959f992608d2058a76deb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1f40f4356c7f7be0e1959f992608d2058a76deb/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | 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 | b1f40f4356c7f7be0e1959f992608d2058a76deb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1f40f4356c7f7be0e1959f992608d2058a76deb/tokio/src/runtime/context.rs | 41 | 72 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | use crate::util::rand::{FastRand, RngSeed};
cfg_rt! {
use crate::runtime::scheduler;
use std::cell::RefCell;
}
struct Context {
/// Handle to the runtime scheduler running on the current thread.
#[cfg(feature = "rt")]
scheduler: RefCell<Option<scheduler::Handle>>,
rng: FastRand,
}
tokio_threa... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | df99428c17ff03134d8f081ee80ef0f6fbe3c813 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df99428c17ff03134d8f081ee80ef0f6fbe3c813/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | 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 | df99428c17ff03134d8f081ee80ef0f6fbe3c813 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df99428c17ff03134d8f081ee80ef0f6fbe3c813/tokio/src/runtime/context.rs | 41 | 72 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | //! Thread local runtime context
use crate::runtime::{Handle, TryCurrentError};
use crate::util::{replace_thread_rng, RngSeed};
use std::cell::RefCell;
tokio_thread_local! {
static CONTEXT: RefCell<Option<Handle>> = const { RefCell::new(None) }
}
pub(crate) fn try_current() -> Result<Handle, crate::runtime::TryC... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 5c2e27565944178b1bc3f7b3dd2cbce41a663aab | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5c2e27565944178b1bc3f7b3dd2cbce41a663aab/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | let rng_seed = new.inner.seed_generator().next_seed();
let old_handle = CONTEXT.try_with(|ctx| ctx.borrow_mut().replace(new)).ok()?;
let old_seed = replace_thread_rng(rng_seed);
Some(EnterGuard {
old_handle,
old_seed,
})
}
#[derive(Debug)]
pub(crate) struct EnterGuard {
old_handle... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 5c2e27565944178b1bc3f7b3dd2cbce41a663aab | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5c2e27565944178b1bc3f7b3dd2cbce41a663aab/tokio/src/runtime/context.rs | 41 | 66 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | //! Thread local runtime context
use crate::runtime::{Handle, TryCurrentError};
use crate::util::{replace_thread_rng, RngSeed};
use std::cell::RefCell;
tokio_thread_local! {
static CONTEXT: RefCell<Option<Handle>> = const { RefCell::new(None) }
}
pub(crate) fn try_current() -> Result<Handle, crate::runtime::TryC... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 6c19748f901a1b8cd7fbf84650f1647342b5a66e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6c19748f901a1b8cd7fbf84650f1647342b5a66e/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | }
/// Sets this [`Handle`] as the current active [`Handle`].
///
/// [`Handle`]: Handle
pub(crate) fn enter(new: Handle) -> EnterGuard {
match try_enter(new) {
Some(guard) => guard,
None => panic!("{}", crate::util::error::THREAD_LOCAL_DESTROYED_ERROR),
}
}
/// Sets this [`Handle`] as the curr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 6c19748f901a1b8cd7fbf84650f1647342b5a66e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6c19748f901a1b8cd7fbf84650f1647342b5a66e/tokio/src/runtime/context.rs | 41 | 82 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | //! Thread local runtime context
use crate::runtime::{Handle, TryCurrentError};
use crate::util::{replace_thread_rng, RngSeed};
use std::cell::RefCell;
tokio_thread_local! {
static CONTEXT: RefCell<Option<Handle>> = const { RefCell::new(None) }
}
pub(crate) fn try_current() -> Result<Handle, crate::runtime::TryC... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | cb67f28fe3c99956959669277fde889bc2dc252e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cb67f28fe3c99956959669277fde889bc2dc252e/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | }
}
cfg_time! {
cfg_test_util! {
pub(crate) fn clock() -> Option<crate::runtime::driver::Clock> {
match CONTEXT.try_with(|ctx| {
let ctx = ctx.borrow();
ctx
.as_ref()
.map(|ctx| ctx.inner.clock().clone())
}) {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | cb67f28fe3c99956959669277fde889bc2dc252e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cb67f28fe3c99956959669277fde889bc2dc252e/tokio/src/runtime/context.rs | 41 | 99 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | old_seed,
})
}
#[derive(Debug)]
pub(crate) struct EnterGuard {
old_handle: Option<Handle>,
old_seed: RngSeed,
}
impl Drop for EnterGuard {
fn drop(&mut self) {
CONTEXT.with(|ctx| {
*ctx.borrow_mut() = self.old_handle.take();
});
// We discard the RngSeed associated ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | cb67f28fe3c99956959669277fde889bc2dc252e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cb67f28fe3c99956959669277fde889bc2dc252e/tokio/src/runtime/context.rs | 81 | 99 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | //! Thread local runtime context
use crate::runtime::{Handle, TryCurrentError};
use crate::util::{replace_thread_rng, RngSeed};
use std::cell::RefCell;
tokio_thread_local! {
static CONTEXT: RefCell<Option<Handle>> = const { RefCell::new(None) }
}
pub(crate) fn try_current() -> Result<Handle, crate::runtime::TryC... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 964535eab006ef7b776e644e53076493a931fbce | github | async-runtime | https://github.com/tokio-rs/tokio/blob/964535eab006ef7b776e644e53076493a931fbce/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | }
}
}
cfg_signal_internal! {
#[cfg(unix)]
pub(crate) fn signal_handle() -> crate::runtime::driver::SignalHandle {
match CONTEXT.try_with(|ctx| {
let ctx = ctx.borrow();
ctx.as_ref()
.expect(crate::util::error::CONTEXT_MISSING_ERROR)
.inner
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 964535eab006ef7b776e644e53076493a931fbce | github | async-runtime | https://github.com/tokio-rs/tokio/blob/964535eab006ef7b776e644e53076493a931fbce/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | pub(crate) fn enter(new: Handle) -> EnterGuard {
match try_enter(new) {
Some(guard) => guard,
None => panic!("{}", crate::util::error::THREAD_LOCAL_DESTROYED_ERROR),
}
}
/// Sets this [`Handle`] as the current active [`Handle`].
///
/// [`Handle`]: Handle
pub(crate) fn try_enter(new: Handle) ->... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 964535eab006ef7b776e644e53076493a931fbce | github | async-runtime | https://github.com/tokio-rs/tokio/blob/964535eab006ef7b776e644e53076493a931fbce/tokio/src/runtime/context.rs | 81 | 117 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | //! Thread local runtime context
use crate::runtime::{Handle, TryCurrentError};
use crate::util::{replace_thread_rng, RngSeed};
use std::cell::RefCell;
thread_local! {
static CONTEXT: RefCell<Option<Handle>> = const { RefCell::new(None) }
}
pub(crate) fn try_current() -> Result<Handle, crate::runtime::TryCurrent... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | ebeb78ed40027032feb77c89a1de4b58d2dcafbf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ebeb78ed40027032feb77c89a1de4b58d2dcafbf/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | //! Thread local runtime context
use crate::runtime::{Handle, TryCurrentError};
use crate::util::{replace_thread_rng, RngSeed};
use std::cell::RefCell;
thread_local! {
static CONTEXT: RefCell<Option<Handle>> = const { RefCell::new(None) }
}
pub(crate) fn try_current() -> Result<Handle, crate::runtime::TryCurrent... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | }
}
}
cfg_signal_internal! {
#[cfg(unix)]
pub(crate) fn signal_handle() -> crate::runtime::driver::SignalHandle {
match CONTEXT.try_with(|ctx| {
let ctx = ctx.borrow();
ctx.as_ref()
.expect(crate::util::error::CONTEXT_MISSING_ERROR)
.as_inner(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | pub(crate) fn spawn_handle() -> Option<crate::runtime::Spawner> {
match CONTEXT.try_with(|ctx| (*ctx.borrow()).as_ref().map(|ctx| ctx.inner.spawner.clone())) {
Ok(spawner) => spawner,
Err(_) => panic!("{}", crate::util::error::THREAD_LOCAL_DESTROYED_ERROR),
}
}
}
/// Sets th... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/context.rs | 81 | 128 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | //! Thread local runtime context
use crate::runtime::{Handle, TryCurrentError};
use std::cell::RefCell;
thread_local! {
static CONTEXT: RefCell<Option<Handle>> = const { RefCell::new(None) }
}
pub(crate) fn try_current() -> Result<Handle, crate::runtime::TryCurrentError> {
match CONTEXT.try_with(|ctx| ctx.bo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 9e0275977981356fc5618b2061cdac8eb39a9569 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9e0275977981356fc5618b2061cdac8eb39a9569/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | }
}
cfg_signal_internal! {
#[cfg(unix)]
pub(crate) fn signal_handle() -> crate::runtime::driver::SignalHandle {
match CONTEXT.try_with(|ctx| {
let ctx = ctx.borrow();
ctx.as_ref()
.expect(crate::util::error::CONTEXT_MISSING_ERROR)
.as_inner()
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 9e0275977981356fc5618b2061cdac8eb39a9569 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9e0275977981356fc5618b2061cdac8eb39a9569/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | match CONTEXT.try_with(|ctx| (*ctx.borrow()).as_ref().map(|ctx| ctx.inner.spawner.clone())) {
Ok(spawner) => spawner,
Err(_) => panic!("{}", crate::util::error::THREAD_LOCAL_DESTROYED_ERROR),
}
}
}
/// Sets this [`Handle`] as the current active [`Handle`].
///
/// [`Handle`]: Handle... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 9e0275977981356fc5618b2061cdac8eb39a9569 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9e0275977981356fc5618b2061cdac8eb39a9569/tokio/src/runtime/context.rs | 81 | 119 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | //! Thread local runtime context
use crate::runtime::{Handle, TryCurrentError};
use std::cell::RefCell;
thread_local! {
static CONTEXT: RefCell<Option<Handle>> = const { RefCell::new(None) }
}
pub(crate) fn try_current() -> Result<Handle, crate::runtime::TryCurrentError> {
match CONTEXT.try_with(|ctx| ctx.bo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 588408c06000313f7b4f31c225d3635e9b012e3f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/588408c06000313f7b4f31c225d3635e9b012e3f/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | pub(crate) fn signal_handle() -> crate::runtime::driver::SignalHandle {
match CONTEXT.try_with(|ctx| {
let ctx = ctx.borrow();
ctx.as_ref().expect(crate::util::error::CONTEXT_MISSING_ERROR).as_inner().signal_handle.clone()
}) {
Ok(signal_handle) => signal_handle,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 588408c06000313f7b4f31c225d3635e9b012e3f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/588408c06000313f7b4f31c225d3635e9b012e3f/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | /// Sets this [`Handle`] as the current active [`Handle`].
///
/// [`Handle`]: Handle
pub(crate) fn try_enter(new: Handle) -> Option<EnterGuard> {
CONTEXT
.try_with(|ctx| {
let old = ctx.borrow_mut().replace(new);
EnterGuard(old)
})
.ok()
}
#[derive(Debug)]
pub(crate... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 588408c06000313f7b4f31c225d3635e9b012e3f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/588408c06000313f7b4f31c225d3635e9b012e3f/tokio/src/runtime/context.rs | 81 | 103 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | //! Thread local runtime context
use crate::runtime::{Handle, TryCurrentError};
use std::cell::RefCell;
thread_local! {
static CONTEXT: RefCell<Option<Handle>> = const { RefCell::new(None) }
}
pub(crate) fn try_current() -> Result<Handle, crate::runtime::TryCurrentError> {
match CONTEXT.try_with(|ctx| ctx.bo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 56ffea09e5ab682e49eab0374da651f277e72566 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/56ffea09e5ab682e49eab0374da651f277e72566/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | pub(crate) fn signal_handle() -> crate::runtime::driver::SignalHandle {
match CONTEXT.try_with(|ctx| {
let ctx = ctx.borrow();
ctx.as_ref().expect(crate::util::error::CONTEXT_MISSING_ERROR).as_inner().signal_handle.clone()
}) {
Ok(signal_handle) => signal_handle,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 56ffea09e5ab682e49eab0374da651f277e72566 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/56ffea09e5ab682e49eab0374da651f277e72566/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | /// Sets this [`Handle`] as the current active [`Handle`].
///
/// [`Handle`]: Handle
pub(crate) fn enter(new: Handle) -> EnterGuard {
match try_enter(new) {
Some(guard) => guard,
None => panic!("{}", crate::util::error::THREAD_LOCAL_DESTROYED_ERROR),
}
}
/// Sets this [`Handle`] as the current... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 56ffea09e5ab682e49eab0374da651f277e72566 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/56ffea09e5ab682e49eab0374da651f277e72566/tokio/src/runtime/context.rs | 81 | 113 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | pub(crate) fn signal_handle() -> crate::runtime::driver::SignalHandle {
match CONTEXT.try_with(|ctx| {
let ctx = ctx.borrow();
ctx.as_ref().expect(crate::util::error::CONTEXT_MISSING_ERROR).as_inner().signal_handle.clone()
}) {
Ok(signal_handle) => signal_handle,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | cbdba8bd32a7a6afd63d43afd5ab978b91745814 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cbdba8bd32a7a6afd63d43afd5ab978b91745814/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | //! Thread local runtime context
use crate::runtime::{Handle, TryCurrentError};
use std::cell::RefCell;
thread_local! {
static CONTEXT: RefCell<Option<Handle>> = const { RefCell::new(None) }
}
pub(crate) fn try_current() -> Result<Handle, crate::runtime::TryCurrentError> {
match CONTEXT.try_with(|ctx| ctx.bo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 7f92bce39f7046e204381127936e2014094f9638 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7f92bce39f7046e204381127936e2014094f9638/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | match CONTEXT.try_with(|ctx| {
let ctx = ctx.borrow();
ctx.as_ref().expect(crate::util::error::CONTEXT_MISSING_ERROR).as_inner().signal_handle.clone()
}) {
Ok(signal_handle) => signal_handle,
Err(_) => panic!("{}", crate::util::error::THREAD_LOCAL_DESTROYED_ERROR)... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 7f92bce39f7046e204381127936e2014094f9638 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7f92bce39f7046e204381127936e2014094f9638/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | //! Thread local runtime context
use crate::runtime::{Handle, TryCurrentError};
use std::cell::RefCell;
thread_local! {
static CONTEXT: RefCell<Option<Handle>> = RefCell::new(None)
}
pub(crate) fn try_current() -> Result<Handle, crate::runtime::TryCurrentError> {
match CONTEXT.try_with(|ctx| ctx.borrow().clo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 159508b916038217ceb668d727d9618b567ea8b1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/159508b916038217ceb668d727d9618b567ea8b1/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | //! Thread local runtime context
use crate::runtime::{Handle, TryCurrentError};
use std::cell::RefCell;
thread_local! {
static CONTEXT: RefCell<Option<Handle>> = RefCell::new(None)
}
pub(crate) fn try_current() -> Result<Handle, crate::runtime::TryCurrentError> {
match CONTEXT.try_with(|ctx| ctx.borrow().clo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 911a0efa87e36f0dffb13e3d52340d5c08415db1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/911a0efa87e36f0dffb13e3d52340d5c08415db1/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | let ctx = ctx.borrow();
ctx.as_ref().expect(crate::util::error::CONTEXT_MISSING_ERROR).as_inner().signal_handle.clone()
}) {
Ok(signal_handle) => signal_handle,
Err(_) => panic!("{}", crate::util::error::THREAD_LOCAL_DESTROYED_ERROR),
}
}
}
cfg_time! {
pub(cr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 911a0efa87e36f0dffb13e3d52340d5c08415db1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/911a0efa87e36f0dffb13e3d52340d5c08415db1/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:3 | ///
/// [`Handle`]: Handle
pub(crate) fn enter(new: Handle) -> EnterGuard {
match try_enter(new) {
Some(guard) => guard,
None => panic!("{}", crate::util::error::THREAD_LOCAL_DESTROYED_ERROR),
}
}
/// Sets this [`Handle`] as the current active [`Handle`].
///
/// [`Handle`]: Handle
pub(crate) f... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 911a0efa87e36f0dffb13e3d52340d5c08415db1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/911a0efa87e36f0dffb13e3d52340d5c08415db1/tokio/src/runtime/context.rs | 81 | 111 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | //! Thread local runtime context
use crate::runtime::{Handle, TryCurrentError};
use std::cell::RefCell;
thread_local! {
static CONTEXT: RefCell<Option<Handle>> = RefCell::new(None)
}
pub(crate) fn try_current() -> Result<Handle, crate::runtime::TryCurrentError> {
match CONTEXT.try_with(|ctx| ctx.borrow().clo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 1f8105588c06c41c90c3c77628d10cde4b3b2edb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1f8105588c06c41c90c3c77628d10cde4b3b2edb/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | let ctx = ctx.borrow();
ctx.as_ref().expect(crate::util::error::CONTEXT_MISSING_ERROR).signal_handle.clone()
}) {
Ok(signal_handle) => signal_handle,
Err(_) => panic!("{}", crate::util::error::THREAD_LOCAL_DESTROYED_ERROR),
}
}
}
cfg_time! {
pub(crate) fn tim... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 1f8105588c06c41c90c3c77628d10cde4b3b2edb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1f8105588c06c41c90c3c77628d10cde4b3b2edb/tokio/src/runtime/context.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | //! Thread local runtime context
use crate::runtime::Handle;
use std::cell::RefCell;
thread_local! {
static CONTEXT: RefCell<Option<Handle>> = RefCell::new(None)
}
pub(crate) fn current() -> Option<Handle> {
CONTEXT.with(|ctx| ctx.borrow().clone())
}
cfg_io_driver! {
pub(crate) fn io_handle() -> crate::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | cfg_test_util! {
pub(crate) fn clock() -> Option<crate::runtime::driver::Clock> {
CONTEXT.with(|ctx| (*ctx.borrow()).as_ref().map(|ctx| ctx.clock.clone()))
}
}
}
cfg_rt! {
pub(crate) fn spawn_handle() -> Option<crate::runtime::Spawner> {
CONTEXT.with(|ctx| (*ctx.borrow()).as... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/runtime/context.rs | 41 | 73 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | //! Thread local runtime context
use crate::runtime::Handle;
use std::cell::RefCell;
thread_local! {
static CONTEXT: RefCell<Option<Handle>> = RefCell::new(None)
}
pub(crate) fn current() -> Option<Handle> {
CONTEXT.with(|ctx| ctx.borrow().clone())
}
cfg_io_driver! {
pub(crate) fn io_handle() -> crate::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | bcb95db4e2d4a9a43a3f3f5e129ddb7232599451 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/bcb95db4e2d4a9a43a3f3f5e129ddb7232599451/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | cfg_test_util! {
pub(crate) fn clock() -> Option<crate::runtime::driver::Clock> {
CONTEXT.with(|ctx| (*ctx.borrow()).as_ref().map(|ctx| ctx.clock.clone()))
}
}
}
cfg_rt! {
pub(crate) fn spawn_handle() -> Option<crate::runtime::Spawner> {
CONTEXT.with(|ctx| (*ctx.borrow()).as... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | bcb95db4e2d4a9a43a3f3f5e129ddb7232599451 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/bcb95db4e2d4a9a43a3f3f5e129ddb7232599451/tokio/src/runtime/context.rs | 41 | 73 |
tokio-rs/tokio:tokio/src/runtime/context.rs:1 | //! Thread local runtime context
use crate::runtime::Handle;
use std::cell::RefCell;
thread_local! {
static CONTEXT: RefCell<Option<Handle>> = RefCell::new(None)
}
pub(crate) fn current() -> Option<Handle> {
CONTEXT.with(|ctx| ctx.borrow().clone())
}
cfg_io_driver! {
pub(crate) fn io_handle() -> crate::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | fdde5583f853655fec57c44928b7d5f01621b754 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fdde5583f853655fec57c44928b7d5f01621b754/tokio/src/runtime/context.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/context.rs:2 | cfg_test_util! {
pub(crate) fn clock() -> Option<crate::runtime::driver::Clock> {
CONTEXT.with(|ctx| match *ctx.borrow() {
Some(ref ctx) => Some(ctx.clock.clone()),
None => None,
})
}
}
}
cfg_rt! {
pub(crate) fn spawn_handle() -> Option<cr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/context.rs | MIT | fdde5583f853655fec57c44928b7d5f01621b754 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fdde5583f853655fec57c44928b7d5f01621b754/tokio/src/runtime/context.rs | 41 | 79 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.