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:16 | );
}
}
}
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 {
#[cfg(tokio_unstable)]
let task_meta = task.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 7ed6da6733199fe4d08b9694fce646dac5944e70 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7ed6da6733199fe4d08b9694fce646dac5944e70/tokio/src/runtime/scheduler/multi_thread/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:17 | .poll_start_callback(&task_meta);
task.run();
#[cfg(tokio_unstable)]
self.worker.handle.task_hooks.poll_stop_callback(&task_meta);
let mut lifo_polls = 0;
// As long as there is budget remaining and a task exists in the
// `lifo_slot`, then kee... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 7ed6da6733199fe4d08b9694fce646dac5944e70 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7ed6da6733199fe4d08b9694fce646dac5944e70/tokio/src/runtime/scheduler/multi_thread/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:18 | task,
&*self.worker.handle,
&mut core.stats,
);
// If we hit this point, the LIFO slot should be enabled.
// There is no need to reset it.
debug_assert!(core.lifo_enabled);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 7ed6da6733199fe4d08b9694fce646dac5944e70 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7ed6da6733199fe4d08b9694fce646dac5944e70/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:20 | /// 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 | 7ed6da6733199fe4d08b9694fce646dac5944e70 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7ed6da6733199fe4d08b9694fce646dac5944e70/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:21 | }
fn park_internal(&self, mut core: Box<Core>, duration: Option<Duration>) -> Box<Core> {
self.assert_lifo_enabled_is_correct(&core);
// Take the parker out of core
let mut park = core.park.take().expect("park missing");
// Store `core` in context
*self.core.borrow_mut() = ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 7ed6da6733199fe4d08b9694fce646dac5944e70 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7ed6da6733199fe4d08b9694fce646dac5944e70/tokio/src/runtime/scheduler/multi_thread/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:22 | let _ = auto_advance_duration;
}
#[cfg(tokio_unstable)]
TimerFlavor::Alternative => {
// Must happens before placing back the parker, as the `Handle::schedule_local`
// will delay the notify if the parker is still in `core`.
//
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 7ed6da6733199fe4d08b9694fce646dac5944e70 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7ed6da6733199fe4d08b9694fce646dac5944e70/tokio/src/runtime/scheduler/multi_thread/worker.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:23 | /// * whether auto-advancing is required (feature = "test-util").
///
/// # Returns
///
/// `(Box<Core>, park_duration, auto_advance_duration)`
fn maintain_local_timers_before_parking(
&self,
park_duration: Option<Duration>,
) -> MaintainLocalTimer {
let handle = &self.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 7ed6da6733199fe4d08b9694fce646dac5944e70 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7ed6da6733199fe4d08b9694fce646dac5944e70/tokio/src/runtime/scheduler/multi_thread/worker.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:24 | (should_yield, next_timer)
});
wake_queue.wake_all();
if should_yield {
MaintainLocalTimer {
park_duration: Some(Duration::from_millis(0)),
auto_advance_duration: None,
}
} else {
// get the minimum duration
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 7ed6da6733199fe4d08b9694fce646dac5944e70 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7ed6da6733199fe4d08b9694fce646dac5944e70/tokio/src/runtime/scheduler/multi_thread/worker.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:25 | Arc::as_ptr(&cx.worker.handle),
Arc::as_ptr(&self.worker.handle),
"function should be called on the exact same worker"
);
let mut maybe_core = cx.core.borrow_mut();
let core = maybe_core.as_mut().expect("core missing");
let time_cx = &mut ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 7ed6da6733199fe4d08b9694fce646dac5944e70 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7ed6da6733199fe4d08b9694fce646dac5944e70/tokio/src/runtime/scheduler/multi_thread/worker.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:26 | ))),
None => f(None),
})
}
}
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.t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 7ed6da6733199fe4d08b9694fce646dac5944e70 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7ed6da6733199fe4d08b9694fce646dac5944e70/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:27 | );
// The worker is currently idle, pull a batch of work from the
// injection queue. We don't want to pull *all* the work so other
// workers can also get some.
let n = usize::min(
worker.inject().len() / worker.handle.shared.remotes.len() + 1,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 7ed6da6733199fe4d08b9694fce646dac5944e70 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7ed6da6733199fe4d08b9694fce646dac5944e70/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:28 | }
let num = worker.handle.shared.remotes.len();
// Start from a random worker
let start = self.rand.fastrand_n(num as u32) as usize;
for i in 0..num {
let i = (start + i) % num;
// Don't steal from ourself! We know we don't have work.
if i == worker... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 7ed6da6733199fe4d08b9694fce646dac5944e70 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7ed6da6733199fe4d08b9694fce646dac5944e70/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:29 | self.is_searching = false;
worker.handle.transition_worker_from_searching();
}
fn has_tasks(&self) -> bool {
self.lifo_slot.is_some() || self.run_queue.has_tasks()
}
fn should_notify_others(&self) -> bool {
// If there are tasks available to steal, but this worker is not
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 7ed6da6733199fe4d08b9694fce646dac5944e70 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7ed6da6733199fe4d08b9694fce646dac5944e70/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:32 | park.shutdown(&handle.driver);
}
fn tune_global_queue_interval(&mut self, worker: &Worker) {
let next = self
.stats
.tuned_global_queue_interval(&worker.handle.shared.config);
// Smooth out jitter
if u32::abs_diff(self.global_queue_interval, next) > 2 {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 7ed6da6733199fe4d08b9694fce646dac5944e70 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7ed6da6733199fe4d08b9694fce646dac5944e70/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:33 | }
// Separated case to reduce LLVM codegen in `Handle::bind_new_task`.
pub(super) fn schedule_option_task_without_yield(&self, task: Option<Notified>) {
if let Some(task) = task {
self.schedule_task(task, false);
}
}
fn schedule_local(&self, core: &mut Core, task: Notified,... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 7ed6da6733199fe4d08b9694fce646dac5944e70 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7ed6da6733199fe4d08b9694fce646dac5944e70/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:34 | }
}
fn next_remote_task(&self) -> Option<Notified> {
if self.shared.inject.is_empty() {
return None;
}
let mut synced = self.shared.synced.lock();
// safety: passing in correct `idle::Synced`
unsafe { self.shared.inject.pop(&mut synced.inject) }
}
f... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 7ed6da6733199fe4d08b9694fce646dac5944e70 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7ed6da6733199fe4d08b9694fce646dac5944e70/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,321 | 1,380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:35 | None => Vec::new(),
}
}
pub(super) fn close(&self) {
if self
.shared
.inject
.close(&mut self.shared.synced.lock().inject)
{
self.notify_all();
}
}
fn notify_parked_local(&self) {
super::counters::inc_num_inc_notif... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 7ed6da6733199fe4d08b9694fce646dac5944e70 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7ed6da6733199fe4d08b9694fce646dac5944e70/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,361 | 1,420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:36 | }
}
if !self.shared.inject.is_empty() {
self.notify_parked_local();
}
}
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 | 7ed6da6733199fe4d08b9694fce646dac5944e70 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7ed6da6733199fe4d08b9694fce646dac5944e70/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,401 | 1,460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:37 | }
fn ptr_eq(&self, other: &Handle) -> bool {
std::ptr::eq(self, other)
}
}
impl Overflow<Arc<Handle>> for Handle {
fn push(&self, task: task::Notified<Arc<Handle>>) {
self.push_remote_task(task);
}
fn push_batch<I>(&self, iter: I)
where
I: Iterator<Item = task::Notifie... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 7ed6da6733199fe4d08b9694fce646dac5944e70 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7ed6da6733199fe4d08b9694fce646dac5944e70/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,441 | 1,498 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:38 | }
#[cfg(all(tokio_unstable, feature = "time"))]
/// Returned by [`Context::maintain_local_timers_before_parking`].
struct MaintainLocalTimer {
park_duration: Option<Duration>,
auto_advance_duration: Option<Duration>,
}
#[track_caller]
fn with_current<R>(f: impl FnOnce(Option<&Context>) -> R) -> R {
use sc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 7ed6da6733199fe4d08b9694fce646dac5944e70 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7ed6da6733199fe4d08b9694fce646dac5944e70/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,481 | 1,498 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:32 | park.shutdown(&handle.driver);
}
fn tune_global_queue_interval(&mut self, worker: &Worker) {
let next = self
.stats
.tuned_global_queue_interval(&worker.handle.shared.config);
// Smooth out jitter
if u32::abs_diff(self.global_queue_interval, next) > 2 {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 73d733a3415af98d72c2cce40612c4e59adbd5d8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/73d733a3415af98d72c2cce40612c4e59adbd5d8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:33 | }
pub(super) fn schedule_option_task_without_yield(&self, task: Option<Notified>) {
if let Some(task) = task {
self.schedule_task(task, false);
}
}
fn schedule_local(&self, core: &mut Core, task: Notified, is_yield: bool) {
core.stats.inc_local_schedule_count();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 73d733a3415af98d72c2cce40612c4e59adbd5d8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/73d733a3415af98d72c2cce40612c4e59adbd5d8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:34 | }
fn next_remote_task(&self) -> Option<Notified> {
if self.shared.inject.is_empty() {
return None;
}
let mut synced = self.shared.synced.lock();
// safety: passing in correct `idle::Synced`
unsafe { self.shared.inject.pop(&mut synced.inject) }
}
fn push... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 73d733a3415af98d72c2cce40612c4e59adbd5d8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/73d733a3415af98d72c2cce40612c4e59adbd5d8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,321 | 1,380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:35 | }
}
pub(super) fn close(&self) {
if self
.shared
.inject
.close(&mut self.shared.synced.lock().inject)
{
self.notify_all();
}
}
fn notify_parked_local(&self) {
super::counters::inc_num_inc_notify_local();
if let S... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 73d733a3415af98d72c2cce40612c4e59adbd5d8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/73d733a3415af98d72c2cce40612c4e59adbd5d8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,361 | 1,420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:36 | }
if !self.shared.inject.is_empty() {
self.notify_parked_local();
}
}
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 no... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 73d733a3415af98d72c2cce40612c4e59adbd5d8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/73d733a3415af98d72c2cce40612c4e59adbd5d8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,401 | 1,460 |
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 sp... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:3 | }
cfg_not_taskdump! {
mod taskdump_mock;
}
/// A scheduler worker
pub(super) struct Worker {
/// Reference to scheduler's handle
handle: Arc<Handle>,
/// Index holding this worker's remote state
index: usize,
/// Used to hand-off a worker's core to another thread.
core: AtomicCell<Core>,... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:4 | /// True if the scheduler is being shutdown
is_shutdown: bool,
/// True if the scheduler is being traced
is_traced: bool,
/// Parker
///
/// Stored in an `Option` as the parker is added / removed to make the
/// borrow checker happy.
park: Option<Parker>,
/// Per-worker runtime st... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:5 | /// Data synchronized by the scheduler mutex
pub(super) synced: Mutex<Synced>,
/// Cores that have observed the shutdown signal
///
/// The core is **not** placed back in the worker to avoid it from being
/// stolen by a thread that was spawned as part of `block_in_place`.
#[allow(clippy::vec_b... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:6 | pub(super) steal: queue::Steal<Arc<Handle>>,
/// Unparks the associated worker thread
unpark: Unparker,
}
/// Thread-local context
pub(crate) struct Context {
/// Worker
worker: Arc<Worker>,
/// Core data
core: RefCell<Option<Box<Core>>>,
/// Tasks to wake after resource drivers are poll... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:7 | blocking_spawner: blocking::Spawner,
seed_generator: RngSeedGenerator,
config: Config,
) -> (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.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:8 | task_hooks: TaskHooks::from_config(&config),
shared: Shared {
remotes: remotes.into_boxed_slice(),
inject,
idle,
owned: OwnedTasks::new(size),
synced: Mutex::new(Synced {
idle: idle_synced,
inject: inject_synced,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:9 | // Try to steal the worker core back
struct Reset {
take_core: bool,
budget: coop::Budget,
}
impl Drop for Reset {
fn drop(&mut self) {
with_current(|maybe_cx| {
if let Some(cx) = maybe_cx {
if self.take_core {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:10 | // We are on a thread pool runtime thread, so we just need to
// set up blocking.
had_entered = true;
}
(
context::EnterRuntime::Entered {
allow_block_in_place,
},
false,
) => {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:11 | Some(core) => core,
None => return Ok(()),
};
// If we heavily call `spawn_blocking`, there might be no available thread to
// run this core. Except for the task in the lifo_slot, all tasks can be
// stolen, so we move the task out of the lifo_slot to the run_queue.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:12 | // Unset the current task's budget. Blocking sections are not
// constrained by task budgets.
let _reset = Reset {
take_core,
budget: coop::stop(),
};
crate::runtime::context::exit_runtime(f)
} else {
f()
}
}
impl Launch {
pub(crate) fn launc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:13 | // worker and there is nothing further to do.
let core = match worker.core.take() {
Some(core) => core,
None => return,
};
worker.handle.shared.worker_metrics[worker.index].set_thread_id(thread::current().id());
let handle = scheduler::Handle::MultiThread(worker.handle.clone());
c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:14 | // will be one of the first things we do.
core.stats.start_processing_scheduled_tasks();
while !core.is_shutdown {
self.assert_lifo_enabled_is_correct(&core);
if core.is_traced {
core = self.worker.handle.trace_core(core);
}
// Increment... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:15 | }
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 {
#[cfg(tokio_unstable)]
let task_meta = task.task_meta();
let task = self.worke... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:16 | #[cfg(tokio_unstable)]
self.worker.handle.task_hooks.poll_stop_callback(&task_meta);
let mut lifo_polls = 0;
// As long as there is budget remaining and a task exists in the
// `lifo_slot`, then keep running.
loop {
// Check if we still have ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:17 | );
// If we hit this point, the LIFO slot should be enabled.
// There is no need to reset it.
debug_assert!(core.lifo_enabled);
return Ok(core);
}
// Track that we are about to run a task from the LIFO slot.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:18 | }
})
}
fn reset_lifo_enabled(&self, core: &mut Core) {
core.lifo_enabled = !self.worker.handle.shared.config.disable_lifo_slot;
}
fn assert_lifo_enabled_is_correct(&self, core: &Core) {
debug_assert_eq!(
core.lifo_enabled,
!self.worker.handle.shared.conf... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:19 | /// 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.
/// Also, we rely on the workstealing algorithm to spread the tasks amongst worker... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:20 | // 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);
} else {
park.park(&self.worker.handle.driver);
}
self.defer.wake();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:21 | 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 % self.global_queue_interval == 0 {
// Update the global queue interval, if needed
self.tune_globa... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:22 | // Take at least one task since the first task is returned directly
// and not pushed onto the local queue.
let n = usize::max(1, n);
let mut synced = worker.handle.shared.synced.lock();
// safety: passing in the correct `inject::Synced`.
let mut tasks = unsa... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:23 | // Don't steal from ourself! We know we don't have work.
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.stats)
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:24 | // If there are tasks available to steal, but this worker is not
// looking for tasks to steal, notify another worker.
if self.is_searching {
return false;
}
self.lifo_slot.is_some() as usize + self.run_queue.len() > 1
}
/// Prepares the worker state for parking.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:25 | // being notified
if self.has_tasks() {
// 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"
// when it wak... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:26 | // Check if the worker should be tracing.
self.is_traced = worker.handle.shared.trace_status.trace_requested();
}
}
/// 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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:27 | if u32::abs_diff(self.global_queue_interval, next) > 2 {
self.global_queue_interval = next;
}
}
}
impl Worker {
/// Returns a reference to the scheduler's injection queue.
fn inject(&self) -> &inject::Shared<Arc<Handle>> {
&self.handle.shared.inject
}
}
impl Handle {
pu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:28 | core.stats.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 **not** a yield, then there is more
// flexibility and the task may go to the fr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:29 | unsafe { self.shared.inject.pop(&mut synced.inject) }
}
fn push_remote_task(&self, task: Notified) {
self.shared.scheduler_metrics.inc_remote_schedule_count();
let mut synced = self.shared.synced.lock();
// safety: passing in correct `idle::Synced`
unsafe {
self.sha... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:31 | 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.next_remote_task() {
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 | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:32 | impl<'a> Lock<inject::Synced> for &'a Handle {
type Handle = InjectGuard<'a>;
fn lock(self) -> Self::Handle {
InjectGuard {
lock: self.shared.synced.lock(),
}
}
}
#[track_caller]
fn with_current<R>(f: impl FnOnce(Option<&Context>) -> R) -> R {
use scheduler::Context::MultiT... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 46f7d87962c0c1273bc66aca99d3f3c08da93265 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/46f7d87962c0c1273bc66aca99d3f3c08da93265/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,241 | 1,260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:6 | pub(super) steal: queue::Steal<Arc<Handle>>,
/// Unparks the associated worker thread
unpark: Unparker,
}
/// Thread-local context
pub(crate) struct Context {
/// Worker
worker: Arc<Worker>,
/// Core data
core: RefCell<Option<Box<Core>>>,
/// Tasks to wake after resource drivers are poll... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3e890cc0171ddb210acdcfec831b7c7bcbb0d2d9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3e890cc0171ddb210acdcfec831b7c7bcbb0d2d9/tokio/src/runtime/scheduler/multi_thread/worker.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:14 | // will be one of the first things we do.
core.stats.start_processing_scheduled_tasks();
while !core.is_shutdown {
self.assert_lifo_enabled_is_correct(&core);
if core.is_traced {
core = self.worker.handle.trace_core(core);
}
// Increment... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 714e5b571f2f6b329dfd830b9d3986fac7e7a0c8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/714e5b571f2f6b329dfd830b9d3986fac7e7a0c8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:15 | }
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 {
#[cfg(tokio_unstable)]
let task_id = task.task_id();
let task = self.worker.ha... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 714e5b571f2f6b329dfd830b9d3986fac7e7a0c8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/714e5b571f2f6b329dfd830b9d3986fac7e7a0c8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:16 | let mut lifo_polls = 0;
// 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 = mat... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 714e5b571f2f6b329dfd830b9d3986fac7e7a0c8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/714e5b571f2f6b329dfd830b9d3986fac7e7a0c8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:17 | debug_assert!(core.lifo_enabled);
return Ok(core);
}
// Track that we are about to run a task from the LIFO slot.
lifo_polls += 1;
super::counters::inc_lifo_schedules();
// Disable the LIFO slot if we reach our limit
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 714e5b571f2f6b329dfd830b9d3986fac7e7a0c8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/714e5b571f2f6b329dfd830b9d3986fac7e7a0c8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:18 | }
fn assert_lifo_enabled_is_correct(&self, core: &Core) {
debug_assert_eq!(
core.lifo_enabled,
!self.worker.handle.shared.config.disable_lifo_slot
);
}
fn maintenance(&self, mut core: Box<Core>) -> Box<Core> {
if core.tick % self.worker.handle.shared.config.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 714e5b571f2f6b329dfd830b9d3986fac7e7a0c8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/714e5b571f2f6b329dfd830b9d3986fac7e7a0c8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:19 | if let Some(f) = &self.worker.handle.shared.config.before_park {
f();
}
if core.transition_to_parked(&self.worker) {
while !core.is_shutdown && !core.is_traced {
core.stats.about_to_park();
core.stats
.submit(&self.worker.handl... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 714e5b571f2f6b329dfd830b9d3986fac7e7a0c8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/714e5b571f2f6b329dfd830b9d3986fac7e7a0c8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:20 | park.park_timeout(&self.worker.handle.driver, timeout);
} else {
park.park(&self.worker.handle.driver);
}
self.defer.wake();
// Remove `core` from context
core = self.core.borrow_mut().take().expect("core missing");
// Place `park` back in `core`
co... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 714e5b571f2f6b329dfd830b9d3986fac7e7a0c8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/714e5b571f2f6b329dfd830b9d3986fac7e7a0c8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:21 | // Update the global queue interval, if needed
self.tune_global_queue_interval(worker);
worker
.handle
.next_remote_task()
.or_else(|| self.next_local_task())
} else {
let maybe_task = self.next_local_task();
if ma... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 714e5b571f2f6b329dfd830b9d3986fac7e7a0c8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/714e5b571f2f6b329dfd830b9d3986fac7e7a0c8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:22 | // safety: passing in the correct `inject::Synced`.
let mut tasks = unsafe { worker.inject().pop_n(&mut synced.inject, n) };
// Pop the first task to return immediately
let ret = tasks.next();
// Push the rest of the on the run queue
self.run_queue.push_back... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 714e5b571f2f6b329dfd830b9d3986fac7e7a0c8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/714e5b571f2f6b329dfd830b9d3986fac7e7a0c8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:23 | if let Some(task) = target
.steal
.steal_into(&mut self.run_queue, &mut self.stats)
{
return Some(task);
}
}
// Fallback on checking the global queue
worker.handle.next_remote_task()
}
fn transition_to_searching(&m... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 714e5b571f2f6b329dfd830b9d3986fac7e7a0c8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/714e5b571f2f6b329dfd830b9d3986fac7e7a0c8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:24 | }
/// Prepares the worker state for parking.
///
/// Returns true if the transition happened, false if there is work to do first.
fn transition_to_parked(&mut self, worker: &Worker) -> bool {
// Workers should not park if they have work to do
if self.has_tasks() || self.is_traced {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 714e5b571f2f6b329dfd830b9d3986fac7e7a0c8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/714e5b571f2f6b329dfd830b9d3986fac7e7a0c8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:25 | self.is_searching = !worker
.handle
.shared
.idle
.unpark_worker_by_id(&worker.handle.shared, worker.index);
return true;
}
if worker
.handle
.shared
.idle
.is_parked(&worker.hand... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 714e5b571f2f6b329dfd830b9d3986fac7e7a0c8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/714e5b571f2f6b329dfd830b9d3986fac7e7a0c8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:26 | /// before we enter the single-threaded phase of shutdown processing.
fn pre_shutdown(&mut self, worker: &Worker) {
// Start from a random inner list
let start = self
.rand
.fastrand_n(worker.handle.shared.owned.get_shard_size() as u32);
// Signal to all tasks to shut... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 714e5b571f2f6b329dfd830b9d3986fac7e7a0c8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/714e5b571f2f6b329dfd830b9d3986fac7e7a0c8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:27 | impl Worker {
/// Returns a reference to the scheduler's injection queue.
fn inject(&self) -> &inject::Shared<Arc<Handle>> {
&self.handle.shared.inject
}
}
impl Handle {
pub(super) fn schedule_task(&self, task: Notified, is_yield: bool) {
with_current(|maybe_cx| {
if let Som... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 714e5b571f2f6b329dfd830b9d3986fac7e7a0c8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/714e5b571f2f6b329dfd830b9d3986fac7e7a0c8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:28 | let should_notify = if is_yield || !core.lifo_enabled {
core.run_queue
.push_back_or_overflow(task, self, &mut core.stats);
true
} else {
// Push to the LIFO slot
let prev = core.lifo_slot.take();
let ret = prev.is_some();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 714e5b571f2f6b329dfd830b9d3986fac7e7a0c8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/714e5b571f2f6b329dfd830b9d3986fac7e7a0c8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:29 | let mut synced = self.shared.synced.lock();
// safety: passing in correct `idle::Synced`
unsafe {
self.shared.inject.push(&mut synced.inject, task);
}
}
pub(super) fn close(&self) {
if self
.shared
.inject
.close(&mut self.shared.s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 714e5b571f2f6b329dfd830b9d3986fac7e7a0c8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/714e5b571f2f6b329dfd830b9d3986fac7e7a0c8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:30 | if !remote.steal.is_empty() {
self.notify_parked_local();
return;
}
}
if !self.shared.inject.is_empty() {
self.notify_parked_local();
}
}
fn transition_worker_from_searching(&self) {
if self.shared.idle.transition_worker_f... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 714e5b571f2f6b329dfd830b9d3986fac7e7a0c8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/714e5b571f2f6b329dfd830b9d3986fac7e7a0c8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:31 | while let Some(task) = self.next_remote_task() {
drop(task);
}
}
fn ptr_eq(&self, other: &Handle) -> bool {
std::ptr::eq(self, other)
}
}
impl Overflow<Arc<Handle>> for Handle {
fn push(&self, task: task::Notified<Arc<Handle>>) {
self.push_remote_task(task);
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 714e5b571f2f6b329dfd830b9d3986fac7e7a0c8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/714e5b571f2f6b329dfd830b9d3986fac7e7a0c8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,201 | 1,254 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:32 | lock: self.shared.synced.lock(),
}
}
}
#[track_caller]
fn with_current<R>(f: impl FnOnce(Option<&Context>) -> R) -> R {
use scheduler::Context::MultiThread;
context::with_scheduler(|ctx| match ctx {
Some(MultiThread(ctx)) => f(Some(ctx)),
_ => f(None),
})
} | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 714e5b571f2f6b329dfd830b9d3986fac7e7a0c8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/714e5b571f2f6b329dfd830b9d3986fac7e7a0c8/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,241 | 1,254 |
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 sp... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:6 | pub(super) steal: queue::Steal<Arc<Handle>>,
/// Unparks the associated worker thread
unpark: Unparker,
}
/// Thread-local context
pub(crate) struct Context {
/// Worker
worker: Arc<Worker>,
/// Core data
core: RefCell<Option<Box<Core>>>,
/// Tasks to wake after resource drivers are poll... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:7 | size: usize,
park: Parker,
driver_handle: driver::Handle,
blocking_spawner: blocking::Spawner,
seed_generator: RngSeedGenerator,
config: Config,
) -> (Arc<Handle>, Launch) {
let mut cores = Vec::with_capacity(size);
let mut remotes = Vec::with_capacity(size);
let mut worker_metrics = Vec... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:8 | let remotes_len = remotes.len();
let handle = Arc::new(Handle {
task_hooks: TaskHooks::from_config(&config),
shared: Shared {
remotes: remotes.into_boxed_slice(),
inject,
idle,
owned: OwnedTasks::new(size),
synced: Mutex::new(Synced {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:9 | where
F: FnOnce() -> R,
{
// Try to steal the worker core back
struct Reset {
take_core: bool,
budget: coop::Budget,
}
impl Drop for Reset {
fn drop(&mut self) {
with_current(|maybe_cx| {
if let Some(cx) = maybe_cx {
if self.ta... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:10 | 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;
}
(
context::EnterRuntime::Entered ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:11 | // Get the worker core. If none is set, then blocking is fine!
let mut core = match cx.core.borrow_mut().take() {
Some(core) => core,
None => return Ok(()),
};
// If we heavily call `spawn_blocking`, there might be no available thread to
// run this core. Except ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:12 | }
if had_entered {
// Unset the current task's budget. Blocking sections are not
// constrained by task budgets.
let _reset = Reset {
take_core,
budget: coop::stop(),
};
crate::runtime::context::exit_runtime(f)
} else {
f()
}
}
impl ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:13 | let _abort_on_panic = AbortOnPanic;
// 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,
};
worker.handle.shared.worker_metrics[worker.index].set... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:14 | self.reset_lifo_enabled(&mut core);
// Start as "processing" tasks as polling tasks from the local queue
// will be one of the first things we do.
core.stats.start_processing_scheduled_tasks();
while !core.is_shutdown {
self.assert_lifo_enabled_is_correct(&core);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:15 | };
core.stats.start_processing_scheduled_tasks();
}
}
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 {
#[cfg(t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:16 | #[cfg(tokio_unstable)]
self.worker.handle.task_hooks.poll_stop_callback(task_id);
let mut lifo_polls = 0;
// 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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:17 | );
// If we hit this point, the LIFO slot should be enabled.
// There is no need to reset it.
debug_assert!(core.lifo_enabled);
return Ok(core);
}
// Track that we are about to run a task from the LIFO slot.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:18 | fn reset_lifo_enabled(&self, core: &mut Core) {
core.lifo_enabled = !self.worker.handle.shared.config.disable_lifo_slot;
}
fn assert_lifo_enabled_is_correct(&self, core: &Core) {
debug_assert_eq!(
core.lifo_enabled,
!self.worker.handle.shared.config.disable_lifo_slot
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:19 | /// 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 | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:20 | // Park thread
if let Some(timeout) = duration {
park.park_timeout(&self.worker.handle.driver, timeout);
} else {
park.park(&self.worker.handle.driver);
}
self.defer.wake();
// Remove `core` from context
core = self.core.borrow_mut().take().expec... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:21 | /// Return the next notified task available to this worker.
fn next_task(&mut self, worker: &Worker) -> Option<Notified> {
if self.tick % self.global_queue_interval == 0 {
// Update the global queue interval, if needed
self.tune_global_queue_interval(worker);
worker
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:22 | let n = usize::max(1, n);
let mut synced = worker.handle.shared.synced.lock();
// safety: passing in the correct `inject::Synced`.
let mut tasks = unsafe { worker.inject().pop_n(&mut synced.inject, n) };
// Pop the first task to return immediately
let ret = ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:23 | }
let target = &worker.handle.shared.remotes[i];
if let Some(task) = target
.steal
.steal_into(&mut self.run_queue, &mut self.stats)
{
return Some(task);
}
}
// Fallback on checking the global queue
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:24 | return false;
}
self.lifo_slot.is_some() as usize + self.run_queue.len() > 1
}
/// Prepares the worker state for parking.
///
/// Returns true if the transition happened, false if there is work to do first.
fn transition_to_parked(&mut self, worker: &Worker) -> bool {
// Wor... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:25 | // state when the wake originates from another worker *or* a new task
// is pushed. We do *not* want the worker to transition to "searching"
// when it wakes when the I/O driver receives new events.
self.is_searching = !worker
.handle
.shared
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:26 | }
/// 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) {
// Start from a random inner list
let start = self
.rand
.fastrand_n(wor... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:27 | }
}
impl Worker {
/// Returns a reference to the scheduler's injection queue.
fn inject(&self) -> &inject::Shared<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> {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:28 | return;
}
}
}
// Otherwise, use the inject queue.
self.push_remote_task(task);
self.notify_parked_remote();
});
}
pub(super) fn schedule_option_task_without_yield(&self, task: Option<Notified>) {
if let Some(ta... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:29 | 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 | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,121 | 1,180 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.