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:6 | ) -> (Arc<Handle>, Launch) {
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();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a94eb089343e1efa9563b91e13c79a0e61b2364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a94eb089343e1efa9563b91e13c79a0e61b2364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:7 | driver: driver_handle,
blocking_spawner,
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)),
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a94eb089343e1efa9563b91e13c79a0e61b2364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a94eb089343e1efa9563b91e13c79a0e61b2364/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;
let setup_result = CURRENT.with(|maybe_cx| {
match (
crate::runtime::context::current_enter_context(),
maybe_cx.is_some(),
) {
(context::EnterRuntime::Entered { .. }, true) => {
// We are on a thread pool ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a94eb089343e1efa9563b91e13c79a0e61b2364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a94eb089343e1efa9563b91e13c79a0e61b2364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:10 | // constrained by task budgets.
let _reset = Reset(coop::stop());
crate::runtime::context::exit_runtime(f)
} else {
f()
}
}
impl Launch {
pub(crate) fn launch(mut self) {
for worker in self.0.drain(..) {
runtime::spawn_blocking(move || run(worker));
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a94eb089343e1efa9563b91e13c79a0e61b2364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a94eb089343e1efa9563b91e13c79a0e61b2364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:11 | let handle = scheduler::Handle::MultiThread(worker.handle.clone());
let _enter = crate::runtime::context::enter_runtime(&handle, true);
// Set the worker context.
let cx = Context {
worker,
core: RefCell::new(None),
};
CURRENT.set(&cx, || {
// This should always be an error... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a94eb089343e1efa9563b91e13c79a0e61b2364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a94eb089343e1efa9563b91e13c79a0e61b2364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:12 | core = self.run_task(task, core)?;
} else {
// Wait for work
core = if did_defer_tasks() {
self.park_timeout(core, Some(Duration::from_millis(0)))
} else {
self.park(core)
};
}
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a94eb089343e1efa9563b91e13c79a0e61b2364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a94eb089343e1efa9563b91e13c79a0e61b2364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:13 | None => return Err(()),
};
// If task poll times is enabled, measure the poll time. Note
// that, if the `core` is stolen, this means `block_in_place`
// was called, turning the poll into a "blocking op". In this
// case, we don't want to ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a94eb089343e1efa9563b91e13c79a0e61b2364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a94eb089343e1efa9563b91e13c79a0e61b2364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:14 | }
fn maintenance(&self, mut core: Box<Core>) -> Box<Core> {
if core.tick % self.worker.handle.shared.config.event_interval == 0 {
super::counters::inc_num_maintenance();
// Call `park` with a 0 timeout. This enables the I/O driver, timer, ...
// to run without actually ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a94eb089343e1efa9563b91e13c79a0e61b2364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a94eb089343e1efa9563b91e13c79a0e61b2364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:15 | core.maintenance(&self.worker);
if core.transition_from_parked(&self.worker) {
break;
}
}
}
if let Some(f) = &self.worker.handle.shared.config.after_unpark {
f();
}
core
}
fn park_timeout(&self, mut co... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a94eb089343e1efa9563b91e13c79a0e61b2364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a94eb089343e1efa9563b91e13c79a0e61b2364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:16 | }
core
}
}
impl Core {
/// Increment the tick
fn tick(&mut self) {
self.tick = self.tick.wrapping_add(1);
}
/// Return the next notified task available to this worker.
fn next_task(&mut self, worker: &Worker) -> Option<Notified> {
if self.tick % worker.handle.shared.co... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a94eb089343e1efa9563b91e13c79a0e61b2364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a94eb089343e1efa9563b91e13c79a0e61b2364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:17 | let mut tasks = worker.inject().pop_n(n);
// Pop the first task to return immedietly
let ret = tasks.next();
// Push the rest of the on the run queue
self.run_queue.push_back(tasks);
ret
}
}
fn next_local_task(&mut self) -> Option<Notified>... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a94eb089343e1efa9563b91e13c79a0e61b2364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a94eb089343e1efa9563b91e13c79a0e61b2364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:18 | .steal
.steal_into(&mut self.run_queue, &mut self.metrics)
{
return Some(task);
}
}
// Fallback on checking the global queue
worker.handle.shared.inject.pop()
}
fn transition_to_searching(&mut self, worker: &Worker) -> bool {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a94eb089343e1efa9563b91e13c79a0e61b2364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a94eb089343e1efa9563b91e13c79a0e61b2364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:19 | let is_last_searcher = worker
.handle
.shared
.idle
.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_search... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a94eb089343e1efa9563b91e13c79a0e61b2364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a94eb089343e1efa9563b91e13c79a0e61b2364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:20 | fn maintenance(&mut self, worker: &Worker) {
self.metrics
.submit(&worker.handle.shared.worker_metrics[worker.index]);
if !self.is_shutdown {
// Check if the scheduler has been shutdown
self.is_shutdown = worker.inject().is_closed();
}
}
/// Signals ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a94eb089343e1efa9563b91e13c79a0e61b2364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a94eb089343e1efa9563b91e13c79a0e61b2364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:21 | impl task::Schedule for Arc<Handle> {
fn release(&self, task: &Task) -> Option<Task> {
self.shared.owned.remove(task)
}
fn schedule(&self, task: Notified) {
self.schedule_task(task, false);
}
fn yield_now(&self, task: Notified) {
self.schedule_task(task, true);
}
}
imp... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a94eb089343e1efa9563b91e13c79a0e61b2364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a94eb089343e1efa9563b91e13c79a0e61b2364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:22 | // tasks to be executed. If **not** a yield, then there is more
// flexibility and the task may go to the front of the queue.
let should_notify = if is_yield || self.shared.config.disable_lifo_slot {
core.run_queue
.push_back_or_overflow(task, &self.shared.inject, &mut core.m... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a94eb089343e1efa9563b91e13c79a0e61b2364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a94eb089343e1efa9563b91e13c79a0e61b2364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:23 | self.shared.remotes[index].unpark.unpark(&self.driver);
}
}
fn notify_parked_remote(&self) {
if let Some(index) = self.shared.idle.worker_to_notify() {
self.shared.remotes[index].unpark.unpark(&self.driver);
}
}
fn notify_all(&self) {
for remote in &self.sha... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a94eb089343e1efa9563b91e13c79a0e61b2364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a94eb089343e1efa9563b91e13c79a0e61b2364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:24 | /// If all workers have reached this point, the final cleanup is performed.
fn shutdown_core(&self, core: Box<Core>) {
let mut cores = self.shared.shutdown_cores.lock();
cores.push(core);
if cores.len() != self.shared.remotes.len() {
return;
}
debug_assert!(self... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a94eb089343e1efa9563b91e13c79a0e61b2364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a94eb089343e1efa9563b91e13c79a0e61b2364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 921 | 967 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:13 | None => return Err(()),
};
// If task poll times is enabled, measure the poll time. Note
// that, if the `core` is stolen, this means `block_in_place`
// was called, turning the poll into a "blocking op". In this
// case, we don't want to ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 8c076cb00d27c31b68071308b12412ca7cecceab | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8c076cb00d27c31b68071308b12412ca7cecceab/tokio/src/runtime/scheduler/multi_thread/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:14 | if core.tick % self.worker.handle.shared.config.event_interval == 0 {
super::counters::inc_num_maintenance();
// Call `park` with a 0 timeout. This enables the I/O driver, timer, ...
// to run without actually putting the thread to sleep.
core = self.park_timeout(core, S... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 8c076cb00d27c31b68071308b12412ca7cecceab | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8c076cb00d27c31b68071308b12412ca7cecceab/tokio/src/runtime/scheduler/multi_thread/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:15 | break;
}
}
}
if let Some(f) = &self.worker.handle.shared.config.after_unpark {
f();
}
core
}
fn park_timeout(&self, mut core: Box<Core>, duration: Option<Duration>) -> Box<Core> {
// Take the parker out of core
let mut par... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 8c076cb00d27c31b68071308b12412ca7cecceab | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8c076cb00d27c31b68071308b12412ca7cecceab/tokio/src/runtime/scheduler/multi_thread/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:16 | }
}
impl Core {
/// Increment the tick
fn tick(&mut self) {
self.tick = self.tick.wrapping_add(1);
}
/// Return the next notified task available to this worker.
fn next_task(&mut self, worker: &Worker) -> Option<Notified> {
if self.tick % worker.handle.shared.config.global_queue_in... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 8c076cb00d27c31b68071308b12412ca7cecceab | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8c076cb00d27c31b68071308b12412ca7cecceab/tokio/src/runtime/scheduler/multi_thread/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:17 | if i == worker.index {
continue;
}
let target = &worker.handle.shared.remotes[i];
if let Some(task) = target
.steal
.steal_into(&mut self.run_queue, &mut self.metrics)
{
return Some(task);
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 8c076cb00d27c31b68071308b12412ca7cecceab | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8c076cb00d27c31b68071308b12412ca7cecceab/tokio/src/runtime/scheduler/multi_thread/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:18 | return false;
}
// When the final worker transitions **out** of searching to parked, it
// must check all the queues one last time in case work materialized
// between the last work scan and transitioning out of searching.
let is_last_searcher = worker
.handle
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 8c076cb00d27c31b68071308b12412ca7cecceab | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8c076cb00d27c31b68071308b12412ca7cecceab/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:19 | // When unparked, the worker is in the searching state.
self.is_searching = true;
true
}
/// Runs maintenance work such as checking the pool's state.
fn maintenance(&mut self, worker: &Worker) {
self.metrics
.submit(&worker.handle.shared.worker_metrics[worker.index]);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 8c076cb00d27c31b68071308b12412ca7cecceab | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8c076cb00d27c31b68071308b12412ca7cecceab/tokio/src/runtime/scheduler/multi_thread/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:20 | fn inject(&self) -> &Inject<Arc<Handle>> {
&self.handle.shared.inject
}
}
// TODO: Move `Handle` impls into handle.rs
impl task::Schedule for Arc<Handle> {
fn release(&self, task: &Task) -> Option<Task> {
self.shared.owned.remove(task)
}
fn schedule(&self, task: Notified) {
sel... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 8c076cb00d27c31b68071308b12412ca7cecceab | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8c076cb00d27c31b68071308b12412ca7cecceab/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:21 | fn schedule_local(&self, core: &mut Core, task: Notified, is_yield: bool) {
core.metrics.inc_local_schedule_count();
// Spawning from the worker thread. If scheduling a "yield" then the
// task must always be pushed to the back of the queue, enabling other
// tasks to be executed. If **... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 8c076cb00d27c31b68071308b12412ca7cecceab | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8c076cb00d27c31b68071308b12412ca7cecceab/tokio/src/runtime/scheduler/multi_thread/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:22 | fn notify_parked_local(&self) {
super::counters::inc_num_inc_notify_local();
if let Some(index) = self.shared.idle.worker_to_notify() {
super::counters::inc_num_unparks_local();
self.shared.remotes[index].unpark.unpark(&self.driver);
}
}
fn notify_parked_remote(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 8c076cb00d27c31b68071308b12412ca7cecceab | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8c076cb00d27c31b68071308b12412ca7cecceab/tokio/src/runtime/scheduler/multi_thread/worker.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:23 | }
}
/// Signals that a worker has observed the shutdown signal and has replaced
/// its core back into its handle.
///
/// If all workers have reached this point, the final cleanup is performed.
fn shutdown_core(&self, core: Box<Core>) {
let mut cores = self.shared.shutdown_cores.lock()... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 8c076cb00d27c31b68071308b12412ca7cecceab | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8c076cb00d27c31b68071308b12412ca7cecceab/tokio/src/runtime/scheduler/multi_thread/worker.rs | 881 | 933 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:24 | }
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 {
self.remotes[worker].steal.len()
}
}
} | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 8c076cb00d27c31b68071308b12412ca7cecceab | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8c076cb00d27c31b68071308b12412ca7cecceab/tokio/src/runtime/scheduler/multi_thread/worker.rs | 921 | 933 |
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 | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/scheduler/multi_thread/worker.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:4 | 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 on a worker thread.
/// 2. Subm... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/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, i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/scheduler/multi_thread/worker.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:6 | for _ in 0..size {
let (steal, run_queue) = queue::local();
let park = park.clone();
let unpark = park.unpark();
let metrics = WorkerMetrics::from_config(&config);
cores.push(Box::new(Core {
tick: 0,
lifo_slot: None,
run_queue,
is... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/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 | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/scheduler/multi_thread/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:8 | crate::runtime::context::current_enter_context(),
maybe_cx.is_some(),
) {
(context::EnterRuntime::Entered { .. }, true) => {
// We are on a thread pool runtime thread, so we just need to
// set up blocking.
had_entered = true;
}... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/scheduler/multi_thread/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:9 | let cx = maybe_cx.expect("no .is_some() == false cases above should lead here");
// Get the worker core. If none is set, then blocking is fine!
let core = match cx.core.borrow_mut().take() {
Some(core) => core,
None => return Ok(()),
};
// The parker should be s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/scheduler/multi_thread/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:10 | }
impl Launch {
pub(crate) fn launch(mut self) {
for worker in self.0.drain(..) {
runtime::spawn_blocking(move || run(worker));
}
}
}
fn run(worker: Arc<Worker>) {
struct AbortOnPanic;
impl Drop for AbortOnPanic {
fn drop(&mut self) {
if std::thread::pa... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/scheduler/multi_thread/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:11 | core: RefCell::new(None),
};
CURRENT.set(&cx, || {
// This should always be an error. It only returns a `Result` to support
// using `?` to short circuit.
assert!(cx.run(core).is_err());
// Check if there are any deferred tasks to notify. This can happen when
// the wor... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/scheduler/multi_thread/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:12 | };
}
}
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);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/scheduler/multi_thread/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:13 | // really count as an async poll anymore.
core.metrics.end_poll();
// Check for a task in the LIFO slot
let task = match core.lifo_slot.take() {
Some(task) => task,
None => return Ok(core),
};
// Po... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/scheduler/multi_thread/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:14 | }
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/Tim... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/scheduler/multi_thread/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:15 | }
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 So... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/scheduler/multi_thread/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:16 | /// Return the next notified task available to this worker.
fn next_task(&mut self, worker: &Worker) -> Option<Notified> {
if self.tick % worker.handle.shared.config.global_queue_interval == 0 {
worker.inject().pop().or_else(|| self.next_local_task())
} else {
self.next_local... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/scheduler/multi_thread/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:17 | return Some(task);
}
}
// 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_t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/scheduler/multi_thread/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:18 | .idle
.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
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:19 | 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 | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/scheduler/multi_thread/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:20 | }
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 l... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:21 | core.run_queue
.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
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/scheduler/multi_thread/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:22 | remote.unpark.unpark(&self.driver);
}
}
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() {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/scheduler/multi_thread/worker.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:23 | core.shutdown(self);
}
// 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:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | c84d0a14b189c45da8f5e963fd3a83790ec92f8e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c84d0a14b189c45da8f5e963fd3a83790ec92f8e/tokio/src/runtime/scheduler/multi_thread/worker.rs | 881 | 915 |
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, i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 70364b707975b84daf223915d60a1610de2539a2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70364b707975b84daf223915d60a1610de2539a2/tokio/src/runtime/scheduler/multi_thread/worker.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:6 | 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,
is_shutdown: false,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 70364b707975b84daf223915d60a1610de2539a2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70364b707975b84daf223915d60a1610de2539a2/tokio/src/runtime/scheduler/multi_thread/worker.rs | 201 | 260 |
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 | 70364b707975b84daf223915d60a1610de2539a2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70364b707975b84daf223915d60a1610de2539a2/tokio/src/runtime/scheduler/multi_thread/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:10 | impl Launch {
pub(crate) fn launch(mut self) {
for worker in self.0.drain(..) {
runtime::spawn_blocking(move || run(worker));
}
}
}
fn run(worker: Arc<Worker>) {
struct AbortOnPanic;
impl Drop for AbortOnPanic {
fn drop(&mut self) {
if std::thread::panic... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 70364b707975b84daf223915d60a1610de2539a2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70364b707975b84daf223915d60a1610de2539a2/tokio/src/runtime/scheduler/multi_thread/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:11 | };
CURRENT.set(&cx, || {
// This should always be an error. It only returns a `Result` to support
// using `?` to short circuit.
assert!(cx.run(core).is_err());
// Check if there are any deferred tasks to notify. This can happen when
// the worker core is lost due to `block... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 70364b707975b84daf223915d60a1610de2539a2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70364b707975b84daf223915d60a1610de2539a2/tokio/src/runtime/scheduler/multi_thread/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:12 | }
}
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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 70364b707975b84daf223915d60a1610de2539a2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70364b707975b84daf223915d60a1610de2539a2/tokio/src/runtime/scheduler/multi_thread/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:13 | // Polling a task doesn't necessarily consume any budget, if it
// doesn't use any Tokio leaf futures. To prevent such tasks
// from using the lifo slot in an infinite loop, we consume an
// extra unit of budget between each iteration of the loop.
coop::co... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 70364b707975b84daf223915d60a1610de2539a2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70364b707975b84daf223915d60a1610de2539a2/tokio/src/runtime/scheduler/multi_thread/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:14 | /// 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 loop, all waken tasks are scheduled
/// in its own local queue until the queue saturates... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 70364b707975b84daf223915d60a1610de2539a2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70364b707975b84daf223915d60a1610de2539a2/tokio/src/runtime/scheduler/multi_thread/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:15 | // Park thread
if let Some(timeout) = duration {
park.park_timeout(&self.worker.handle.driver, timeout);
} else {
park.park(&self.worker.handle.driver);
}
wake_deferred_tasks();
// Remove `core` from context
core = self.core.borrow_mut().take().e... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 70364b707975b84daf223915d60a1610de2539a2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70364b707975b84daf223915d60a1610de2539a2/tokio/src/runtime/scheduler/multi_thread/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:16 | 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 | 70364b707975b84daf223915d60a1610de2539a2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70364b707975b84daf223915d60a1610de2539a2/tokio/src/runtime/scheduler/multi_thread/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:17 | 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, worker: &Worker) {
if !self.is_sear... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 70364b707975b84daf223915d60a1610de2539a2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70364b707975b84daf223915d60a1610de2539a2/tokio/src/runtime/scheduler/multi_thread/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:18 | 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 unpark regardless of
// being notified
if self.lifo_slot.is... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 70364b707975b84daf223915d60a1610de2539a2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70364b707975b84daf223915d60a1610de2539a2/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:19 | /// 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();
self.metrics
.submit(&worker.handle.shared.worker_metrics[worker.index]);... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 70364b707975b84daf223915d60a1610de2539a2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70364b707975b84daf223915d60a1610de2539a2/tokio/src/runtime/scheduler/multi_thread/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:20 | }
}
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) {
// An... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 70364b707975b84daf223915d60a1610de2539a2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70364b707975b84daf223915d60a1610de2539a2/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:21 | if let Some(prev) = prev {
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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 70364b707975b84daf223915d60a1610de2539a2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70364b707975b84daf223915d60a1610de2539a2/tokio/src/runtime/scheduler/multi_thread/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:22 | return;
}
}
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
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 70364b707975b84daf223915d60a1610de2539a2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70364b707975b84daf223915d60a1610de2539a2/tokio/src/runtime/scheduler/multi_thread/worker.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:23 | }
}
fn ptr_eq(&self, other: &Handle) -> bool {
std::ptr::eq(self, other)
}
}
fn did_defer_tasks() -> bool {
context::with_defer(|deferred| !deferred.is_empty()).unwrap()
}
fn wake_deferred_tasks() {
context::with_defer(|deferred| deferred.wake());
}
cfg_metrics! {
impl Shared {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 70364b707975b84daf223915d60a1610de2539a2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70364b707975b84daf223915d60a1610de2539a2/tokio/src/runtime/scheduler/multi_thread/worker.rs | 881 | 907 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:12 | }
}
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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | d1b789f33aa9d2bbca84f24b810235a10b149e92 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1b789f33aa9d2bbca84f24b810235a10b149e92/tokio/src/runtime/scheduler/multi_thread/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:13 | 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 | d1b789f33aa9d2bbca84f24b810235a10b149e92 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1b789f33aa9d2bbca84f24b810235a10b149e92/tokio/src/runtime/scheduler/multi_thread/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:14 | /// Also, we rely on the workstealing algorithm to spread the tasks amongst workers
/// 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(&s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | d1b789f33aa9d2bbca84f24b810235a10b149e92 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1b789f33aa9d2bbca84f24b810235a10b149e92/tokio/src/runtime/scheduler/multi_thread/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:15 | }
wake_deferred_tasks();
// 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 ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | d1b789f33aa9d2bbca84f24b810235a10b149e92 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1b789f33aa9d2bbca84f24b810235a10b149e92/tokio/src/runtime/scheduler/multi_thread/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:16 | ///
/// 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 self, worker: &Worker) -> Option<Notified> {
if !self.transitio... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | d1b789f33aa9d2bbca84f24b810235a10b149e92 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1b789f33aa9d2bbca84f24b810235a10b149e92/tokio/src/runtime/scheduler/multi_thread/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:17 | }
fn transition_from_searching(&mut self, worker: &Worker) {
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 transiti... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | d1b789f33aa9d2bbca84f24b810235a10b149e92 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1b789f33aa9d2bbca84f24b810235a10b149e92/tokio/src/runtime/scheduler/multi_thread/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:18 | /// 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 should only transition to ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | d1b789f33aa9d2bbca84f24b810235a10b149e92 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1b789f33aa9d2bbca84f24b810235a10b149e92/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:19 | .submit(&worker.handle.shared.worker_metrics[worker.index]);
}
/// Shuts down the core.
fn shutdown(&mut self, handle: &Handle) {
// Take the core
let mut park = self.park.take().expect("park missing");
// Drain the queue
while self.next_local_task().is_some() {}
p... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | d1b789f33aa9d2bbca84f24b810235a10b149e92 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1b789f33aa9d2bbca84f24b810235a10b149e92/tokio/src/runtime/scheduler/multi_thread/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:20 | if let Some(cx) = maybe_cx {
// Make sure the task is part of the **current** scheduler.
if self.ptr_eq(&cx.worker.handle) {
// And the current thread still holds a core
if let Some(core) = cx.core.borrow_mut().as_mut() {
se... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | d1b789f33aa9d2bbca84f24b810235a10b149e92 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1b789f33aa9d2bbca84f24b810235a10b149e92/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:21 | ret
};
// 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.not... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | d1b789f33aa9d2bbca84f24b810235a10b149e92 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1b789f33aa9d2bbca84f24b810235a10b149e92/tokio/src/runtime/scheduler/multi_thread/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:22 | }
}
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 ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | d1b789f33aa9d2bbca84f24b810235a10b149e92 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d1b789f33aa9d2bbca84f24b810235a10b149e92/tokio/src/runtime/scheduler/multi_thread/worker.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:9 | // Get the worker core. If none is set, then blocking is fine!
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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:10 | impl Launch {
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 d... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:11 | core = self.maintenance(core);
// First, check work available to the current worker.
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 s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:12 | // Run the task
coop::budget(|| {
task.run();
// As long as there is budget remaining and a task exists in the
// `lifo_slot`, then keep running.
loop {
// Check if we still have the core. If not, the core was stolen
// by another ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:13 | // to run without actually putting the thread to sleep.
core = self.park_timeout(core, Some(Duration::from_millis(0)));
// Run regularly scheduled maintenance
core.maintenance(&self.worker);
}
core
}
/// Parks the worker thread while waiting for tasks to ex... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/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(f) = &self.worker.handle.shared.config.after_unpark {
f();
}
core
}
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");
// S... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:15 | /// Increment the tick
fn tick(&mut self) {
self.tick = self.tick.wrapping_add(1);
}
/// Return the next notified task available to this worker.
fn next_task(&mut self, worker: &Worker) -> Option<Notified> {
if self.tick % worker.handle.shared.config.global_queue_interval == 0 {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:16 | let target = &worker.handle.shared.remotes[i];
if let Some(task) = target
.steal
.steal_into(&mut self.run_queue, &mut self.metrics)
{
return Some(task);
}
}
// Fallback on checking the global queue
worker.handl... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:17 | // must check all the queues one last time in case work materialized
// between the last work scan and transitioning out of searching.
let is_last_searcher = worker
.handle
.shared
.idle
.transition_worker_to_parked(worker.index, self.is_searching);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:18 | /// Runs maintenance work such as checking the pool's state.
fn maintenance(&mut self, worker: &Worker) {
self.metrics
.submit(&worker.handle.shared.worker_metrics[worker.index]);
if !self.is_shutdown {
// Check if the scheduler has been shutdown
self.is_shutdown... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:19 | // TODO: Move `Handle` impls into handle.rs
impl task::Schedule for Arc<Handle> {
fn release(&self, task: &Task) -> Option<Task> {
self.shared.owned.remove(task)
}
fn schedule(&self, task: Notified) {
self.schedule_task(task, false);
}
fn yield_now(&self, task: Notified) {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:20 | // Spawning from the worker thread. If scheduling a "yield" then the
// task must always be pushed to the back of the queue, enabling other
// tasks to be executed. If **not** a yield, then there is more
// flexibility and the task may go to the front of the queue.
let should_notify = if... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:21 | }
}
fn notify_all(&self) {
for remote in &self.shared.remotes[..] {
remote.unpark.unpark(&self.driver);
}
}
fn notify_if_work_pending(&self) {
for remote in &self.shared.remotes[..] {
if !remote.steal.is_empty() {
self.notify_parked();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:22 | }
debug_assert!(self.shared.owned.is_empty());
for mut core in cores.drain(..) {
core.shutdown(self);
}
// Drain the injection queue
//
// We already shut down every task, so we can simply drop the tasks.
while let Some(task) = self.shared.inject.po... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 22862739dddd49a94065aa7a917cde2dc8a3f6bc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/22862739dddd49a94065aa7a917cde2dc8a3f6bc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 841 | 880 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:10 | impl Launch {
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 d... | 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 | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:11 | core = self.maintenance(core);
// First, check work available to the current worker.
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 s... | 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 | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:12 | // As long as there is budget remaining and a task exists in the
// `lifo_slot`, then keep running.
loop {
// 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() {
... | 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 | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:13 | core.maintenance(&self.worker);
}
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... | 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 | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:14 | core
}
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
... | 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 | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:15 | fn next_task(&mut self, worker: &Worker) -> Option<Notified> {
if self.tick % worker.handle.shared.config.global_queue_interval == 0 {
worker.inject().pop().or_else(|| self.next_local_task())
} else {
self.next_local_task().or_else(|| worker.inject().pop())
}
}
f... | 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 | 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();
}
... | 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 | 601 | 660 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.