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_alt/worker.rs:11 | return Err(
"can call blocking only when running on the multi-threaded runtime",
);
}
}
(context::EnterRuntime::NotEntered, true) => {
// This is a nested call to block_in_place (we already exited).
// Al... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:12 | Ok(())
});
if let Err(panic_message) = setup_result {
panic!("{}", panic_message);
}
if had_entered {
// Unset the current task's budget. Blocking sections are not
// constrained by task budgets.
let _reset = Reset(coop::stop());
crate::runtime::context::exit_r... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:13 | let num_workers = handle.shared.condvars.len();
let mut worker = Worker {
tick: 0,
num_seq_local_queue_polls: 0,
global_queue_interval: Stats::DEFAULT_GLOBAL_QUEUE_INTERVAL,
is_shutdown: false,
is_traced: false,
workers_to_notify: Vec::with_capacity(num_workers - 1),... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:14 | }
});
});
}
macro_rules! try_task {
($e:expr) => {{
let (task, core) = $e?;
if task.is_some() {
return Ok((task, core));
}
core
}};
}
macro_rules! try_task_new_batch {
($w:expr, $e:expr) => {{
let (task, mut core) = $e?;
if task.is_so... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:15 | if let Some(core) = self.try_acquire_available_core(cx, &mut synced) {
// Try to poll a task from the global queue
let maybe_task = cx.shared().next_remote_task_synced(&mut synced);
(maybe_task, core)
} else {
// block the t... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:16 | // Try to acquire an available core, but do not block the thread
fn try_acquire_available_core(
&mut self,
cx: &Context,
synced: &mut Synced,
) -> Option<Box<Core>> {
if let Some(mut core) = cx
.shared()
.idle
.try_acquire_available_core(&mut s... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:17 | }
// If shutting down, abort
if cx.shared().inject.is_closed(&synced.inject) {
self.shutdown_clear_defer(cx);
return Err(());
}
synced = cx.shared().condvars[cx.index].wait(synced).unwrap();
};
self.reset_acquired_core(cx... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:18 | self.update_global_flags(cx, synced);
}
/// Finds the next task to run, this could be from a queue or stealing. If
/// none are available, the thread sleeps and tries again.
fn next_task(&mut self, cx: &Context, mut core: Box<Core>) -> NextTaskResult {
self.assert_lifo_enabled_is_correct(cx);
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:19 | core = try_task_new_batch!(self, self.search_for_work(cx, core));
debug_assert!(cx.defer.borrow().is_empty());
core = try_task_new_batch!(self, self.park(cx, core));
}
// Shutting down, drop any deferred tasks
self.shutdown_clear_defer(cx);
Ok((None, core))
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:20 | let mut synced = cx.shared().synced.lock();
cx.shared().next_remote_task_synced(&mut synced)
}
fn next_remote_task_batch(&self, cx: &Context, mut core: Box<Core>) -> NextTaskResult {
if cx.shared().inject.is_empty() {
return Ok((None, core));
}
// Other threads can ... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:21 | let n = usize::min(n, max) + 1;
// safety: passing in the correct `inject::Synced`.
let mut tasks = unsafe { cx.shared().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
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:22 | // Get a snapshot of which workers are idle
cx.shared().idle.snapshot(&mut self.idle_snapshot);
let num = cx.shared().remotes.len();
for i in 0..ROUNDS {
// Start from a random worker
let start = core.rand.fastrand_n(num as u32) as usize;
if let Some(task) ... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:23 | let target = &cx.shared().remotes[i];
if let Some(task) = target
.steal
.steal_into(&mut core.run_queue, &mut core.stats)
{
return Some(task);
}
}
None
}
fn run_task(&mut self, cx: &Context, mut core: Box<Core... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:24 | // 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 cx.core.borrow_mut().take() {
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:25 | lifo_polls += 1;
super::counters::inc_lifo_schedules();
// Disable the LIFO slot if we reach our limit
//
// In ping-ping style workloads where task A notifies task B,
// which notifies task A again, continuously prioritizing the
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:26 | let mut synced = synced();
// Number of tasks we want to try to spread across idle workers
let num_fanout = cmp::min(defer.len(), cx.shared().idle.num_idle(&synced.idle));
// Cap the number of threads woken up at one time. This is to limit
// the number of no-op wakes a... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:27 | Ok((task, core))
}
fn schedule_deferred_without_core<'a>(&mut self, cx: &Context, synced: &mut Synced) {
let mut defer = cx.defer.borrow_mut();
let num = defer.len();
if num > 0 {
// Push all tasks to the injection queue
cx.shared()
.push_remote_... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:28 | }
fn flush_metrics(&self, cx: &Context, core: &mut Core) {
core.stats.submit(&cx.shared().worker_metrics[core.index]);
}
fn update_global_flags(&mut self, cx: &Context, synced: &mut Synced) {
if !self.is_shutdown {
self.is_shutdown = cx.shared().inject.is_closed(&synced.inject)... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:29 | driver.park_timeout(&cx.handle.driver, Duration::from_millis(0));
cx.shared().driver.set(driver);
// If there are more I/O events, schedule them.
self.schedule_deferred_with_core(cx, core, || cx.shared().synced.lock())
} else {
Ok((None, core))
}
}
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:30 | // Try one last time to get tasks
let n = cmp::max(core.run_queue.remaining_slots() / 2, 1);
if let Some(task) = self.next_remote_task_batch_synced(cx, &mut synced, &mut core, n) {
return Ok((Some(task), core));
}
if !was_searching {
if cx
.shared... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:31 | for i in 0..cx.shared().remotes.len() {
if !cx.shared().remotes[i].steal.is_empty() {
let mut synced = cx.shared().synced.lock();
// Try to get a core
if let Some(mut core) = self.try_acquire_available_core(cx, &mut synced) {
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:32 | // Wait for a core.
self.wait_for_core(cx, synced)
}
} else {
synced = cx.shared().synced.lock();
// Wait for a core to be assigned to us
self.wait_for_core(cx, synced)
}
}
fn transition_to_searching(&self, cx: &Context, core: &mu... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:33 | .set(!cx.handle.shared.config.disable_lifo_slot);
}
fn assert_lifo_enabled_is_correct(&self, cx: &Context) {
debug_assert_eq!(
cx.lifo_enabled.get(),
!cx.handle.shared.config.disable_lifo_slot
);
}
fn tune_global_queue_interval(&mut self, cx: &Context, core: &mu... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:34 | self.index
}
}
impl Core {
fn next_local_task(&mut self) -> Option<Notified> {
self.next_lifo_task().or_else(|| self.run_queue.pop())
}
fn next_lifo_task(&mut self) -> Option<Notified> {
self.lifo_slot.take()
}
}
impl Shared {
fn next_remote_task_synced(&self, synced: &mut Syn... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,321 | 1,380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:35 | return;
}
}
// Otherwise, use the inject queue.
self.schedule_remote(task);
})
}
fn schedule_local(&self, cx: &Context, core: &mut Core, task: Notified) {
core.stats.inc_local_schedule_count();
if cx.lifo_enabled.get() {
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,361 | 1,420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:37 | {
unsafe {
self.inject.push_batch(self, iter);
}
}
fn push_remote_task_batch_synced<I>(&self, synced: &mut Synced, iter: I)
where
I: Iterator<Item = task::Notified<Arc<Handle>>>,
{
unsafe {
self.inject.push_batch(&mut synced.inject, iter);
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,441 | 1,500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:38 | pub(super) fn shutdown_finalize(&self, handle: &Handle, synced: &mut Synced) {
// Wait for all cores
if synced.shutdown_cores.len() != self.remotes.len() {
return;
}
let driver = synced.shutdown_driver.take();
if self.driver_enabled() && driver.is_none() {
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,481 | 1,540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:39 | fn push_batch<I>(&self, iter: I)
where
I: Iterator<Item = task::Notified<Arc<Handle>>>,
{
self.push_remote_task_batch(iter)
}
}
impl<'a> Lock<inject::Synced> for &'a Shared {
type Handle = SyncedGuard<'a>;
fn lock(self) -> Self::Handle {
SyncedGuard {
lock: self... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,521 | 1,580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:40 | }
}
impl AsMut<Synced> for Synced {
fn as_mut(&mut self) -> &mut Synced {
self
}
}
pub(crate) struct SyncedGuard<'a> {
lock: crate::loom::sync::MutexGuard<'a, Synced>,
}
impl<'a> AsMut<inject::Synced> for SyncedGuard<'a> {
fn as_mut(&mut self) -> &mut inject::Synced {
&mut self.lock.i... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,561 | 1,594 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:32 | // Wait for a core.
self.wait_for_core(cx, synced)
}
} else {
synced = cx.shared().synced.lock();
// Wait for a core to be assigned to us
self.wait_for_core(cx, synced)
}
}
fn transition_to_searching(&self, cx: &Context, core: &mu... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 90b23a9584db99ae81fffee38a89a09d2eca1834 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/90b23a9584db99ae81fffee38a89a09d2eca1834/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:33 | .set(!cx.handle.shared.config.disable_lifo_slot);
}
fn assert_lifo_enabled_is_correct(&self, cx: &Context) {
debug_assert_eq!(
cx.lifo_enabled.get(),
!cx.handle.shared.config.disable_lifo_slot
);
}
fn tune_global_queue_interval(&mut self, cx: &Context, core: &mu... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 90b23a9584db99ae81fffee38a89a09d2eca1834 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/90b23a9584db99ae81fffee38a89a09d2eca1834/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:40 | }
}
impl AsMut<Synced> for Synced {
fn as_mut(&mut self) -> &mut Synced {
self
}
}
pub(crate) struct SyncedGuard<'a> {
lock: crate::loom::sync::MutexGuard<'a, Synced>,
}
impl<'a> AsMut<inject::Synced> for SyncedGuard<'a> {
fn as_mut(&mut self) -> &mut inject::Synced {
&mut self.lock.i... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 90b23a9584db99ae81fffee38a89a09d2eca1834 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/90b23a9584db99ae81fffee38a89a09d2eca1834/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,561 | 1,603 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/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 | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:14 | }
});
});
}
macro_rules! try_task {
($e:expr) => {{
let (task, core) = $e?;
if task.is_some() {
return Ok((task, core));
}
core
}};
}
macro_rules! try_task_new_batch {
($w:expr, $e:expr) => {{
let (task, mut core) = $e?;
if task.is_so... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:15 | if let Some(core) = self.try_acquire_available_core(cx, &mut synced) {
// Try to poll a task from the global queue
let maybe_task = cx.shared().next_remote_task_synced(&mut synced);
(maybe_task, core)
} else {
// block the t... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:17 | // If shutting down, abort
if cx.shared().inject.is_closed(&synced.inject) {
self.shutdown_clear_defer(cx);
return Err(());
}
synced = cx.shared().condvars[cx.index].wait(synced).unwrap();
};
self.reset_acquired_core(cx, &mut synced, ... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:18 | }
/// Finds the next task to run, this could be from a queue or stealing. If
/// none are available, the thread sleeps and tries again.
fn next_task(&mut self, cx: &Context, mut core: Box<Core>) -> NextTaskResult {
self.assert_lifo_enabled_is_correct(cx);
if self.is_traced {
co... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:19 | debug_assert!(cx.defer.borrow().is_empty());
core = try_task_new_batch!(self, self.park(cx, core));
}
// Shutting down, drop any deferred tasks
self.shutdown_clear_defer(cx);
Ok((None, core))
}
fn next_notified_task(&mut self, cx: &Context, mut core: Box<Core>) -> ... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:20 | cx.shared().next_remote_task_synced(&mut synced)
}
fn next_remote_task_batch(&self, cx: &Context, mut core: Box<Core>) -> NextTaskResult {
if cx.shared().inject.is_empty() {
return Ok((None, core));
}
// Other threads can only **remove** tasks from the current worker's
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:21 | let n = usize::min(n, max) + 1;
// safety: passing in the correct `inject::Synced`.
let mut tasks = unsafe { cx.shared().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
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:22 | // Get a snapshot of which workers are idle
cx.shared().idle.snapshot(&mut self.idle_snapshot);
let num = cx.shared().remotes.len();
for i in 0..ROUNDS {
// Start from a random worker
let start = core.rand.fastrand_n(num as u32) as usize;
if let Some(task) ... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:23 | let target = &cx.shared().remotes[i];
if let Some(task) = target
.steal
.steal_into(&mut core.run_queue, &mut core.stats)
{
return Some(task);
}
}
None
}
fn run_task(&mut self, cx: &Context, mut core: Box<Core... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:24 | // 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 cx.core.borrow_mut().take() {
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:25 | super::counters::inc_lifo_schedules();
// Disable the LIFO slot if we reach our limit
//
// In ping-ping style workloads where task A notifies task B,
// which notifies task A again, continuously prioritizing the
// LIFO slot can cause sta... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:26 | // Number of tasks we want to try to spread across idle workers
let num_fanout = cmp::min(defer.len(), cx.shared().idle.num_idle(&synced.idle));
// Cap the number of threads woken up at one time. This is to limit
// the number of no-op wakes and reduce mutext contention.
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:27 | Ok((task, core))
}
fn schedule_deferred_without_core<'a>(&mut self, cx: &Context, synced: &mut Synced) {
let mut defer = cx.defer.borrow_mut();
let num = defer.len();
if num > 0 {
// Push all tasks to the injection queue
cx.shared()
.push_remote_... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:28 | fn flush_metrics(&self, cx: &Context, core: &mut Core) {
core.stats.submit(&cx.shared().worker_metrics[core.index]);
}
fn update_global_flags(&mut self, cx: &Context, synced: &mut Synced) {
if !self.is_shutdown {
self.is_shutdown = cx.shared().inject.is_closed(&synced.inject);
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:29 | cx.shared().driver.set(driver);
// If there are more I/O events, schedule them.
self.schedule_deferred_with_core(cx, core, || cx.shared().synced.lock())
} else {
Ok((None, core))
}
}
*/
fn park(&mut self, cx: &Context, mut core: Box<Core>) -> NextTaskRes... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:31 | if !cx.shared().remotes[i].steal.is_empty() {
let mut synced = cx.shared().synced.lock();
// Try to get a core
if let Some(mut core) = self.try_acquire_available_core(cx, &mut synced) {
cx.shared().idle.transition_worke... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:32 | // Wait for a core.
self.wait_for_core(cx, synced)
}
} else {
synced = cx.shared().synced.lock();
// Wait for a core to be assigned to us
self.wait_for_core(cx, synced)
}
}
fn transition_to_searching(&self, cx: &Context, core: &mu... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:33 | }
fn assert_lifo_enabled_is_correct(&self, cx: &Context) {
debug_assert_eq!(
cx.lifo_enabled.get(),
!cx.handle.shared.config.disable_lifo_slot
);
}
fn tune_global_queue_interval(&mut self, cx: &Context, core: &mut Core) {
let next = core.stats.tuned_global_q... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:34 | }
}
impl Core {
fn next_local_task(&mut self) -> Option<Notified> {
self.next_lifo_task().or_else(|| self.run_queue.pop())
}
fn next_lifo_task(&mut self) -> Option<Notified> {
self.lifo_slot.take()
}
}
impl Shared {
fn next_remote_task_synced(&self, synced: &mut Synced) -> Option<... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,321 | 1,380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:35 | }
}
// Otherwise, use the inject queue.
self.schedule_remote(task);
})
}
fn schedule_local(&self, cx: &Context, core: &mut Core, task: Notified) {
core.stats.inc_local_schedule_count();
if cx.lifo_enabled.get() {
// Push to the LIFO slot... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,361 | 1,420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:36 | // Push the task in the
self.push_remote_task(&mut synced, task);
// Notify a worker. The mutex is passed in and will be released as part
// of the method call.
self.idle.notify_remote(synced, self);
}
pub(super) fn close(&self, handle: &Handle) {
{
let mut ... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,401 | 1,460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:37 | unsafe {
self.inject.push_batch(self, iter);
}
}
fn push_remote_task_batch_synced<I>(&self, synced: &mut Synced, iter: I)
where
I: Iterator<Item = task::Notified<Arc<Handle>>>,
{
unsafe {
self.inject.push_batch(&mut synced.inject, iter);
}
}
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,441 | 1,500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:38 | // Wait for all cores
if synced.shutdown_cores.len() != self.remotes.len() {
return;
}
let driver = synced.shutdown_driver.take();
if self.driver_enabled() && driver.is_none() {
return;
}
debug_assert!(self.owned.is_empty());
for mut co... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,481 | 1,540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:39 | fn push_batch<I>(&self, iter: I)
where
I: Iterator<Item = task::Notified<Arc<Handle>>>,
{
self.push_remote_task_batch(iter)
}
}
impl<'a> Lock<inject::Synced> for &'a Shared {
type Handle = SyncedGuard<'a>;
fn lock(self) -> Self::Handle {
SyncedGuard {
lock: self... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,521 | 1,580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:40 | }
impl AsMut<Synced> for Synced {
fn as_mut(&mut self) -> &mut Synced {
self
}
}
pub(crate) struct SyncedGuard<'a> {
lock: crate::loom::sync::MutexGuard<'a, Synced>,
}
impl<'a> AsMut<inject::Synced> for SyncedGuard<'a> {
fn as_mut(&mut self) -> &mut inject::Synced {
&mut self.lock.inj... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | b69f16aa219818bc75e7ae6a22631d4e574efd39 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b69f16aa219818bc75e7ae6a22631d4e574efd39/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,561 | 1,602 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:17 | // If shutting down, abort
if cx.shared().inject.is_closed(&synced.inject) {
self.shutdown_clear_defer(cx);
return Err(());
}
synced = cx.shared().condvars[cx.index].wait(synced).unwrap();
};
self.reset_acquired_core(cx, &mut synced, ... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:18 | /// none are available, the thread sleeps and tries again.
fn next_task(&mut self, cx: &Context, mut core: Box<Core>) -> NextTaskResult {
self.assert_lifo_enabled_is_correct(cx);
if self.is_traced {
core = cx.handle.trace_core(core);
}
// Increment the tick
self... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:19 | }
// Shutting down, drop any deferred tasks
self.shutdown_clear_defer(cx);
Ok((None, core))
}
fn next_notified_task(&mut self, cx: &Context, mut core: Box<Core>) -> NextTaskResult {
self.num_seq_local_queue_polls += 1;
if self.num_seq_local_queue_polls % self.global_q... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:20 | fn next_remote_task_batch(&self, cx: &Context, mut core: Box<Core>) -> NextTaskResult {
if cx.shared().inject.is_empty() {
return Ok((None, core));
}
// Other threads can only **remove** tasks from the current worker's
// `run_queue`. So, we can be confident that by the time... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:21 | let mut tasks = unsafe { cx.shared().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
core.run_queue.push_back(tasks);
ret
}
/// Function responsible for stealing tasks ... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:22 | let num = cx.shared().remotes.len();
for i in 0..ROUNDS {
// Start from a random worker
let start = core.rand.fastrand_n(num as u32) as usize;
if let Some(task) = self.steal_one_round(cx, &mut core, start) {
return Ok((Some(task), core));
}
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:23 | .steal
.steal_into(&mut core.run_queue, &mut core.stats)
{
return Some(task);
}
}
None
}
fn run_task(&mut self, cx: &Context, mut core: Box<Core>, task: Notified) -> RunResult {
let task = cx.shared().owned.assert_owner(task);
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:24 | // Check if we still have the core. If not, the core was stolen
// by another worker.
let mut core = match cx.core.borrow_mut().take() {
Some(core) => core,
None => {
// In this case, we cannot call `reset_lifo_enabled()`
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:25 | //
// In ping-ping style workloads where task A notifies task B,
// which notifies task A again, continuously prioritizing the
// LIFO slot can cause starvation as these two tasks will
// repeatedly schedule the other. To mitigate this, we limit the
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:26 | // Cap the number of threads woken up at one time. This is to limit
// the number of no-op wakes and reduce mutext contention.
//
// This number was picked after some basic benchmarks, but it can
// probably be tuned using the mean poll time value (slower task
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:27 | fn schedule_deferred_without_core<'a>(&mut self, cx: &Context, synced: &mut Synced) {
let mut defer = cx.defer.borrow_mut();
let num = defer.len();
if num > 0 {
// Push all tasks to the injection queue
cx.shared()
.push_remote_task_batch_synced(synced, de... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:28 | }
fn update_global_flags(&mut self, cx: &Context, synced: &mut Synced) {
if !self.is_shutdown {
self.is_shutdown = cx.shared().inject.is_closed(&synced.inject);
}
if !self.is_traced {
self.is_traced = cx.shared().trace_status.trace_requested();
}
}
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:29 | // If there are more I/O events, schedule them.
self.schedule_deferred_with_core(cx, core, || cx.shared().synced.lock())
} else {
Ok((None, core))
}
}
*/
fn park(&mut self, cx: &Context, mut core: Box<Core>) -> NextTaskResult {
if let Some(f) = &cx.shared().c... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:30 | return Ok((Some(task), core));
}
if !was_searching {
if cx
.shared()
.idle
.transition_worker_to_searching_if_needed(&mut synced.idle, &mut core)
{
// Skip parking, go back to searching
return Ok((No... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:31 | // Try to get a core
if let Some(mut core) = self.try_acquire_available_core(cx, &mut synced) {
cx.shared().idle.transition_worker_to_searching(&mut core);
return Ok((None, core));
} else {
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:32 | } else {
synced = cx.shared().synced.lock();
// Wait for a core to be assigned to us
self.wait_for_core(cx, synced)
}
}
fn transition_to_searching(&self, cx: &Context, core: &mut Core) -> bool {
if !core.is_searching {
cx.shared().idle.try_transi... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:33 | debug_assert_eq!(
cx.lifo_enabled.get(),
!cx.handle.shared.config.disable_lifo_slot
);
}
fn tune_global_queue_interval(&mut self, cx: &Context, core: &mut Core) {
let next = core.stats.tuned_global_queue_interval(&cx.shared().config);
// Smooth out jitter
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:34 | impl Core {
fn next_local_task(&mut self) -> Option<Notified> {
self.next_lifo_task().or_else(|| self.run_queue.pop())
}
fn next_lifo_task(&mut self) -> Option<Notified> {
self.lifo_slot.take()
}
}
impl Shared {
fn next_remote_task_synced(&self, synced: &mut Synced) -> Option<Notif... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,321 | 1,380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:35 | // Otherwise, use the inject queue.
self.schedule_remote(task);
})
}
fn schedule_local(&self, cx: &Context, core: &mut Core, task: Notified) {
core.stats.inc_local_schedule_count();
if cx.lifo_enabled.get() {
// Push to the LIFO slot
let prev = std::... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,361 | 1,420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:36 | // Notify a worker. The mutex is passed in and will be released as part
// of the method call.
self.idle.notify_remote(synced, self);
}
pub(super) fn close(&self, handle: &Handle) {
{
let mut synced = self.synced.lock();
if let Some(driver) = self.driver.take() ... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,401 | 1,460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:37 | }
fn push_remote_task_batch_synced<I>(&self, synced: &mut Synced, iter: I)
where
I: Iterator<Item = task::Notified<Arc<Handle>>>,
{
unsafe {
self.inject.push_batch(&mut synced.inject, iter);
}
}
fn take_driver(&self) -> Option<Box<Driver>> {
if !self.dri... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,441 | 1,500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:38 | }
let driver = synced.shutdown_driver.take();
if self.driver_enabled() && driver.is_none() {
return;
}
debug_assert!(self.owned.is_empty());
for mut core in synced.shutdown_cores.drain(..) {
// Drain tasks from the local queue
while core.ne... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,481 | 1,540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:39 | {
self.push_remote_task_batch(iter)
}
}
impl<'a> Lock<inject::Synced> for &'a Shared {
type Handle = SyncedGuard<'a>;
fn lock(self) -> Self::Handle {
SyncedGuard {
lock: self.synced.lock(),
}
}
}
impl<'a> Lock<Synced> for &'a Shared {
type Handle = SyncedGuard<... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,521 | 1,580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:40 | fn as_mut(&mut self) -> &mut Synced {
self
}
}
pub(crate) struct SyncedGuard<'a> {
lock: crate::loom::sync::MutexGuard<'a, Synced>,
}
impl<'a> AsMut<inject::Synced> for SyncedGuard<'a> {
fn as_mut(&mut self) -> &mut inject::Synced {
&mut self.lock.inject
}
}
impl<'a> AsMut<Synced> for... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,561 | 1,599 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/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 | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 1914e1e4b9bfe6ea2d61970ec3fcf2b5d7bb0210 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1914e1e4b9bfe6ea2d61970ec3fcf2b5d7bb0210/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:33 | debug_assert_eq!(
cx.lifo_enabled.get(),
!cx.handle.shared.config.disable_lifo_slot
);
}
fn tune_global_queue_interval(&mut self, cx: &Context, core: &mut Core) {
let next = core.stats.tuned_global_queue_interval(&cx.shared().config);
// Smooth out jitter
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 328a02c1ce08df6e888b19c81cc81d59422af5ef | github | async-runtime | https://github.com/tokio-rs/tokio/blob/328a02c1ce08df6e888b19c81cc81d59422af5ef/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:34 | fn next_lifo_task(&mut self) -> Option<Notified> {
self.lifo_slot.take()
}
}
impl Shared {
fn next_remote_task_synced(&self, synced: &mut Synced) -> Option<Notified> {
// safety: we only have access to a valid `Synced` in this file.
unsafe { self.inject.pop(&mut synced.inject) }
}
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 328a02c1ce08df6e888b19c81cc81d59422af5ef | github | async-runtime | https://github.com/tokio-rs/tokio/blob/328a02c1ce08df6e888b19c81cc81d59422af5ef/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,321 | 1,380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:35 | fn schedule_local(&self, cx: &Context, core: &mut Core, task: Notified) {
core.stats.inc_local_schedule_count();
if cx.lifo_enabled.get() {
// Push to the LIFO slot
let prev = std::mem::replace(&mut core.lifo_slot, Some(task));
// let prev = cx.shared().remotes[core.... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 328a02c1ce08df6e888b19c81cc81d59422af5ef | github | async-runtime | https://github.com/tokio-rs/tokio/blob/328a02c1ce08df6e888b19c81cc81d59422af5ef/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,361 | 1,420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:36 | pub(super) fn close(&self, handle: &Handle) {
{
let mut synced = self.synced.lock();
if let Some(driver) = self.driver.take() {
synced.shutdown_driver = Some(driver);
}
if !self.inject.close(&mut synced.inject) {
return;
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 328a02c1ce08df6e888b19c81cc81d59422af5ef | github | async-runtime | https://github.com/tokio-rs/tokio/blob/328a02c1ce08df6e888b19c81cc81d59422af5ef/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,401 | 1,460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:37 | {
unsafe {
self.inject.push_batch(&mut synced.inject, iter);
}
}
fn take_driver(&self) -> Option<Box<Driver>> {
if !self.driver_enabled() {
return None;
}
self.driver.take()
}
fn driver_enabled(&self) -> bool {
self.condvars.len(... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 328a02c1ce08df6e888b19c81cc81d59422af5ef | github | async-runtime | https://github.com/tokio-rs/tokio/blob/328a02c1ce08df6e888b19c81cc81d59422af5ef/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,441 | 1,500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:38 | return;
}
debug_assert!(self.owned.is_empty());
for mut core in synced.shutdown_cores.drain(..) {
// Drain tasks from the local queue
while core.next_local_task().is_some() {}
}
// Shutdown the driver
if let Some(mut driver) = driver {
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 328a02c1ce08df6e888b19c81cc81d59422af5ef | github | async-runtime | https://github.com/tokio-rs/tokio/blob/328a02c1ce08df6e888b19c81cc81d59422af5ef/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,481 | 1,540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:39 | impl<'a> Lock<inject::Synced> for &'a Shared {
type Handle = SyncedGuard<'a>;
fn lock(self) -> Self::Handle {
SyncedGuard {
lock: self.synced.lock(),
}
}
}
impl<'a> Lock<Synced> for &'a Shared {
type Handle = SyncedGuard<'a>;
fn lock(self) -> Self::Handle {
Syn... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 328a02c1ce08df6e888b19c81cc81d59422af5ef | github | async-runtime | https://github.com/tokio-rs/tokio/blob/328a02c1ce08df6e888b19c81cc81d59422af5ef/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,521 | 1,580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:40 | pub(crate) struct SyncedGuard<'a> {
lock: crate::loom::sync::MutexGuard<'a, Synced>,
}
impl<'a> AsMut<inject::Synced> for SyncedGuard<'a> {
fn as_mut(&mut self) -> &mut inject::Synced {
&mut self.lock.inject
}
}
impl<'a> AsMut<Synced> for SyncedGuard<'a> {
fn as_mut(&mut self) -> &mut Synced {... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 328a02c1ce08df6e888b19c81cc81d59422af5ef | github | async-runtime | https://github.com/tokio-rs/tokio/blob/328a02c1ce08df6e888b19c81cc81d59422af5ef/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,561 | 1,594 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:17 | // If shutting down, abort
if cx.shared().inject.is_closed(&synced.inject) {
self.shutdown_clear_defer(cx);
return Err(());
}
synced = cx.shared().condvars[cx.index].wait(synced).unwrap();
};
self.reset_acquired_core(cx, &mut synced, ... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:18 | /// Finds the next task to run, this could be from a queue or stealing. If
/// none are available, the thread sleeps and tries again.
fn next_task(&mut self, cx: &Context, mut core: Box<Core>) -> NextTaskResult {
self.assert_lifo_enabled_is_correct(cx);
if self.is_traced {
core = cx... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:19 | core = try_task_new_batch!(self, self.park(cx, core));
}
// Shutting down, drop any deferred tasks
self.shutdown_clear_defer(cx);
Ok((None, core))
}
fn next_notified_task(&mut self, cx: &Context, mut core: Box<Core>) -> NextTaskResult {
self.num_seq_local_queue_polls +... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:21 | // safety: passing in the correct `inject::Synced`.
let mut tasks = unsafe { cx.shared().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
core.run_queue.push_back(tasks);
... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:23 | if let Some(task) = target
.steal
.steal_into(&mut core.run_queue, &mut core.stats)
{
return Some(task);
}
}
None
}
fn run_task(&mut self, cx: &Context, mut core: Box<Core>, task: Notified) -> RunResult {
let task ... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:24 | loop {
// Check if we still have the core. If not, the core was stolen
// by another worker.
let mut core = match cx.core.borrow_mut().take() {
Some(core) => core,
None => {
// In this case, we cannot call `r... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:25 | // Disable the LIFO slot if we reach our limit
//
// In ping-ping style workloads where task A notifies task B,
// which notifies task A again, continuously prioritizing the
// LIFO slot can cause starvation as these two tasks will
// repea... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:26 | let num_fanout = cmp::min(defer.len(), cx.shared().idle.num_idle(&synced.idle));
// Cap the number of threads woken up at one time. This is to limit
// the number of no-op wakes and reduce mutext contention.
//
// This number was picked after some basic benchmarks, but i... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/worker.rs:27 | fn schedule_deferred_without_core<'a>(&mut self, cx: &Context, synced: &mut Synced) {
let mut defer = cx.defer.borrow_mut();
let num = defer.len();
if num > 0 {
// Push all tasks to the injection queue
cx.shared()
.push_remote_task_batch_synced(synced, de... | rust | rust | macro-heavy | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | MIT | 131e7b4e49c8849298ba54b4e0c99f4b81d869e3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/131e7b4e49c8849298ba54b4e0c99f4b81d869e3/tokio/src/runtime/scheduler/multi_thread_alt/worker.rs | 1,041 | 1,100 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.