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/scheduler/current_thread.rs:15 | if let Some(core) = core.as_mut() {
core.unhandled_panic = true;
self.shared.owned.close_and_shutdown_all();
}
}
_ => unreachable!("runtime core not set in CURRENT thread-local"),
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/scheduler/current_thread.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:16 | pin!(future);
'outer: loop {
let handle = &context.handle;
if handle.reset_woken() {
let (c, res) = context.enter(core, || {
crate::runtime::coop::budget(|| future.as_mut().poll(&mut cx))
});
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/scheduler/current_thread.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:17 | context.park(core, handle)
};
// Try polling the `block_on` future next
continue 'outer;
}
};
let task = context.handle.shared.owned.assert_owner(task);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/scheduler/current_thread.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:18 | // Call the closure and place `core` back
let (core, ret) = CURRENT.set(&self.context, || f(core, &self.context));
*self.context.core.borrow_mut() = Some(core);
ret
}
}
impl Drop for CoreGuard<'_> {
fn drop(&mut self) {
if let Some(core) = self.context.core.borrow_mut().take()... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/scheduler/current_thread.rs | 681 | 702 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:3 | /// Keeps track of various runtime metrics.
scheduler_metrics: SchedulerMetrics,
/// This scheduler only has one worker.
worker_metrics: WorkerMetrics,
}
/// Thread-local context.
struct Context {
/// Scheduler handle
handle: Arc<Handle>,
/// Scheduler core, enabling the holder of `Context` t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 7430865d655d31836ce62e65d8f03bcb9a85b12e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7430865d655d31836ce62e65d8f03bcb9a85b12e/tokio/src/runtime/scheduler/current_thread.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:4 | driver: driver_handle,
blocking_spawner,
seed_generator,
});
let core = AtomicCell::new(Some(Box::new(Core {
tasks: VecDeque::with_capacity(INITIAL_CAPACITY),
tick: 0,
driver: Some(driver),
metrics: MetricsBatch::new(),
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 7430865d655d31836ce62e65d8f03bcb9a85b12e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7430865d655d31836ce62e65d8f03bcb9a85b12e/tokio/src/runtime/scheduler/current_thread.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:5 | .block_on(poll_fn(|cx| {
if notified.as_mut().poll(cx).is_ready() {
return Ready(None);
}
if let Ready(out) = future.as_mut().poll(cx) {
return Ready(Some(out));
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 7430865d655d31836ce62e65d8f03bcb9a85b12e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7430865d655d31836ce62e65d8f03bcb9a85b12e/tokio/src/runtime/scheduler/current_thread.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:6 | None => panic!("Oh no! We never placed the Core back, this is a bug!"),
};
core.enter(|mut core, _context| {
// Drain the OwnedTasks collection. This call also closes the
// collection, ensuring that no tasks are ever pushed after this
// call returns.
ha... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 7430865d655d31836ce62e65d8f03bcb9a85b12e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7430865d655d31836ce62e65d8f03bcb9a85b12e/tokio/src/runtime/scheduler/current_thread.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:7 | impl fmt::Debug for CurrentThread {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("CurrentThread").finish()
}
}
// ===== impl Core =====
impl Core {
fn pop_task(&mut self, handle: &Handle) -> Option<task::Notified<Arc<Handle>>> {
let ret = self.tasks.pop_fro... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 7430865d655d31836ce62e65d8f03bcb9a85b12e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7430865d655d31836ce62e65d8f03bcb9a85b12e/tokio/src/runtime/scheduler/current_thread.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:8 | if let Some(wakers) = wakers {
for waker in wakers {
waker.wake();
}
}
}
// ===== impl Context =====
impl Context {
/// Execute the closure with the given scheduler core stored in the
/// thread-local context.
fn run_task<R>(&self, mut core: Box<Core>, f: impl FnOnce() -> R... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 7430865d655d31836ce62e65d8f03bcb9a85b12e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7430865d655d31836ce62e65d8f03bcb9a85b12e/tokio/src/runtime/scheduler/current_thread.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:9 | });
core = c;
core.metrics.returned_from_park();
}
if let Some(f) = &handle.shared.config.after_unpark {
// Incorrect lint, the closures are actually different types so `f`
// cannot be passed as an argument to `enter`.
#[allow(clippy::redund... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 7430865d655d31836ce62e65d8f03bcb9a85b12e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7430865d655d31836ce62e65d8f03bcb9a85b12e/tokio/src/runtime/scheduler/current_thread.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:10 | // Take the scheduler core back
let core = self.core.borrow_mut().take().expect("core missing");
(core, ret)
}
}
// ===== impl Handle =====
impl Handle {
/// Spawns a future onto the `CurrentThread` scheduler
pub(crate) fn spawn<F>(
me: &Arc<Self>,
future: F,
id: cr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 7430865d655d31836ce62e65d8f03bcb9a85b12e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7430865d655d31836ce62e65d8f03bcb9a85b12e/tokio/src/runtime/scheduler/current_thread.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:11 | let mut traces = vec![];
// todo: how to make this work outside of a runtime context?
CURRENT.with(|maybe_context| {
// drain the local queue
let context = if let Some(context) = maybe_context {
context
} else {
return;
};
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 7430865d655d31836ce62e65d8f03bcb9a85b12e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7430865d655d31836ce62e65d8f03bcb9a85b12e/tokio/src/runtime/scheduler/current_thread.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:12 | match self.shared.queue.lock().as_mut() {
Some(queue) => queue.pop_front(),
None => None,
}
}
fn waker_ref(me: &Arc<Self>) -> WakerRef<'_> {
// Set woken to true when enter block_on, ensure outer future
// be polled for the first time when enter loop
me.s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 7430865d655d31836ce62e65d8f03bcb9a85b12e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7430865d655d31836ce62e65d8f03bcb9a85b12e/tokio/src/runtime/scheduler/current_thread.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:13 | pub(crate) fn num_blocking_threads(&self) -> usize {
self.blocking_spawner.num_threads()
}
pub(crate) fn num_idle_blocking_threads(&self) -> usize {
self.blocking_spawner.num_idle_threads()
}
pub(crate) fn blocking_queue_depth(&self) -> usize {
self.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 7430865d655d31836ce62e65d8f03bcb9a85b12e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7430865d655d31836ce62e65d8f03bcb9a85b12e/tokio/src/runtime/scheduler/current_thread.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:14 | core.push_task(self, task);
}
}
_ => {
// Track that a task was scheduled from **outside** of the runtime.
self.shared.scheduler_metrics.inc_remote_schedule_count();
// If the queue is None, then the runtime has shut down. We
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 7430865d655d31836ce62e65d8f03bcb9a85b12e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7430865d655d31836ce62e65d8f03bcb9a85b12e/tokio/src/runtime/scheduler/current_thread.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:15 | }
_ => unreachable!("runtime core not set in CURRENT thread-local"),
})
}
}
}
}
}
impl Wake for Handle {
fn wake(arc_self: Arc<Self>) {
Wake::wake_by_ref(&arc_self)
}
/// Wake by reference
fn wake_by_ref(arc_se... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 7430865d655d31836ce62e65d8f03bcb9a85b12e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7430865d655d31836ce62e65d8f03bcb9a85b12e/tokio/src/runtime/scheduler/current_thread.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:16 | let handle = &context.handle;
if handle.reset_woken() {
let (c, res) = context.enter(core, || {
crate::runtime::coop::budget(|| future.as_mut().poll(&mut cx))
});
core = c;
if let Ready(v) = res {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 7430865d655d31836ce62e65d8f03bcb9a85b12e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7430865d655d31836ce62e65d8f03bcb9a85b12e/tokio/src/runtime/scheduler/current_thread.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:7 | impl fmt::Debug for CurrentThread {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("CurrentThread").finish()
}
}
// ===== impl Core =====
impl Core {
fn pop_task(&mut self, handle: &Handle) -> Option<task::Notified<Arc<Handle>>> {
let ret = self.tasks.pop_fro... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f/tokio/src/runtime/scheduler/current_thread.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:8 | /// Execute the closure with the given scheduler core stored in the
/// thread-local context.
fn run_task<R>(&self, mut core: Box<Core>, f: impl FnOnce() -> R) -> (Box<Core>, R) {
core.metrics.incr_poll_count();
self.enter(core, || crate::runtime::coop::budget(f))
}
/// Blocks the curre... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f/tokio/src/runtime/scheduler/current_thread.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:9 | let (c, _) = self.enter(core, || f());
core = c;
}
core.driver = Some(driver);
core
}
/// Checks the driver for new events without blocking the thread.
fn park_yield(&self, mut core: Box<Core>, handle: &Handle) -> Box<Core> {
let mut driver = core.driver.take().... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f/tokio/src/runtime/scheduler/current_thread.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:10 | /// Spawns a future onto the `CurrentThread` scheduler
pub(crate) fn spawn<F>(
me: &Arc<Self>,
future: F,
id: crate::runtime::task::Id,
) -> JoinHandle<F::Output>
where
F: crate::future::Future + Send + 'static,
F::Output: Send + 'static,
{
let (handle, no... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f/tokio/src/runtime/scheduler/current_thread.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:11 | let mut maybe_core = context.core.borrow_mut();
let core = if let Some(core) = maybe_core.as_mut() {
core
} else {
return;
};
let local = &mut core.tasks;
let mut injection = self.shared.queue.lock();
let injection ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f/tokio/src/runtime/scheduler/current_thread.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:12 | self.shared.woken.swap(false, AcqRel)
}
}
cfg_metrics! {
impl Handle {
pub(crate) fn scheduler_metrics(&self) -> &SchedulerMetrics {
&self.shared.scheduler_metrics
}
pub(crate) fn injection_queue_depth(&self) -> usize {
// TODO: avoid having to lock. The multi-t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f/tokio/src/runtime/scheduler/current_thread.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:13 | }
}
}
impl fmt::Debug for Handle {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("current_thread::Handle { ... }").finish()
}
}
// ===== impl Shared =====
impl Schedule for Arc<Handle> {
fn release(&self, task: &Task<Self>) -> Option<Task<Self>> {
self.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f/tokio/src/runtime/scheduler/current_thread.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:14 | }
});
}
cfg_unstable! {
fn unhandled_panic(&self) {
use crate::runtime::UnhandledPanic;
match self.shared.config.unhandled_panic {
UnhandledPanic::Ignore => {
// Do nothing
}
UnhandledPanic::ShutdownRun... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f/tokio/src/runtime/scheduler/current_thread.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:15 | fn wake_by_ref(arc_self: &Arc<Self>) {
arc_self.shared.woken.store(true, Release);
arc_self.driver.unpark();
}
}
// ===== CoreGuard =====
/// Used to ensure we always place the `Core` value back into its slot in
/// `CurrentThread`, even if the future panics.
struct CoreGuard<'a> {
context: Co... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f/tokio/src/runtime/scheduler/current_thread.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:16 | // Make sure we didn't hit an unhandled_panic
if core.unhandled_panic {
return (core, None);
}
// Get and increment the current tick
let tick = core.tick;
core.tick = core.tick.wrapping_add(1);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f/tokio/src/runtime/scheduler/current_thread.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:17 | core = context.park_yield(core, handle);
}
});
match ret {
Some(ret) => ret,
None => {
// `block_on` panicked.
panic!("a spawned task panicked and the runtime is configured to shut down on unhandled panic");
}
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/660eac71f0ac7274dc3ba6dd92df9ff2ea61be9f/tokio/src/runtime/scheduler/current_thread.rs | 641 | 683 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:9 | let (c, _) = self.enter(core, || f());
core = c;
}
core.driver = Some(driver);
core
}
/// Checks the driver for new events without blocking the thread.
fn park_yield(&self, mut core: Box<Core>, handle: &Handle) -> Box<Core> {
let mut driver = core.driver.take().... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 1d785fd66fce4a9125c6f0c403dfe1921d011539 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d785fd66fce4a9125c6f0c403dfe1921d011539/tokio/src/runtime/scheduler/current_thread.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:10 | /// Spawns a future onto the `CurrentThread` scheduler
pub(crate) fn spawn<F>(
me: &Arc<Self>,
future: F,
id: crate::runtime::task::Id,
) -> JoinHandle<F::Output>
where
F: crate::future::Future + Send + 'static,
F::Output: Send + 'static,
{
let (handle, no... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 1d785fd66fce4a9125c6f0c403dfe1921d011539 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d785fd66fce4a9125c6f0c403dfe1921d011539/tokio/src/runtime/scheduler/current_thread.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:11 | impl Handle {
pub(crate) fn scheduler_metrics(&self) -> &SchedulerMetrics {
&self.shared.scheduler_metrics
}
pub(crate) fn injection_queue_depth(&self) -> usize {
// TODO: avoid having to lock. The multi-threaded injection queue
// could probably be used here... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 1d785fd66fce4a9125c6f0c403dfe1921d011539 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d785fd66fce4a9125c6f0c403dfe1921d011539/tokio/src/runtime/scheduler/current_thread.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:12 | fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("current_thread::Handle { ... }").finish()
}
}
// ===== impl Shared =====
impl Schedule for Arc<Handle> {
fn release(&self, task: &Task<Self>) -> Option<Task<Self>> {
self.shared.owned.remove(task)
}
fn sche... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 1d785fd66fce4a9125c6f0c403dfe1921d011539 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d785fd66fce4a9125c6f0c403dfe1921d011539/tokio/src/runtime/scheduler/current_thread.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:13 | fn unhandled_panic(&self) {
use crate::runtime::UnhandledPanic;
match self.shared.config.unhandled_panic {
UnhandledPanic::Ignore => {
// Do nothing
}
UnhandledPanic::ShutdownRuntime => {
// This hook is onl... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 1d785fd66fce4a9125c6f0c403dfe1921d011539 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d785fd66fce4a9125c6f0c403dfe1921d011539/tokio/src/runtime/scheduler/current_thread.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:14 | // ===== CoreGuard =====
/// Used to ensure we always place the `Core` value back into its slot in
/// `CurrentThread`, even if the future panics.
struct CoreGuard<'a> {
context: Context,
scheduler: &'a CurrentThread,
}
impl CoreGuard<'_> {
#[track_caller]
fn block_on<F: Future>(self, future: F) -> F:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 1d785fd66fce4a9125c6f0c403dfe1921d011539 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d785fd66fce4a9125c6f0c403dfe1921d011539/tokio/src/runtime/scheduler/current_thread.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:15 | // Get and increment the current tick
let tick = core.tick;
core.tick = core.tick.wrapping_add(1);
let entry = if tick % handle.shared.config.global_queue_interval == 0 {
handle.pop().or_else(|| core.tasks.pop_front())
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 1d785fd66fce4a9125c6f0c403dfe1921d011539 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d785fd66fce4a9125c6f0c403dfe1921d011539/tokio/src/runtime/scheduler/current_thread.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:16 | Some(ret) => ret,
None => {
// `block_on` panicked.
panic!("a spawned task panicked and the runtime is configured to shut down on unhandled panic");
}
}
}
/// Enters the scheduler context. This sets the queue and other necessary
/// scheduler ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 1d785fd66fce4a9125c6f0c403dfe1921d011539 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d785fd66fce4a9125c6f0c403dfe1921d011539/tokio/src/runtime/scheduler/current_thread.rs | 601 | 638 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:11 | impl Handle {
pub(crate) fn scheduler_metrics(&self) -> &SchedulerMetrics {
&self.shared.scheduler_metrics
}
pub(crate) fn injection_queue_depth(&self) -> usize {
// TODO: avoid having to lock. The multi-threaded injection queue
// could probably be used here... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/scheduler/current_thread.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:12 | // ===== impl Shared =====
impl Schedule for Arc<Handle> {
fn release(&self, task: &Task<Self>) -> Option<Task<Self>> {
self.shared.owned.remove(task)
}
fn schedule(&self, task: task::Notified<Self>) {
CURRENT.with(|maybe_cx| match maybe_cx {
Some(cx) if Arc::ptr_eq(self, &cx.h... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/scheduler/current_thread.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:13 | UnhandledPanic::Ignore => {
// Do nothing
}
UnhandledPanic::ShutdownRuntime => {
// This hook is only called from within the runtime, so
// `CURRENT` should match with `&self`, i.e. there is no
// opportunity... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/scheduler/current_thread.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:14 | /// `CurrentThread`, even if the future panics.
struct CoreGuard<'a> {
context: Context,
scheduler: &'a CurrentThread,
}
impl CoreGuard<'_> {
#[track_caller]
fn block_on<F: Future>(self, future: F) -> F::Output {
let ret = self.enter(|mut core, context| {
let waker = Handle::waker_r... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/scheduler/current_thread.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:15 | let entry = if tick % handle.shared.config.global_queue_interval == 0 {
handle.pop().or_else(|| core.tasks.pop_front())
} else {
core.tasks.pop_front().or_else(|| handle.pop())
};
let task = match entry {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/scheduler/current_thread.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:16 | }
}
}
/// Enters the scheduler context. This sets the queue and other necessary
/// scheduler state in the thread-local.
fn enter<F, R>(self, f: F) -> R
where
F: FnOnce(Box<Core>, &Context) -> (Box<Core>, R),
{
// Remove `core` from `context` to pass into the closure.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/scheduler/current_thread.rs | 601 | 634 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:1 | use crate::future::poll_fn;
use crate::loom::sync::atomic::AtomicBool;
use crate::loom::sync::{Arc, Mutex};
use crate::runtime::driver::{self, Driver};
use crate::runtime::task::{self, JoinHandle, OwnedTasks, Schedule, Task};
use crate::runtime::{blocking, scheduler, Config};
use crate::runtime::{MetricsBatch, Schedule... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/scheduler/current_thread.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:7 | impl fmt::Debug for CurrentThread {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("CurrentThread").finish()
}
}
// ===== impl Core =====
impl Core {
fn pop_task(&mut self, handle: &Handle) -> Option<task::Notified<Arc<Handle>>> {
let ret = self.tasks.pop_fro... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/scheduler/current_thread.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:8 | /// including I/O events, timer events, ...
fn park(&self, mut core: Box<Core>, handle: &Handle) -> Box<Core> {
let mut driver = core.driver.take().expect("driver missing");
if let Some(f) = &handle.shared.config.before_park {
// Incorrect lint, the closures are actually different types... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/scheduler/current_thread.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:9 | fn park_yield(&self, mut core: Box<Core>, handle: &Handle) -> Box<Core> {
let mut driver = core.driver.take().expect("driver missing");
core.metrics.submit(&handle.shared.worker_metrics);
let (mut core, _) = self.enter(core, || {
driver.park_timeout(&handle.driver, Duration::from_mi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/scheduler/current_thread.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:10 | let (handle, notified) = me.shared.owned.bind(future, me.clone(), id);
if let Some(notified) = notified {
me.schedule(notified);
}
handle
}
fn pop(&self) -> Option<task::Notified<Arc<Handle>>> {
match self.shared.queue.lock().as_mut() {
Some(queue) => q... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/scheduler/current_thread.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:11 | .lock()
.as_ref()
.map(|queue| queue.len())
.unwrap_or(0)
}
pub(crate) fn worker_metrics(&self, worker: usize) -> &WorkerMetrics {
assert_eq!(0, worker);
&self.shared.worker_metrics
}
pub(crate) fn num_blocking_thr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/scheduler/current_thread.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:12 | Some(cx) if Arc::ptr_eq(self, &cx.handle) => {
let mut core = cx.core.borrow_mut();
// If `None`, the runtime is shutting down, so there is no need
// to schedule the task.
if let Some(core) = core.as_mut() {
core.push_task(self, task)... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/scheduler/current_thread.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:14 | let waker = Handle::waker_ref(&context.handle);
let mut cx = std::task::Context::from_waker(&waker);
pin!(future);
'outer: loop {
let handle = &context.handle;
if handle.reset_woken() {
let (c, res) = context.enter(core, || {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/scheduler/current_thread.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:15 | // Try polling the `block_on` future next
continue 'outer;
}
};
let task = context.handle.shared.owned.assert_owner(task);
let (c, _) = context.run_task(core, || {
task.run();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/scheduler/current_thread.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:16 | let (core, ret) = CURRENT.set(&self.context, || f(core, &self.context));
*self.context.core.borrow_mut() = Some(core);
ret
}
}
impl Drop for CoreGuard<'_> {
fn drop(&mut self) {
if let Some(core) = self.context.core.borrow_mut().take() {
// Replace old scheduler back into ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/scheduler/current_thread.rs | 601 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:4 | driver: driver_handle,
blocking_spawner,
seed_generator,
});
let core = AtomicCell::new(Some(Box::new(Core {
tasks: VecDeque::with_capacity(INITIAL_CAPACITY),
tick: 0,
driver: Some(driver),
metrics: MetricsBatch::new(),
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | b2f5dbea4703be0c97150b91d3b2c46f29f1a0bf | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b2f5dbea4703be0c97150b91d3b2c46f29f1a0bf/tokio/src/runtime/scheduler/current_thread.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:1 | use crate::future::poll_fn;
use crate::loom::sync::atomic::AtomicBool;
use crate::loom::sync::{Arc, Mutex};
use crate::runtime::context::SetCurrentGuard;
use crate::runtime::driver::{self, Driver};
use crate::runtime::task::{self, JoinHandle, OwnedTasks, Schedule, Task};
use crate::runtime::{blocking, Config};
use crat... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 23fdd32b0180f6a0f65040170755901ea6f48056 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/23fdd32b0180f6a0f65040170755901ea6f48056/tokio/src/runtime/scheduler/current_thread.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:2 | pub(crate) struct Handle {
/// Scheduler state shared across threads
shared: Shared,
/// Resource driver handles
pub(crate) driver: driver::Handle,
/// Blocking pool spawner
pub(crate) blocking_spawner: blocking::Spawner,
/// Current random number generator seed
pub(crate) seed_genera... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 23fdd32b0180f6a0f65040170755901ea6f48056 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/23fdd32b0180f6a0f65040170755901ea6f48056/tokio/src/runtime/scheduler/current_thread.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:3 | /// Collection of all active tasks spawned onto this executor.
owned: OwnedTasks<Arc<Handle>>,
/// Indicates whether the blocked on thread was woken.
woken: AtomicBool,
/// Scheduler configuration options
config: Config,
/// Keeps track of various runtime metrics.
scheduler_metrics: Sched... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 23fdd32b0180f6a0f65040170755901ea6f48056 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/23fdd32b0180f6a0f65040170755901ea6f48056/tokio/src/runtime/scheduler/current_thread.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:4 | ) -> CurrentThread {
let handle = Arc::new(Handle {
shared: Shared {
queue: Mutex::new(Some(VecDeque::with_capacity(INITIAL_CAPACITY))),
owned: OwnedTasks::new(),
woken: AtomicBool::new(false),
config,
scheduler_metrics:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 23fdd32b0180f6a0f65040170755901ea6f48056 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/23fdd32b0180f6a0f65040170755901ea6f48056/tokio/src/runtime/scheduler/current_thread.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:5 | let handle = scheduler::Handle::CurrentThread(self.handle.clone());
let mut enter = crate::runtime::enter_runtime(&handle, false);
// Attempt to steal the scheduler core and block_on the future if we can
// there, otherwise, lets select on a notification that the core is
// available or... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 23fdd32b0180f6a0f65040170755901ea6f48056 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/23fdd32b0180f6a0f65040170755901ea6f48056/tokio/src/runtime/scheduler/current_thread.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:6 | handle: self.handle.clone(),
core: RefCell::new(Some(core)),
},
scheduler: self,
})
}
pub(crate) fn set_context_guard(&mut self, guard: SetCurrentGuard) {
self.context_guard = Some(guard);
}
}
impl Drop for CurrentThread {
fn drop(&mut self) {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 23fdd32b0180f6a0f65040170755901ea6f48056 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/23fdd32b0180f6a0f65040170755901ea6f48056/tokio/src/runtime/scheduler/current_thread.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:7 | if let Some(remote_queue) = remote_queue {
for task in remote_queue {
drop(task);
}
}
assert!(context.handle.shared.owned.is_empty());
// Submit metrics
core.metrics.submit(&self.handle.shared.worker_metrics);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 23fdd32b0180f6a0f65040170755901ea6f48056 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/23fdd32b0180f6a0f65040170755901ea6f48056/tokio/src/runtime/scheduler/current_thread.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:8 | self.tasks.push_back(task);
self.metrics.inc_local_schedule_count();
handle
.shared
.worker_metrics
.set_queue_depth(self.tasks.len());
}
}
// ===== impl Context =====
impl Context {
/// Execute the closure with the given scheduler core stored in the
///... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 23fdd32b0180f6a0f65040170755901ea6f48056 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/23fdd32b0180f6a0f65040170755901ea6f48056/tokio/src/runtime/scheduler/current_thread.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:9 | driver.park(&self.handle.driver);
});
core = c;
core.metrics.returned_from_park();
}
if let Some(f) = &self.handle.shared.config.after_unpark {
// Incorrect lint, the closures are actually different types so `f`
// cannot be passed as an argu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 23fdd32b0180f6a0f65040170755901ea6f48056 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/23fdd32b0180f6a0f65040170755901ea6f48056/tokio/src/runtime/scheduler/current_thread.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:10 | // Take the scheduler core back
let core = self.core.borrow_mut().take().expect("core missing");
(core, ret)
}
}
// ===== impl Handle =====
impl Handle {
/// Spawns a future onto the `CurrentThread` scheduler
pub(crate) fn spawn<F>(
me: &Arc<Self>,
future: F,
id: cr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 23fdd32b0180f6a0f65040170755901ea6f48056 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/23fdd32b0180f6a0f65040170755901ea6f48056/tokio/src/runtime/scheduler/current_thread.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:11 | waker_ref(me)
}
// reset woken to false and return original value
pub(crate) fn reset_woken(&self) -> bool {
self.shared.woken.swap(false, AcqRel)
}
}
cfg_metrics! {
impl Handle {
pub(crate) fn scheduler_metrics(&self) -> &SchedulerMetrics {
&self.shared.scheduler_metri... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 23fdd32b0180f6a0f65040170755901ea6f48056 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/23fdd32b0180f6a0f65040170755901ea6f48056/tokio/src/runtime/scheduler/current_thread.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:12 | self.blocking_spawner.queue_depth()
}
}
}
impl fmt::Debug for Handle {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("current_thread::Handle { ... }").finish()
}
}
// ===== impl Shared =====
impl Schedule for Arc<Handle> {
fn release(&self, task: &Task<... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 23fdd32b0180f6a0f65040170755901ea6f48056 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/23fdd32b0180f6a0f65040170755901ea6f48056/tokio/src/runtime/scheduler/current_thread.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:13 | }
}
});
}
cfg_unstable! {
fn unhandled_panic(&self) {
use crate::runtime::UnhandledPanic;
match self.shared.config.unhandled_panic {
UnhandledPanic::Ignore => {
// Do nothing
}
UnhandledPani... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 23fdd32b0180f6a0f65040170755901ea6f48056 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/23fdd32b0180f6a0f65040170755901ea6f48056/tokio/src/runtime/scheduler/current_thread.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:14 | /// Wake by reference
fn wake_by_ref(arc_self: &Arc<Self>) {
arc_self.shared.woken.store(true, Release);
arc_self.driver.unpark();
}
}
// ===== CoreGuard =====
/// Used to ensure we always place the `Core` value back into its slot in
/// `CurrentThread`, even if the future panics.
struct CoreG... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 23fdd32b0180f6a0f65040170755901ea6f48056 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/23fdd32b0180f6a0f65040170755901ea6f48056/tokio/src/runtime/scheduler/current_thread.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:15 | for _ in 0..handle.shared.config.event_interval {
// Make sure we didn't hit an unhandled_panic
if core.unhandled_panic {
return (core, None);
}
// Get and increment the current tick
let tick = c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 23fdd32b0180f6a0f65040170755901ea6f48056 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/23fdd32b0180f6a0f65040170755901ea6f48056/tokio/src/runtime/scheduler/current_thread.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:16 | match ret {
Some(ret) => ret,
None => {
// `block_on` panicked.
panic!("a spawned task panicked and the runtime is configured to shut down on unhandled panic");
}
}
}
/// Enters the scheduler context. This sets the queue and other nece... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 23fdd32b0180f6a0f65040170755901ea6f48056 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/23fdd32b0180f6a0f65040170755901ea6f48056/tokio/src/runtime/scheduler/current_thread.rs | 601 | 640 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:11 | waker_ref(me)
}
// reset woken to false and return original value
pub(crate) fn reset_woken(&self) -> bool {
self.shared.woken.swap(false, AcqRel)
}
}
cfg_metrics! {
impl Handle {
pub(crate) fn scheduler_metrics(&self) -> &SchedulerMetrics {
&self.shared.scheduler_metri... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 32da1aa9da833f6db59d6a97e2a569b780d9f6b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/32da1aa9da833f6db59d6a97e2a569b780d9f6b4/tokio/src/runtime/scheduler/current_thread.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:12 | impl Schedule for Arc<Handle> {
fn release(&self, task: &Task<Self>) -> Option<Task<Self>> {
self.shared.owned.remove(task)
}
fn schedule(&self, task: task::Notified<Self>) {
CURRENT.with(|maybe_cx| match maybe_cx {
Some(cx) if Arc::ptr_eq(self, &cx.handle) => {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 32da1aa9da833f6db59d6a97e2a569b780d9f6b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/32da1aa9da833f6db59d6a97e2a569b780d9f6b4/tokio/src/runtime/scheduler/current_thread.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:13 | }
UnhandledPanic::ShutdownRuntime => {
// This hook is only called from within the runtime, so
// `CURRENT` should match with `&self`, i.e. there is no
// opportunity for a nested scheduler to be called.
CURRENT.with(|maybe_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 32da1aa9da833f6db59d6a97e2a569b780d9f6b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/32da1aa9da833f6db59d6a97e2a569b780d9f6b4/tokio/src/runtime/scheduler/current_thread.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:14 | context: Context,
scheduler: &'a CurrentThread,
}
impl CoreGuard<'_> {
#[track_caller]
fn block_on<F: Future>(self, future: F) -> F::Output {
let ret = self.enter(|mut core, context| {
let waker = Handle::waker_ref(&context.handle);
let mut cx = std::task::Context::from_wake... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 32da1aa9da833f6db59d6a97e2a569b780d9f6b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/32da1aa9da833f6db59d6a97e2a569b780d9f6b4/tokio/src/runtime/scheduler/current_thread.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:15 | } else {
core.tasks.pop_front().or_else(|| handle.pop())
};
let task = match entry {
Some(entry) => entry,
None => {
core = context.park(core);
// Try... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 32da1aa9da833f6db59d6a97e2a569b780d9f6b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/32da1aa9da833f6db59d6a97e2a569b780d9f6b4/tokio/src/runtime/scheduler/current_thread.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:16 | fn enter<F, R>(self, f: F) -> R
where
F: FnOnce(Box<Core>, &Context) -> (Box<Core>, R),
{
// Remove `core` from `context` to pass into the closure.
let core = self.context.core.borrow_mut().take().expect("core missing");
// Call the closure and place `core` back
let (cor... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 32da1aa9da833f6db59d6a97e2a569b780d9f6b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/32da1aa9da833f6db59d6a97e2a569b780d9f6b4/tokio/src/runtime/scheduler/current_thread.rs | 601 | 628 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:4 | ) -> CurrentThread {
let handle = Arc::new(Handle {
shared: Shared {
queue: Mutex::new(Some(VecDeque::with_capacity(INITIAL_CAPACITY))),
owned: OwnedTasks::new(),
woken: AtomicBool::new(false),
config,
scheduler_metrics:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/current_thread.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:5 | // there, otherwise, lets select on a notification that the core is
// available or the future is complete.
loop {
if let Some(core) = self.take_core() {
return core.block_on(future);
} else {
let mut enter = crate::runtime::enter(false);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/current_thread.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:6 | })
}
pub(crate) fn set_context_guard(&mut self, guard: SetCurrentGuard) {
self.context_guard = Some(guard);
}
}
impl Drop for CurrentThread {
fn drop(&mut self) {
// Avoid a double panic if we are currently panicking and
// the lock may be poisoned.
let core = match se... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/current_thread.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:7 | }
assert!(context.handle.shared.owned.is_empty());
// Submit metrics
core.metrics.submit(&self.handle.shared.worker_metrics);
// Shutdown the resource drivers
if let Some(driver) = core.driver.as_mut() {
driver.shutdown(&self.handle.driver);... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/current_thread.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:8 | .worker_metrics
.set_queue_depth(self.tasks.len());
}
}
// ===== impl Context =====
impl Context {
/// Execute the closure with the given scheduler core stored in the
/// thread-local context.
fn run_task<R>(&self, mut core: Box<Core>, f: impl FnOnce() -> R) -> (Box<Core>, R) {
cor... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/current_thread.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:9 | core.metrics.returned_from_park();
}
if let Some(f) = &self.handle.shared.config.after_unpark {
// Incorrect lint, the closures are actually different types so `f`
// cannot be passed as an argument to `enter`.
#[allow(clippy::redundant_closure)]
let (c, ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/current_thread.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:10 | }
}
// ===== impl Handle =====
impl Handle {
/// Spawns a future onto the `CurrentThread` scheduler
pub(crate) fn spawn<F>(
me: &Arc<Self>,
future: F,
id: crate::runtime::task::Id,
) -> JoinHandle<F::Output>
where
F: crate::future::Future + Send + 'static,
F::Ou... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/current_thread.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:11 | pub(crate) fn reset_woken(&self) -> bool {
self.shared.woken.swap(false, AcqRel)
}
}
cfg_metrics! {
impl Handle {
pub(crate) fn scheduler_metrics(&self) -> &SchedulerMetrics {
&self.shared.scheduler_metrics
}
pub(crate) fn injection_queue_depth(&self) -> usize {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/current_thread.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:12 | }
fn schedule(&self, task: task::Notified<Self>) {
CURRENT.with(|maybe_cx| match maybe_cx {
Some(cx) if Arc::ptr_eq(self, &cx.handle) => {
let mut core = cx.core.borrow_mut();
// If `None`, the runtime is shutting down, so there is no need
// to ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/current_thread.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:13 | // opportunity for a nested scheduler to be called.
CURRENT.with(|maybe_cx| match maybe_cx {
Some(cx) if Arc::ptr_eq(self, &cx.handle) => {
let mut core = cx.core.borrow_mut();
// If `None`, the runtime is shutting down... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/current_thread.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:14 | impl CoreGuard<'_> {
#[track_caller]
fn block_on<F: Future>(self, future: F) -> F::Output {
let ret = self.enter(|mut core, context| {
let _enter = crate::runtime::enter(false);
let waker = Handle::waker_ref(&context.handle);
let mut cx = std::task::Context::from_wake... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/current_thread.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:15 | let task = match entry {
Some(entry) => entry,
None => {
core = context.park(core);
// Try polling the `block_on` future next
continue 'outer;
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/current_thread.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:16 | {
// Remove `core` from `context` to pass into the closure.
let core = self.context.core.borrow_mut().take().expect("core missing");
// Call the closure and place `core` back
let (core, ret) = CURRENT.set(&self.context, || f(core, &self.context));
*self.context.core.borrow_mut(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/current_thread.rs | 601 | 625 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:7 | }
assert!(context.handle.shared.owned.is_empty());
// Submit metrics
core.metrics.submit(&self.handle.shared.worker_metrics);
// Shutdown the resource drivers
if let Some(driver) = core.driver.as_mut() {
driver.shutdown(&self.handle.driver);... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | b1f40f4356c7f7be0e1959f992608d2058a76deb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1f40f4356c7f7be0e1959f992608d2058a76deb/tokio/src/runtime/scheduler/current_thread.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:8 | .worker_metrics
.set_queue_depth(self.tasks.len());
}
}
// ===== impl Context =====
impl Context {
/// Execute the closure with the given scheduler core stored in the
/// thread-local context.
fn run_task<R>(&self, mut core: Box<Core>, f: impl FnOnce() -> R) -> (Box<Core>, R) {
cor... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | b1f40f4356c7f7be0e1959f992608d2058a76deb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1f40f4356c7f7be0e1959f992608d2058a76deb/tokio/src/runtime/scheduler/current_thread.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:13 | // opportunity for a nested scheduler to be called.
CURRENT.with(|maybe_cx| match maybe_cx {
Some(cx) if Arc::ptr_eq(self, &cx.handle) => {
let mut core = cx.core.borrow_mut();
// If `None`, the runtime is shutting down... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | b1f40f4356c7f7be0e1959f992608d2058a76deb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1f40f4356c7f7be0e1959f992608d2058a76deb/tokio/src/runtime/scheduler/current_thread.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:14 | impl CoreGuard<'_> {
#[track_caller]
fn block_on<F: Future>(self, future: F) -> F::Output {
let ret = self.enter(|mut core, context| {
let _enter = crate::runtime::enter(false);
let waker = Handle::waker_ref(&context.handle);
let mut cx = std::task::Context::from_wake... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | b1f40f4356c7f7be0e1959f992608d2058a76deb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1f40f4356c7f7be0e1959f992608d2058a76deb/tokio/src/runtime/scheduler/current_thread.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:1 | use crate::future::poll_fn;
use crate::loom::sync::atomic::AtomicBool;
use crate::loom::sync::{Arc, Mutex};
use crate::runtime::context::EnterGuard;
use crate::runtime::driver::{self, Driver};
use crate::runtime::task::{self, JoinHandle, OwnedTasks, Schedule, Task};
use crate::runtime::{blocking, Config};
use crate::ru... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | df99428c17ff03134d8f081ee80ef0f6fbe3c813 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df99428c17ff03134d8f081ee80ef0f6fbe3c813/tokio/src/runtime/scheduler/current_thread.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:5 | // there, otherwise, lets select on a notification that the core is
// available or the future is complete.
loop {
if let Some(core) = self.take_core() {
return core.block_on(future);
} else {
let mut enter = crate::runtime::enter(false);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | df99428c17ff03134d8f081ee80ef0f6fbe3c813 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df99428c17ff03134d8f081ee80ef0f6fbe3c813/tokio/src/runtime/scheduler/current_thread.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:6 | })
}
pub(crate) fn set_context_guard(&mut self, guard: EnterGuard) {
self.context_guard = Some(guard);
}
}
impl Drop for CurrentThread {
fn drop(&mut self) {
// Avoid a double panic if we are currently panicking and
// the lock may be poisoned.
let core = match self.ta... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | df99428c17ff03134d8f081ee80ef0f6fbe3c813 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df99428c17ff03134d8f081ee80ef0f6fbe3c813/tokio/src/runtime/scheduler/current_thread.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:1 | use crate::future::poll_fn;
use crate::loom::sync::atomic::AtomicBool;
use crate::loom::sync::{Arc, Mutex};
use crate::runtime::driver::{self, Driver};
use crate::runtime::scheduler::EnterGuard;
use crate::runtime::task::{self, JoinHandle, OwnedTasks, Schedule, Task};
use crate::runtime::{blocking, Config};
use crate::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 2f244514346a37bf598d8fc1c593d68771eb6047 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2f244514346a37bf598d8fc1c593d68771eb6047/tokio/src/runtime/scheduler/current_thread.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:6 | })
}
pub(crate) fn set_context_guard(&mut self, guard: EnterGuard) {
self.context_guard = Some(guard);
}
}
impl Drop for CurrentThread {
fn drop(&mut self) {
// Avoid a double panic if we are currently panicking and
// the lock may be poisoned.
let core = match self.ta... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 0b92f80a6506c6a89eb998e5f61a33415353bba1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b92f80a6506c6a89eb998e5f61a33415353bba1/tokio/src/runtime/scheduler/current_thread.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:7 | }
assert!(context.handle.shared.owned.is_empty());
// Submit metrics
core.metrics.submit(&self.handle.shared.worker_metrics);
// Shutdown the resource drivers
if let Some(driver) = core.driver.as_mut() {
driver.shutdown();
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 0b92f80a6506c6a89eb998e5f61a33415353bba1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b92f80a6506c6a89eb998e5f61a33415353bba1/tokio/src/runtime/scheduler/current_thread.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/current_thread.rs:8 | .worker_metrics
.set_queue_depth(self.tasks.len());
}
}
// ===== impl Context =====
impl Context {
/// Execute the closure with the given scheduler core stored in the
/// thread-local context.
fn run_task<R>(&self, mut core: Box<Core>, f: impl FnOnce() -> R) -> (Box<Core>, R) {
cor... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/current_thread.rs | MIT | 0b92f80a6506c6a89eb998e5f61a33415353bba1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b92f80a6506c6a89eb998e5f61a33415353bba1/tokio/src/runtime/scheduler/current_thread.rs | 281 | 340 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.