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/multi_thread/worker.rs:17 | .transition_worker_to_parked(worker.index, self.is_searching);
// The worker is no longer searching. Setting this is the local cache
// only.
self.is_searching = false;
if is_last_searcher {
worker.handle.notify_if_work_pending();
}
true
}
/// Retu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/scheduler/multi_thread/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:18 | if !self.is_shutdown {
// Check if the scheduler has been shutdown
self.is_shutdown = worker.inject().is_closed();
}
}
/// Signals all tasks to shut down, and waits for them to complete. Must run
/// before we enter the single-threaded phase of shutdown processing.
fn pr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:19 | fn schedule(&self, task: Notified) {
self.schedule_task(task, false);
}
fn yield_now(&self, task: Notified) {
self.schedule_task(task, true);
}
}
impl Handle {
pub(super) fn schedule_task(&self, task: Notified, is_yield: bool) {
CURRENT.with(|maybe_cx| {
if let Some... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/scheduler/multi_thread/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:20 | .push_back(task, &self.shared.inject, &mut core.metrics);
true
} else {
// Push to the LIFO slot
let prev = core.lifo_slot.take();
let ret = prev.is_some();
if let Some(prev) = prev {
core.run_queue
.push_back(prev,... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:21 | }
}
fn notify_if_work_pending(&self) {
for remote in &self.shared.remotes[..] {
if !remote.steal.is_empty() {
self.notify_parked();
return;
}
}
if !self.shared.inject.is_empty() {
self.notify_parked();
}
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/scheduler/multi_thread/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:22 | }
// Drain the injection queue
//
// We already shut down every task, so we can simply drop the tasks.
while let Some(task) = self.shared.inject.pop() {
drop(task);
}
}
fn ptr_eq(&self, other: &Handle) -> bool {
std::ptr::eq(self, other)
}
}
cfg... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/runtime/scheduler/multi_thread/worker.rs | 841 | 866 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:2 | //! inject queue.
//!
//! The first case can only happen if the OwnedTasks::bind call happens before
//! or during step 1 of shutdown. In this case, the runtime will clean up the
//! task in step 3 of shutdown.
//!
//! In the latter case, the task was not spawned and the task is immediately
//! cancelled by the spaw... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 32da1aa9da833f6db59d6a97e2a569b780d9f6b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/32da1aa9da833f6db59d6a97e2a569b780d9f6b4/tokio/src/runtime/scheduler/multi_thread/worker.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:7 | launch.0.push(Arc::new(Worker {
handle: handle.clone(),
index,
core: AtomicCell::new(Some(core)),
}));
}
(handle, launch)
}
#[track_caller]
pub(crate) fn block_in_place<F, R>(f: F) -> R
where
F: FnOnce() -> R,
{
// Try to steal the worker core back
struc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 32da1aa9da833f6db59d6a97e2a569b780d9f6b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/32da1aa9da833f6db59d6a97e2a569b780d9f6b4/tokio/src/runtime/scheduler/multi_thread/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:8 | // We are on a thread pool runtime thread, so we just need to
// set up blocking.
had_entered = true;
}
(
EnterContext::Entered {
allow_block_in_place,
},
false,
) => {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 32da1aa9da833f6db59d6a97e2a569b780d9f6b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/32da1aa9da833f6db59d6a97e2a569b780d9f6b4/tokio/src/runtime/scheduler/multi_thread/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:9 | Some(core) => core,
None => return Ok(()),
};
// The parker should be set here
assert!(core.park.is_some());
// In order to block, the core must be sent to another thread for
// execution.
//
// First, move the core back into the worker's shared core... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 32da1aa9da833f6db59d6a97e2a569b780d9f6b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/32da1aa9da833f6db59d6a97e2a569b780d9f6b4/tokio/src/runtime/scheduler/multi_thread/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:10 | for worker in self.0.drain(..) {
runtime::spawn_blocking(move || run(worker));
}
}
}
fn run(worker: Arc<Worker>) {
// Acquire a core. If this fails, then another thread is running this
// worker and there is nothing further to do.
let core = match worker.core.take() {
Some(c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 32da1aa9da833f6db59d6a97e2a569b780d9f6b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/32da1aa9da833f6db59d6a97e2a569b780d9f6b4/tokio/src/runtime/scheduler/multi_thread/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:11 | if let Some(task) = core.next_task(&self.worker) {
core = self.run_task(task, core)?;
continue;
}
// There is no more **local** work to process, try to steal work
// from other workers.
if let Some(task) = core.steal_work(&self.worker) {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 32da1aa9da833f6db59d6a97e2a569b780d9f6b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/32da1aa9da833f6db59d6a97e2a569b780d9f6b4/tokio/src/runtime/scheduler/multi_thread/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:12 | // Check if we still have the core. If not, the core was stolen
// by another worker.
let mut core = match self.core.borrow_mut().take() {
Some(core) => core,
None => return Err(()),
};
// Check for a task in the LI... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 32da1aa9da833f6db59d6a97e2a569b780d9f6b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/32da1aa9da833f6db59d6a97e2a569b780d9f6b4/tokio/src/runtime/scheduler/multi_thread/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:13 | core
}
/// Parks the worker thread while waiting for tasks to execute.
///
/// This function checks if indeed there's no more work left to be done before parking.
/// Also important to notice that, before parking, the worker thread will try to take
/// ownership of the Driver (IO/Time) and disp... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 32da1aa9da833f6db59d6a97e2a569b780d9f6b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/32da1aa9da833f6db59d6a97e2a569b780d9f6b4/tokio/src/runtime/scheduler/multi_thread/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:14 | fn park_timeout(&self, mut core: Box<Core>, duration: Option<Duration>) -> Box<Core> {
// Take the parker out of core
let mut park = core.park.take().expect("park missing");
// Store `core` in context
*self.core.borrow_mut() = Some(core);
// Park thread
if let Some(time... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 32da1aa9da833f6db59d6a97e2a569b780d9f6b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/32da1aa9da833f6db59d6a97e2a569b780d9f6b4/tokio/src/runtime/scheduler/multi_thread/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:15 | } else {
self.next_local_task().or_else(|| worker.inject().pop())
}
}
fn next_local_task(&mut self) -> Option<Notified> {
self.lifo_slot.take().or_else(|| self.run_queue.pop())
}
/// Function responsible for stealing tasks from another worker
///
/// Note: Only if l... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 32da1aa9da833f6db59d6a97e2a569b780d9f6b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/32da1aa9da833f6db59d6a97e2a569b780d9f6b4/tokio/src/runtime/scheduler/multi_thread/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:16 | // Fallback on checking the global queue
worker.handle.shared.inject.pop()
}
fn transition_to_searching(&mut self, worker: &Worker) -> bool {
if !self.is_searching {
self.is_searching = worker.handle.shared.idle.transition_worker_to_searching();
}
self.is_searching
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 32da1aa9da833f6db59d6a97e2a569b780d9f6b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/32da1aa9da833f6db59d6a97e2a569b780d9f6b4/tokio/src/runtime/scheduler/multi_thread/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:17 | // only.
self.is_searching = false;
if is_last_searcher {
worker.handle.notify_if_work_pending();
}
true
}
/// Returns `true` if the transition happened.
fn transition_from_parked(&mut self, worker: &Worker) -> bool {
// If a task is in the lifo slot, t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 32da1aa9da833f6db59d6a97e2a569b780d9f6b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/32da1aa9da833f6db59d6a97e2a569b780d9f6b4/tokio/src/runtime/scheduler/multi_thread/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:18 | }
}
/// Signals all tasks to shut down, and waits for them to complete. Must run
/// before we enter the single-threaded phase of shutdown processing.
fn pre_shutdown(&mut self, worker: &Worker) {
// Signal to all tasks to shut down.
worker.handle.shared.owned.close_and_shutdown_all();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 32da1aa9da833f6db59d6a97e2a569b780d9f6b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/32da1aa9da833f6db59d6a97e2a569b780d9f6b4/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:19 | }
fn yield_now(&self, task: Notified) {
self.schedule_task(task, true);
}
}
impl Handle {
pub(super) fn schedule_task(&self, task: Notified, is_yield: bool) {
CURRENT.with(|maybe_cx| {
if let Some(cx) = maybe_cx {
// Make sure the task is part of the **current**... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 32da1aa9da833f6db59d6a97e2a569b780d9f6b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/32da1aa9da833f6db59d6a97e2a569b780d9f6b4/tokio/src/runtime/scheduler/multi_thread/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:20 | // Push to the LIFO slot
let prev = core.lifo_slot.take();
let ret = prev.is_some();
if let Some(prev) = prev {
core.run_queue
.push_back(prev, &self.shared.inject, &mut core.metrics);
}
core.lifo_slot = Some(task);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 32da1aa9da833f6db59d6a97e2a569b780d9f6b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/32da1aa9da833f6db59d6a97e2a569b780d9f6b4/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:21 | fn notify_if_work_pending(&self) {
for remote in &self.shared.remotes[..] {
if !remote.steal.is_empty() {
self.notify_parked();
return;
}
}
if !self.shared.inject.is_empty() {
self.notify_parked();
}
}
fn trans... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 32da1aa9da833f6db59d6a97e2a569b780d9f6b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/32da1aa9da833f6db59d6a97e2a569b780d9f6b4/tokio/src/runtime/scheduler/multi_thread/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:22 | //
// We already shut down every task, so we can simply drop the tasks.
while let Some(task) = self.shared.inject.pop() {
drop(task);
}
}
fn ptr_eq(&self, other: &Handle) -> bool {
std::ptr::eq(self, other)
}
}
cfg_metrics! {
impl Shared {
pub(super)... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 32da1aa9da833f6db59d6a97e2a569b780d9f6b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/32da1aa9da833f6db59d6a97e2a569b780d9f6b4/tokio/src/runtime/scheduler/multi_thread/worker.rs | 841 | 863 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:2 | //! inject queue.
//!
//! The first case can only happen if the OwnedTasks::bind call happens before
//! or during step 1 of shutdown. In this case, the runtime will clean up the
//! task in step 3 of shutdown.
//!
//! In the latter case, the task was not spawned and the task is immediately
//! cancelled by the spaw... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/multi_thread/worker.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:9 | Some(core) => core,
None => return Ok(()),
};
// The parker should be set here
assert!(core.park.is_some());
// In order to block, the core must be sent to another thread for
// execution.
//
// First, move the core back into the worker's shared core... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/multi_thread/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:10 | for worker in self.0.drain(..) {
runtime::spawn_blocking(move || run(worker));
}
}
}
fn run(worker: Arc<Worker>) {
// Acquire a core. If this fails, then another thread is running this
// worker and there is nothing further to do.
let core = match worker.core.take() {
Some(c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/multi_thread/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:11 | core = self.run_task(task, core)?;
continue;
}
// There is no more **local** work to process, try to steal work
// from other workers.
if let Some(task) = core.steal_work(&self.worker) {
core = self.run_task(task, core)?;
} els... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/multi_thread/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:12 | // by another worker.
let mut core = match self.core.borrow_mut().take() {
Some(core) => core,
None => return Err(()),
};
// Check for a task in the LIFO slot
let task = match core.lifo_slot.take() {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/multi_thread/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:13 | }
/// Parks the worker thread while waiting for tasks to execute.
///
/// This function checks if indeed there's no more work left to be done before parking.
/// Also important to notice that, before parking, the worker thread will try to take
/// ownership of the Driver (IO/Time) and dispatch any ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/multi_thread/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:14 | // Take the parker out of core
let mut park = core.park.take().expect("park missing");
// Store `core` in context
*self.core.borrow_mut() = Some(core);
// Park thread
if let Some(timeout) = duration {
park.park_timeout(&self.worker.handle.driver, timeout);
}... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/multi_thread/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:15 | self.next_local_task().or_else(|| worker.inject().pop())
}
}
fn next_local_task(&mut self) -> Option<Notified> {
self.lifo_slot.take().or_else(|| self.run_queue.pop())
}
/// Function responsible for stealing tasks from another worker
///
/// Note: Only if less than half the wor... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/multi_thread/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:16 | worker.handle.shared.inject.pop()
}
fn transition_to_searching(&mut self, worker: &Worker) -> bool {
if !self.is_searching {
self.is_searching = worker.handle.shared.idle.transition_worker_to_searching();
}
self.is_searching
}
fn transition_from_searching(&mut self... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/multi_thread/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:17 | self.is_searching = false;
if is_last_searcher {
worker.handle.notify_if_work_pending();
}
true
}
/// Returns `true` if the transition happened.
fn transition_from_parked(&mut self, worker: &Worker) -> bool {
// If a task is in the lifo slot, then we must unpar... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/multi_thread/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:18 | }
/// Signals all tasks to shut down, and waits for them to complete. Must run
/// before we enter the single-threaded phase of shutdown processing.
fn pre_shutdown(&mut self, worker: &Worker) {
// Signal to all tasks to shut down.
worker.handle.shared.owned.close_and_shutdown_all();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:19 | fn yield_now(&self, task: Notified) {
self.schedule_task(task, true);
}
}
impl Handle {
pub(super) fn schedule_task(&self, task: Notified, is_yield: bool) {
CURRENT.with(|maybe_cx| {
if let Some(cx) = maybe_cx {
// Make sure the task is part of the **current** schedu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/multi_thread/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:20 | let prev = core.lifo_slot.take();
let ret = prev.is_some();
if let Some(prev) = prev {
core.run_queue
.push_back(prev, &self.shared.inject, &mut core.metrics);
}
core.lifo_slot = Some(task);
ret
};
// Onl... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:21 | for remote in &self.shared.remotes[..] {
if !remote.steal.is_empty() {
self.notify_parked();
return;
}
}
if !self.shared.inject.is_empty() {
self.notify_parked();
}
}
fn transition_worker_from_searching(&self) {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/multi_thread/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:22 | // We already shut down every task, so we can simply drop the tasks.
while let Some(task) = self.shared.inject.pop() {
drop(task);
}
}
fn ptr_eq(&self, other: &Handle) -> bool {
std::ptr::eq(self, other)
}
}
cfg_metrics! {
impl Shared {
pub(super) fn injecti... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/runtime/scheduler/multi_thread/worker.rs | 841 | 862 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:2 | //! inject queue.
//!
//! The first case can only happen if the OwnedTasks::bind call happens before
//! or during step 1 of shutdown. In this case, the runtime will clean up the
//! task in step 3 of shutdown.
//!
//! In the latter case, the task was not spawned and the task is immediately
//! cancelled by the spaw... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b1f40f4356c7f7be0e1959f992608d2058a76deb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1f40f4356c7f7be0e1959f992608d2058a76deb/tokio/src/runtime/scheduler/multi_thread/worker.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:3 | /// Used to hand-off a worker's core to another thread.
core: AtomicCell<Core>,
}
/// Core data
struct Core {
/// Used to schedule bookkeeping tasks every so often.
tick: u32,
/// When a task is scheduled from a worker, it is stored in this slot. The
/// worker will check this slot for a task **be... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b1f40f4356c7f7be0e1959f992608d2058a76deb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1f40f4356c7f7be0e1959f992608d2058a76deb/tokio/src/runtime/scheduler/multi_thread/worker.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:4 | /// State shared across all workers
pub(super) struct Shared {
/// Per-worker remote state. All other workers have access to this and is
/// how they communicate between each other.
remotes: Box<[Remote]>,
/// Global task queue used for:
/// 1. Submit work to the scheduler while **not** currently ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b1f40f4356c7f7be0e1959f992608d2058a76deb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1f40f4356c7f7be0e1959f992608d2058a76deb/tokio/src/runtime/scheduler/multi_thread/worker.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:5 | }
/// Thread-local context
struct Context {
/// Worker
worker: Arc<Worker>,
/// Core data
core: RefCell<Option<Box<Core>>>,
}
/// Starts the workers
pub(crate) struct Launch(Vec<Arc<Worker>>);
/// Running a task may consume the core. If the core is still available when
/// running the task completes... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b1f40f4356c7f7be0e1959f992608d2058a76deb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1f40f4356c7f7be0e1959f992608d2058a76deb/tokio/src/runtime/scheduler/multi_thread/worker.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:6 | // Create the local queues
for _ in 0..size {
let (steal, run_queue) = queue::local();
let park = park.clone();
let unpark = park.unpark();
cores.push(Box::new(Core {
tick: 0,
lifo_slot: None,
run_queue,
is_searching: false,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b1f40f4356c7f7be0e1959f992608d2058a76deb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1f40f4356c7f7be0e1959f992608d2058a76deb/tokio/src/runtime/scheduler/multi_thread/worker.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:7 | for (index, core) in cores.drain(..).enumerate() {
launch.0.push(Arc::new(Worker {
handle: handle.clone(),
index,
core: AtomicCell::new(Some(core)),
}));
}
(handle, launch)
}
#[track_caller]
pub(crate) fn block_in_place<F, R>(f: F) -> R
where
F: FnOnce()... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b1f40f4356c7f7be0e1959f992608d2058a76deb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1f40f4356c7f7be0e1959f992608d2058a76deb/tokio/src/runtime/scheduler/multi_thread/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:8 | (EnterContext::Entered { .. }, true) => {
// We are on a thread pool runtime thread, so we just need to
// set up blocking.
had_entered = true;
}
(
EnterContext::Entered {
allow_block_in_place,
},... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b1f40f4356c7f7be0e1959f992608d2058a76deb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1f40f4356c7f7be0e1959f992608d2058a76deb/tokio/src/runtime/scheduler/multi_thread/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:9 | let core = match cx.core.borrow_mut().take() {
Some(core) => core,
None => return Ok(()),
};
// The parker should be set here
assert!(core.park.is_some());
// In order to block, the core must be sent to another thread for
// execution.
//
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b1f40f4356c7f7be0e1959f992608d2058a76deb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1f40f4356c7f7be0e1959f992608d2058a76deb/tokio/src/runtime/scheduler/multi_thread/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:10 | pub(crate) fn launch(mut self) {
for worker in self.0.drain(..) {
runtime::spawn_blocking(move || run(worker));
}
}
}
fn run(worker: Arc<Worker>) {
// Acquire a core. If this fails, then another thread is running this
// worker and there is nothing further to do.
let core = ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b1f40f4356c7f7be0e1959f992608d2058a76deb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1f40f4356c7f7be0e1959f992608d2058a76deb/tokio/src/runtime/scheduler/multi_thread/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:7 | for (index, core) in cores.drain(..).enumerate() {
launch.0.push(Arc::new(Worker {
handle: handle.clone(),
index,
core: AtomicCell::new(Some(core)),
}));
}
(handle, launch)
}
#[track_caller]
pub(crate) fn block_in_place<F, R>(f: F) -> R
where
F: FnOnce()... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | df99428c17ff03134d8f081ee80ef0f6fbe3c813 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df99428c17ff03134d8f081ee80ef0f6fbe3c813/tokio/src/runtime/scheduler/multi_thread/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:8 | (EnterContext::Entered { .. }, true) => {
// We are on a thread pool runtime thread, so we just need to
// set up blocking.
had_entered = true;
}
(EnterContext::Entered { allow_blocking }, false) => {
// We are on an executor, but _... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | df99428c17ff03134d8f081ee80ef0f6fbe3c813 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df99428c17ff03134d8f081ee80ef0f6fbe3c813/tokio/src/runtime/scheduler/multi_thread/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:9 | // The parker should be set here
assert!(core.park.is_some());
// In order to block, the core must be sent to another thread for
// execution.
//
// First, move the core back into the worker's shared core slot.
cx.worker.core.set(core);
// Next, clone the worker... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | df99428c17ff03134d8f081ee80ef0f6fbe3c813 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df99428c17ff03134d8f081ee80ef0f6fbe3c813/tokio/src/runtime/scheduler/multi_thread/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:10 | }
fn run(worker: Arc<Worker>) {
// Acquire a core. If this fails, then another thread is running this
// worker and there is nothing further to do.
let core = match worker.core.take() {
Some(core) => core,
None => return,
};
// Set the worker context.
let cx = Context {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | df99428c17ff03134d8f081ee80ef0f6fbe3c813 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df99428c17ff03134d8f081ee80ef0f6fbe3c813/tokio/src/runtime/scheduler/multi_thread/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:11 | // There is no more **local** work to process, try to steal work
// from other workers.
if let Some(task) = core.steal_work(&self.worker) {
core = self.run_task(task, core)?;
} else {
// Wait for work
core = self.park(core);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | df99428c17ff03134d8f081ee80ef0f6fbe3c813 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df99428c17ff03134d8f081ee80ef0f6fbe3c813/tokio/src/runtime/scheduler/multi_thread/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:12 | };
// Check for a task in the LIFO slot
let task = match core.lifo_slot.take() {
Some(task) => task,
None => return Ok(core),
};
if coop::has_budget_remaining() {
// Run the LIFO task, then loop... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | df99428c17ff03134d8f081ee80ef0f6fbe3c813 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df99428c17ff03134d8f081ee80ef0f6fbe3c813/tokio/src/runtime/scheduler/multi_thread/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:13 | /// This function checks if indeed there's no more work left to be done before parking.
/// Also important to notice that, before parking, the worker thread will try to take
/// ownership of the Driver (IO/Time) and dispatch any events that might have fired.
/// Whenever a worker thread executes the Driver ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | df99428c17ff03134d8f081ee80ef0f6fbe3c813 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df99428c17ff03134d8f081ee80ef0f6fbe3c813/tokio/src/runtime/scheduler/multi_thread/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:14 | *self.core.borrow_mut() = Some(core);
// Park thread
if let Some(timeout) = duration {
park.park_timeout(&self.worker.handle.driver, timeout);
} else {
park.park(&self.worker.handle.driver);
}
// Remove `core` from context
core = self.core.borrow... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | df99428c17ff03134d8f081ee80ef0f6fbe3c813 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df99428c17ff03134d8f081ee80ef0f6fbe3c813/tokio/src/runtime/scheduler/multi_thread/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:15 | fn next_local_task(&mut self) -> Option<Notified> {
self.lifo_slot.take().or_else(|| self.run_queue.pop())
}
/// Function responsible for stealing tasks from another worker
///
/// Note: Only if less than half the workers are searching for tasks to steal
/// a new worker will actually try t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | df99428c17ff03134d8f081ee80ef0f6fbe3c813 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df99428c17ff03134d8f081ee80ef0f6fbe3c813/tokio/src/runtime/scheduler/multi_thread/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:16 | if !self.is_searching {
self.is_searching = worker.handle.shared.idle.transition_worker_to_searching();
}
self.is_searching
}
fn transition_from_searching(&mut self, worker: &Worker) {
if !self.is_searching {
return;
}
self.is_searching = false;... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | df99428c17ff03134d8f081ee80ef0f6fbe3c813 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df99428c17ff03134d8f081ee80ef0f6fbe3c813/tokio/src/runtime/scheduler/multi_thread/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:17 | }
true
}
/// Returns `true` if the transition happened.
fn transition_from_parked(&mut self, worker: &Worker) -> bool {
// If a task is in the lifo slot, then we must unpark regardless of
// being notified
if self.lifo_slot.is_some() {
// When a worker wakes, it... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | df99428c17ff03134d8f081ee80ef0f6fbe3c813 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df99428c17ff03134d8f081ee80ef0f6fbe3c813/tokio/src/runtime/scheduler/multi_thread/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:18 | fn pre_shutdown(&mut self, worker: &Worker) {
// Signal to all tasks to shut down.
worker.handle.shared.owned.close_and_shutdown_all();
self.metrics
.submit(&worker.handle.shared.worker_metrics[worker.index]);
}
/// Shuts down the core.
fn shutdown(&mut self, handle: &H... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | df99428c17ff03134d8f081ee80ef0f6fbe3c813 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df99428c17ff03134d8f081ee80ef0f6fbe3c813/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:19 | }
impl Handle {
pub(super) fn schedule_task(&self, task: Notified, is_yield: bool) {
CURRENT.with(|maybe_cx| {
if let Some(cx) = maybe_cx {
// Make sure the task is part of the **current** scheduler.
if self.ptr_eq(&cx.worker.handle) {
// And ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | df99428c17ff03134d8f081ee80ef0f6fbe3c813 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df99428c17ff03134d8f081ee80ef0f6fbe3c813/tokio/src/runtime/scheduler/multi_thread/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:20 | core.run_queue
.push_back(prev, &self.shared.inject, &mut core.metrics);
}
core.lifo_slot = Some(task);
ret
};
// Only notify if not currently parked. If `park` is `None`, then the
// scheduling is from a resource driver. As notification... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | df99428c17ff03134d8f081ee80ef0f6fbe3c813 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df99428c17ff03134d8f081ee80ef0f6fbe3c813/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:21 | }
}
if !self.shared.inject.is_empty() {
self.notify_parked();
}
}
fn transition_worker_from_searching(&self) {
if self.shared.idle.transition_worker_from_searching() {
// We are the final searching worker. Because work was found, we
// need t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | df99428c17ff03134d8f081ee80ef0f6fbe3c813 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df99428c17ff03134d8f081ee80ef0f6fbe3c813/tokio/src/runtime/scheduler/multi_thread/worker.rs | 801 | 858 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:22 | }
fn ptr_eq(&self, other: &Handle) -> bool {
std::ptr::eq(self, other)
}
}
cfg_metrics! {
impl Shared {
pub(super) fn injection_queue_depth(&self) -> usize {
self.inject.len()
}
pub(super) fn worker_local_queue_depth(&self, worker: usize) -> usize {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | df99428c17ff03134d8f081ee80ef0f6fbe3c813 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df99428c17ff03134d8f081ee80ef0f6fbe3c813/tokio/src/runtime/scheduler/multi_thread/worker.rs | 841 | 858 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:2 | //! inject queue.
//!
//! The first case can only happen if the OwnedTasks::bind call happens before
//! or during step 1 of shutdown. In this case, the runtime will clean up the
//! task in step 3 of shutdown.
//!
//! In the latter case, the task was not spawned and the task is immediately
//! cancelled by the spaw... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | a03e0420249d1740668f608a5a16f1fa614be2c7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a03e0420249d1740668f608a5a16f1fa614be2c7/tokio/src/runtime/scheduler/multi_thread/worker.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:13 | /// This function checks if indeed there's no more work left to be done before parking.
/// Also important to notice that, before parking, the worker thread will try to take
/// ownership of the Driver (IO/Time) and dispatch any events that might have fired.
/// Whenever a worker thread executes the Driver ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 7096a8007502526b23ee1707a6cb37c68c4f0a84 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7096a8007502526b23ee1707a6cb37c68c4f0a84/tokio/src/runtime/scheduler/multi_thread/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:14 | *self.core.borrow_mut() = Some(core);
// Park thread
if let Some(timeout) = duration {
park.park_timeout(timeout);
} else {
park.park();
}
// Remove `core` from context
core = self.core.borrow_mut().take().expect("core missing");
// Plac... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 7096a8007502526b23ee1707a6cb37c68c4f0a84 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7096a8007502526b23ee1707a6cb37c68c4f0a84/tokio/src/runtime/scheduler/multi_thread/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:17 | }
true
}
/// Returns `true` if the transition happened.
fn transition_from_parked(&mut self, worker: &Worker) -> bool {
// If a task is in the lifo slot, then we must unpark regardless of
// being notified
if self.lifo_slot.is_some() {
// When a worker wakes, it... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 7096a8007502526b23ee1707a6cb37c68c4f0a84 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7096a8007502526b23ee1707a6cb37c68c4f0a84/tokio/src/runtime/scheduler/multi_thread/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:18 | fn pre_shutdown(&mut self, worker: &Worker) {
// Signal to all tasks to shut down.
worker.handle.shared.owned.close_and_shutdown_all();
self.metrics
.submit(&worker.handle.shared.worker_metrics[worker.index]);
}
/// Shuts down the core.
fn shutdown(&mut self) {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 7096a8007502526b23ee1707a6cb37c68c4f0a84 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7096a8007502526b23ee1707a6cb37c68c4f0a84/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:21 | }
}
if !self.shared.inject.is_empty() {
self.notify_parked();
}
}
fn transition_worker_from_searching(&self) {
if self.shared.idle.transition_worker_from_searching() {
// We are the final searching worker. Because work was found, we
// need t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 7096a8007502526b23ee1707a6cb37c68c4f0a84 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7096a8007502526b23ee1707a6cb37c68c4f0a84/tokio/src/runtime/scheduler/multi_thread/worker.rs | 801 | 858 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:6 | // Create the local queues
for _ in 0..size {
let (steal, run_queue) = queue::local();
let park = park.clone();
let unpark = park.unpark();
cores.push(Box::new(Core {
tick: 0,
lifo_slot: None,
run_queue,
is_searching: false,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 0b92f80a6506c6a89eb998e5f61a33415353bba1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b92f80a6506c6a89eb998e5f61a33415353bba1/tokio/src/runtime/scheduler/multi_thread/worker.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:7 | for (index, core) in cores.drain(..).enumerate() {
launch.0.push(Arc::new(Worker {
handle: handle.clone(),
index,
core: AtomicCell::new(Some(core)),
}));
}
(handle, launch)
}
pub(crate) fn block_in_place<F, R>(f: F) -> R
where
F: FnOnce() -> R,
{
// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 0b92f80a6506c6a89eb998e5f61a33415353bba1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b92f80a6506c6a89eb998e5f61a33415353bba1/tokio/src/runtime/scheduler/multi_thread/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:8 | // We are on a thread pool runtime thread, so we just need to
// set up blocking.
had_entered = true;
}
(EnterContext::Entered { allow_blocking }, false) => {
// We are on an executor, but _not_ on the thread pool. That is
// _only... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 0b92f80a6506c6a89eb998e5f61a33415353bba1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b92f80a6506c6a89eb998e5f61a33415353bba1/tokio/src/runtime/scheduler/multi_thread/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:9 | // In order to block, the core must be sent to another thread for
// execution.
//
// First, move the core back into the worker's shared core slot.
cx.worker.core.set(core);
// Next, clone the worker handle and send it to a new thread for
// processing.
//
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 0b92f80a6506c6a89eb998e5f61a33415353bba1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b92f80a6506c6a89eb998e5f61a33415353bba1/tokio/src/runtime/scheduler/multi_thread/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:10 | };
// Set the worker context.
let cx = Context {
worker,
core: RefCell::new(None),
};
let _enter = crate::runtime::enter(true);
CURRENT.set(&cx, || {
// This should always be an error. It only returns a `Result` to support
// using `?` to short circuit.
ass... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 0b92f80a6506c6a89eb998e5f61a33415353bba1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b92f80a6506c6a89eb998e5f61a33415353bba1/tokio/src/runtime/scheduler/multi_thread/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:11 | }
core.pre_shutdown(&self.worker);
// Signal shutdown
self.worker.handle.shutdown_core(core);
Err(())
}
fn run_task(&self, task: Notified, mut core: Box<Core>) -> RunResult {
let task = self.worker.handle.shared.owned.assert_owner(task);
// Make sure the worke... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 0b92f80a6506c6a89eb998e5f61a33415353bba1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b92f80a6506c6a89eb998e5f61a33415353bba1/tokio/src/runtime/scheduler/multi_thread/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:12 | if coop::has_budget_remaining() {
// Run the LIFO task, then loop
core.metrics.incr_poll_count();
*self.core.borrow_mut() = Some(core);
let task = self.worker.handle.shared.owned.assert_owner(task);
task.run();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 0b92f80a6506c6a89eb998e5f61a33415353bba1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b92f80a6506c6a89eb998e5f61a33415353bba1/tokio/src/runtime/scheduler/multi_thread/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:13 | /// after all the IOs get dispatched
fn park(&self, mut core: Box<Core>) -> Box<Core> {
if let Some(f) = &self.worker.handle.shared.config.before_park {
f();
}
if core.transition_to_parked(&self.worker) {
while !core.is_shutdown {
core.metrics.about_t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 0b92f80a6506c6a89eb998e5f61a33415353bba1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b92f80a6506c6a89eb998e5f61a33415353bba1/tokio/src/runtime/scheduler/multi_thread/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:14 | // Remove `core` from context
core = self.core.borrow_mut().take().expect("core missing");
// Place `park` back in `core`
core.park = Some(park);
// If there are tasks available to steal, but this worker is not
// looking for tasks to steal, notify another worker.
if !c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 0b92f80a6506c6a89eb998e5f61a33415353bba1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b92f80a6506c6a89eb998e5f61a33415353bba1/tokio/src/runtime/scheduler/multi_thread/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:15 | /// workers will be trying to steal at the same time.
fn steal_work(&mut self, worker: &Worker) -> Option<Notified> {
if !self.transition_to_searching(worker) {
return None;
}
let num = worker.handle.shared.remotes.len();
// Start from a random worker
let start =... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 0b92f80a6506c6a89eb998e5f61a33415353bba1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b92f80a6506c6a89eb998e5f61a33415353bba1/tokio/src/runtime/scheduler/multi_thread/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:16 | if !self.is_searching {
return;
}
self.is_searching = false;
worker.handle.transition_worker_from_searching();
}
/// Prepares the worker state for parking.
///
/// Returns true if the transition happened, false if there is work to do first.
fn transition_to_park... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 0b92f80a6506c6a89eb998e5f61a33415353bba1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b92f80a6506c6a89eb998e5f61a33415353bba1/tokio/src/runtime/scheduler/multi_thread/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:17 | // being notified
if self.lifo_slot.is_some() {
// When a worker wakes, it should only transition to the "searching"
// state when the wake originates from another worker *or* a new task
// is pushed. We do *not* want the worker to transition to "searching"
// whe... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 0b92f80a6506c6a89eb998e5f61a33415353bba1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b92f80a6506c6a89eb998e5f61a33415353bba1/tokio/src/runtime/scheduler/multi_thread/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:18 | /// Shuts down the core.
fn shutdown(&mut self) {
// Take the core
let mut park = self.park.take().expect("park missing");
// Drain the queue
while self.next_local_task().is_some() {}
park.shutdown();
}
}
impl Worker {
/// Returns a reference to the scheduler's inj... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 0b92f80a6506c6a89eb998e5f61a33415353bba1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b92f80a6506c6a89eb998e5f61a33415353bba1/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:19 | // And the current thread still holds a core
if let Some(core) = cx.core.borrow_mut().as_mut() {
self.schedule_local(core, task, is_yield);
return;
}
}
}
// Otherwise, use the inject queue.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 0b92f80a6506c6a89eb998e5f61a33415353bba1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b92f80a6506c6a89eb998e5f61a33415353bba1/tokio/src/runtime/scheduler/multi_thread/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:20 | // Only notify if not currently parked. If `park` is `None`, then the
// scheduling is from a resource driver. As notifications often come in
// batches, the notification is delayed until the park is complete.
if should_notify && core.park.is_some() {
self.notify_parked();
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 0b92f80a6506c6a89eb998e5f61a33415353bba1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b92f80a6506c6a89eb998e5f61a33415353bba1/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:21 | fn transition_worker_from_searching(&self) {
if self.shared.idle.transition_worker_from_searching() {
// We are the final searching worker. Because work was found, we
// need to notify another worker.
self.notify_parked();
}
}
/// Signals that a worker has ob... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 0b92f80a6506c6a89eb998e5f61a33415353bba1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b92f80a6506c6a89eb998e5f61a33415353bba1/tokio/src/runtime/scheduler/multi_thread/worker.rs | 801 | 850 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:22 | impl Shared {
pub(super) fn injection_queue_depth(&self) -> usize {
self.inject.len()
}
pub(super) fn worker_local_queue_depth(&self, worker: usize) -> usize {
self.remotes[worker].steal.len()
}
}
} | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 0b92f80a6506c6a89eb998e5f61a33415353bba1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b92f80a6506c6a89eb998e5f61a33415353bba1/tokio/src/runtime/scheduler/multi_thread/worker.rs | 841 | 850 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:3 | /// Used to hand-off a worker's core to another thread.
core: AtomicCell<Core>,
}
/// Core data
struct Core {
/// Used to schedule bookkeeping tasks every so often.
tick: u32,
/// When a task is scheduled from a worker, it is stored in this slot. The
/// worker will check this slot for a task **be... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cba5c1009e3a1e6a0e87afcd380f2427485785ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cba5c1009e3a1e6a0e87afcd380f2427485785ec/tokio/src/runtime/scheduler/multi_thread/worker.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:4 | /// State shared across all workers
pub(super) struct Shared {
/// Per-worker remote state. All other workers have access to this and is
/// how they communicate between each other.
remotes: Box<[Remote]>,
/// Used to unpark threads blocked on the I/O driver
driver: driver::Unpark,
/// Global ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cba5c1009e3a1e6a0e87afcd380f2427485785ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cba5c1009e3a1e6a0e87afcd380f2427485785ec/tokio/src/runtime/scheduler/multi_thread/worker.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:5 | /// Unparks the associated worker thread
unpark: Unparker,
}
/// Thread-local context
struct Context {
/// Worker
worker: Arc<Worker>,
/// Core data
core: RefCell<Option<Box<Core>>>,
}
/// Starts the workers
pub(crate) struct Launch(Vec<Arc<Worker>>);
/// Running a task may consume the core. If ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cba5c1009e3a1e6a0e87afcd380f2427485785ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cba5c1009e3a1e6a0e87afcd380f2427485785ec/tokio/src/runtime/scheduler/multi_thread/worker.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:6 | let mut cores = Vec::with_capacity(size);
let mut remotes = Vec::with_capacity(size);
let mut worker_metrics = Vec::with_capacity(size);
// Create the local queues
for _ in 0..size {
let (steal, run_queue) = queue::local();
let park = park.clone();
let unpark = park.unpark();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cba5c1009e3a1e6a0e87afcd380f2427485785ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cba5c1009e3a1e6a0e87afcd380f2427485785ec/tokio/src/runtime/scheduler/multi_thread/worker.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:7 | seed_generator,
});
let mut launch = Launch(vec![]);
for (index, core) in cores.drain(..).enumerate() {
launch.0.push(Arc::new(Worker {
handle: handle.clone(),
index,
core: AtomicCell::new(Some(core)),
}));
}
(handle, launch)
}
pub(crate) fn bl... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cba5c1009e3a1e6a0e87afcd380f2427485785ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cba5c1009e3a1e6a0e87afcd380f2427485785ec/tokio/src/runtime/scheduler/multi_thread/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:8 | let mut had_entered = false;
CURRENT.with(|maybe_cx| {
match (crate::runtime::enter::context(), maybe_cx.is_some()) {
(EnterContext::Entered { .. }, true) => {
// We are on a thread pool runtime thread, so we just need to
// set up blocking.
had_e... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cba5c1009e3a1e6a0e87afcd380f2427485785ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cba5c1009e3a1e6a0e87afcd380f2427485785ec/tokio/src/runtime/scheduler/multi_thread/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:9 | };
// The parker should be set here
assert!(core.park.is_some());
// In order to block, the core must be sent to another thread for
// execution.
//
// First, move the core back into the worker's shared core slot.
cx.worker.core.set(core);
// Next, clon... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cba5c1009e3a1e6a0e87afcd380f2427485785ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cba5c1009e3a1e6a0e87afcd380f2427485785ec/tokio/src/runtime/scheduler/multi_thread/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:10 | // Acquire a core. If this fails, then another thread is running this
// worker and there is nothing further to do.
let core = match worker.core.take() {
Some(core) => core,
None => return,
};
// Set the worker context.
let cx = Context {
worker,
core: RefCell::new(N... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cba5c1009e3a1e6a0e87afcd380f2427485785ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cba5c1009e3a1e6a0e87afcd380f2427485785ec/tokio/src/runtime/scheduler/multi_thread/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:11 | core = self.run_task(task, core)?;
} else {
// Wait for work
core = self.park(core);
}
}
core.pre_shutdown(&self.worker);
// Signal shutdown
self.worker.handle.shared.shutdown(core);
Err(())
}
fn run_task(&self, t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cba5c1009e3a1e6a0e87afcd380f2427485785ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cba5c1009e3a1e6a0e87afcd380f2427485785ec/tokio/src/runtime/scheduler/multi_thread/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:12 | let task = match core.lifo_slot.take() {
Some(task) => task,
None => return Ok(core),
};
if coop::has_budget_remaining() {
// Run the LIFO task, then loop
core.metrics.incr_poll_count();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cba5c1009e3a1e6a0e87afcd380f2427485785ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cba5c1009e3a1e6a0e87afcd380f2427485785ec/tokio/src/runtime/scheduler/multi_thread/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:13 | /// Whenever a worker thread executes the Driver loop, all waken tasks are scheduled
/// in its own local queue until the queue saturates (ntasks > LOCAL_QUEUE_CAPACITY).
/// When the local queue is saturated, the overflow tasks are added to the injection queue
/// from where other workers can pick them up.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cba5c1009e3a1e6a0e87afcd380f2427485785ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cba5c1009e3a1e6a0e87afcd380f2427485785ec/tokio/src/runtime/scheduler/multi_thread/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:14 | if let Some(timeout) = duration {
park.park_timeout(timeout);
} else {
park.park();
}
// Remove `core` from context
core = self.core.borrow_mut().take().expect("core missing");
// Place `park` back in `core`
core.park = Some(park);
// If... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cba5c1009e3a1e6a0e87afcd380f2427485785ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cba5c1009e3a1e6a0e87afcd380f2427485785ec/tokio/src/runtime/scheduler/multi_thread/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:15 | /// Function responsible for stealing tasks from another worker
///
/// Note: Only if less than half the workers are searching for tasks to steal
/// a new worker will actually try to steal. The idea is to make sure not all
/// workers will be trying to steal at the same time.
fn steal_work(&mut sel... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cba5c1009e3a1e6a0e87afcd380f2427485785ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cba5c1009e3a1e6a0e87afcd380f2427485785ec/tokio/src/runtime/scheduler/multi_thread/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:16 | self.is_searching
}
fn transition_from_searching(&mut self, worker: &Worker) {
if !self.is_searching {
return;
}
self.is_searching = false;
worker.handle.shared.transition_worker_from_searching();
}
/// Prepares the worker state for parking.
///
///... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cba5c1009e3a1e6a0e87afcd380f2427485785ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cba5c1009e3a1e6a0e87afcd380f2427485785ec/tokio/src/runtime/scheduler/multi_thread/worker.rs | 601 | 660 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.