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:30 | fn notify_parked_local(&self) {
super::counters::inc_num_inc_notify_local();
if let Some(index) = self.shared.idle.worker_to_notify(&self.shared) {
super::counters::inc_num_unparks_local();
self.shared.remotes[index].unpark.unpark(&self.driver);
}
}
fn notify_pa... | 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,161 | 1,220 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:31 | }
}
/// Signals that a worker has observed the shutdown signal and has replaced
/// its core back into its handle.
///
/// If all workers have reached this point, the final cleanup is performed.
fn shutdown_core(&self, core: Box<Core>) {
let mut cores = self.shared.shutdown_cores.lock()... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1ae9434e8e4a419ce25644e6c8d2b2e2e8c34750/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:32 | where
I: Iterator<Item = task::Notified<Arc<Handle>>>,
{
unsafe {
self.shared.inject.push_batch(self, iter);
}
}
}
pub(crate) struct InjectGuard<'a> {
lock: crate::loom::sync::MutexGuard<'a, Synced>,
}
impl<'a> AsMut<inject::Synced> for InjectGuard<'a> {
fn as_mut(&... | 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,241 | 1,278 |
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 | addbfb9204be25a8621feb3f20b44a7c1f00edbd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/addbfb9204be25a8621feb3f20b44a7c1f00edbd/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:21 | /// Increment the tick
fn tick(&mut self) {
self.tick = self.tick.wrapping_add(1);
}
/// Return the next notified task available to this worker.
fn next_task(&mut self, worker: &Worker) -> Option<Notified> {
if self.tick % self.global_queue_interval == 0 {
// Update the glob... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | addbfb9204be25a8621feb3f20b44a7c1f00edbd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/addbfb9204be25a8621feb3f20b44a7c1f00edbd/tokio/src/runtime/scheduler/multi_thread/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:22 | cap,
);
// 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`.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | addbfb9204be25a8621feb3f20b44a7c1f00edbd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/addbfb9204be25a8621feb3f20b44a7c1f00edbd/tokio/src/runtime/scheduler/multi_thread/worker.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:23 | let i = (start + i) % num;
// 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_int... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | addbfb9204be25a8621feb3f20b44a7c1f00edbd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/addbfb9204be25a8621feb3f20b44a7c1f00edbd/tokio/src/runtime/scheduler/multi_thread/worker.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:24 | fn should_notify_others(&self) -> bool {
// 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
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | addbfb9204be25a8621feb3f20b44a7c1f00edbd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/addbfb9204be25a8621feb3f20b44a7c1f00edbd/tokio/src/runtime/scheduler/multi_thread/worker.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:25 | fn transition_from_parked(&mut self, worker: &Worker) -> bool {
// If a task is in the lifo slot/run queue, then we must unpark regardless of
// being notified
if self.has_tasks() {
// When a worker wakes, it should only transition to the "searching"
// state when the wak... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | addbfb9204be25a8621feb3f20b44a7c1f00edbd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/addbfb9204be25a8621feb3f20b44a7c1f00edbd/tokio/src/runtime/scheduler/multi_thread/worker.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:26 | if !self.is_traced {
// 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 pro... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | addbfb9204be25a8621feb3f20b44a7c1f00edbd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/addbfb9204be25a8621feb3f20b44a7c1f00edbd/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:27 | // Smooth out jitter
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
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | addbfb9204be25a8621feb3f20b44a7c1f00edbd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/addbfb9204be25a8621feb3f20b44a7c1f00edbd/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:28 | // Make sure the task is part of the **current** scheduler.
if self.ptr_eq(&cx.worker.handle) {
// And the current thread still holds a core
if let Some(core) = cx.core.borrow_mut().as_mut() {
self.schedule_local(core, task, is_yield);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | addbfb9204be25a8621feb3f20b44a7c1f00edbd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/addbfb9204be25a8621feb3f20b44a7c1f00edbd/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:29 | .push_back_or_overflow(prev, self, &mut core.stats);
}
core.lifo_slot = Some(task);
ret
};
// Only notify if not currently parked. If `park` is `None`, then the
// scheduling is from a resource driver. As notifications often come in
// batches, the ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | addbfb9204be25a8621feb3f20b44a7c1f00edbd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/addbfb9204be25a8621feb3f20b44a7c1f00edbd/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:30 | .close(&mut self.shared.synced.lock().inject)
{
self.notify_all();
}
}
fn notify_parked_local(&self) {
super::counters::inc_num_inc_notify_local();
if let Some(index) = self.shared.idle.worker_to_notify(&self.shared) {
super::counters::inc_num_unparks_lo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | addbfb9204be25a8621feb3f20b44a7c1f00edbd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/addbfb9204be25a8621feb3f20b44a7c1f00edbd/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:31 | fn transition_worker_from_searching(&self) {
if self.shared.idle.transition_worker_from_searching() {
// We are the final searching worker. Because work was found, we
// need to notify another worker.
self.notify_parked_local();
}
}
/// Signals that a worker ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | addbfb9204be25a8621feb3f20b44a7c1f00edbd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/addbfb9204be25a8621feb3f20b44a7c1f00edbd/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:32 | 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::Notified<Arc<Handle>>>,
{
unsafe {
self.shared.inject.push_batch(self, iter);
}
}
}
pub(crate) struct Injec... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | addbfb9204be25a8621feb3f20b44a7c1f00edbd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/addbfb9204be25a8621feb3f20b44a7c1f00edbd/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,241 | 1,283 |
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 | 605ef578df04f12a951060dc3b2fb930f6f379fe | github | async-runtime | https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:21 | 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
.handle
.next_remote_task()
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 605ef578df04f12a951060dc3b2fb930f6f379fe | github | async-runtime | https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/runtime/scheduler/multi_thread/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:22 | 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 = tasks.next();
// Push the ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 605ef578df04f12a951060dc3b2fb930f6f379fe | github | async-runtime | https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/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
worker.handle.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 605ef578df04f12a951060dc3b2fb930f6f379fe | github | async-runtime | https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/runtime/scheduler/multi_thread/worker.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:24 | }
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 {
// Workers should not park i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 605ef578df04f12a951060dc3b2fb930f6f379fe | github | async-runtime | https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/runtime/scheduler/multi_thread/worker.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:25 | // 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
.idle
.unpark_worker_by_id(&worker.handle.shared, worker.in... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 605ef578df04f12a951060dc3b2fb930f6f379fe | github | async-runtime | https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/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(worker.han... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 605ef578df04f12a951060dc3b2fb930f6f379fe | github | async-runtime | https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/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 | 605ef578df04f12a951060dc3b2fb930f6f379fe | github | async-runtime | https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:28 | }
}
}
// 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(task) = task {
sel... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 605ef578df04f12a951060dc3b2fb930f6f379fe | github | async-runtime | https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:29 | };
// Only notify if not currently parked. If `park` is `None`, then the
// scheduling is from a resource driver. As notifications often come in
// batches, the notification is delayed until the park is complete.
if should_notify && core.park.is_some() {
self.notify_parked_l... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 605ef578df04f12a951060dc3b2fb930f6f379fe | github | async-runtime | https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:31 | }
/// Signals that a worker has observed the shutdown signal and has replaced
/// its core back into its handle.
///
/// If all workers have reached this point, the final cleanup is performed.
fn shutdown_core(&self, core: Box<Core>) {
let mut cores = self.shared.shutdown_cores.lock();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 605ef578df04f12a951060dc3b2fb930f6f379fe | github | async-runtime | https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:32 | I: Iterator<Item = task::Notified<Arc<Handle>>>,
{
unsafe {
self.shared.inject.push_batch(self, iter);
}
}
}
pub(crate) struct InjectGuard<'a> {
lock: crate::loom::sync::MutexGuard<'a, Synced>,
}
impl<'a> AsMut<inject::Synced> for InjectGuard<'a> {
fn as_mut(&mut self) -> &... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 605ef578df04f12a951060dc3b2fb930f6f379fe | github | async-runtime | https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,241 | 1,277 |
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 | b8ac94ed70df22f885bad7ea3c0ff51c536bad4a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b8ac94ed70df22f885bad7ea3c0ff51c536bad4a/tokio/src/runtime/scheduler/multi_thread/worker.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:3 | mod taskdump;
}
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: Ato... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b8ac94ed70df22f885bad7ea3c0ff51c536bad4a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b8ac94ed70df22f885bad7ea3c0ff51c536bad4a/tokio/src/runtime/scheduler/multi_thread/worker.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:4 | is_searching: bool,
/// 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>,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b8ac94ed70df22f885bad7ea3c0ff51c536bad4a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b8ac94ed70df22f885bad7ea3c0ff51c536bad4a/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 | b8ac94ed70df22f885bad7ea3c0ff51c536bad4a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b8ac94ed70df22f885bad7ea3c0ff51c536bad4a/tokio/src/runtime/scheduler/multi_thread/worker.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:6 | /// Steals tasks from this worker.
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 ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b8ac94ed70df22f885bad7ea3c0ff51c536bad4a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b8ac94ed70df22f885bad7ea3c0ff51c536bad4a/tokio/src/runtime/scheduler/multi_thread/worker.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:7 | pub(super) fn create(
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);
le... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b8ac94ed70df22f885bad7ea3c0ff51c536bad4a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b8ac94ed70df22f885bad7ea3c0ff51c536bad4a/tokio/src/runtime/scheduler/multi_thread/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:8 | let (inject, inject_synced) = inject::Shared::new();
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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b8ac94ed70df22f885bad7ea3c0ff51c536bad4a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b8ac94ed70df22f885bad7ea3c0ff51c536bad4a/tokio/src/runtime/scheduler/multi_thread/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:9 | pub(crate) fn block_in_place<F, R>(f: F) -> R
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(c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b8ac94ed70df22f885bad7ea3c0ff51c536bad4a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b8ac94ed70df22f885bad7ea3c0ff51c536bad4a/tokio/src/runtime/scheduler/multi_thread/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:10 | crate::runtime::context::current_enter_context(),
maybe_cx.is_some(),
) {
(context::EnterRuntime::Entered { .. }, true) => {
// We are on a thread pool runtime thread, so we just need to
// set up blocking.
had_entered = true;
}... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b8ac94ed70df22f885bad7ea3c0ff51c536bad4a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b8ac94ed70df22f885bad7ea3c0ff51c536bad4a/tokio/src/runtime/scheduler/multi_thread/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:11 | let cx = maybe_cx.expect("no .is_some() == false cases above should lead here");
// Get the worker core. If none is set, then blocking is fine!
let mut core = match cx.core.borrow_mut().take() {
Some(core) => core,
None => return Ok(()),
};
// If we heavily call... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b8ac94ed70df22f885bad7ea3c0ff51c536bad4a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b8ac94ed70df22f885bad7ea3c0ff51c536bad4a/tokio/src/runtime/scheduler/multi_thread/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:12 | panic!("{}", panic_message);
}
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)
} ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b8ac94ed70df22f885bad7ea3c0ff51c536bad4a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b8ac94ed70df22f885bad7ea3c0ff51c536bad4a/tokio/src/runtime/scheduler/multi_thread/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:13 | #[cfg(debug_assertions)]
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.wor... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b8ac94ed70df22f885bad7ea3c0ff51c536bad4a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b8ac94ed70df22f885bad7ea3c0ff51c536bad4a/tokio/src/runtime/scheduler/multi_thread/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:14 | // a task that had the LIFO slot disabled.
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 {
sel... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b8ac94ed70df22f885bad7ea3c0ff51c536bad4a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b8ac94ed70df22f885bad7ea3c0ff51c536bad4a/tokio/src/runtime/scheduler/multi_thread/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:15 | self.park(core)
};
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>... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b8ac94ed70df22f885bad7ea3c0ff51c536bad4a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b8ac94ed70df22f885bad7ea3c0ff51c536bad4a/tokio/src/runtime/scheduler/multi_thread/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:16 | task.run();
#[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 {
// C... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b8ac94ed70df22f885bad7ea3c0ff51c536bad4a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b8ac94ed70df22f885bad7ea3c0ff51c536bad4a/tokio/src/runtime/scheduler/multi_thread/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:17 | &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);
return Ok(core);
}
// Track that we are ab... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b8ac94ed70df22f885bad7ea3c0ff51c536bad4a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b8ac94ed70df22f885bad7ea3c0ff51c536bad4a/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_s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b8ac94ed70df22f885bad7ea3c0ff51c536bad4a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b8ac94ed70df22f885bad7ea3c0ff51c536bad4a/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:19 | /// from where other workers can pick them up.
/// 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();... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b8ac94ed70df22f885bad7ea3c0ff51c536bad4a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b8ac94ed70df22f885bad7ea3c0ff51c536bad4a/tokio/src/runtime/scheduler/multi_thread/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:20 | *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();
// Remove `core` from context
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b8ac94ed70df22f885bad7ea3c0ff51c536bad4a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b8ac94ed70df22f885bad7ea3c0ff51c536bad4a/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:7 | pub(super) fn create(
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);
le... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 542197cdb9031384b05ab81b64c6b6dc057a3dfc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/542197cdb9031384b05ab81b64c6b6dc057a3dfc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:8 | let (inject, inject_synced) = inject::Shared::new();
let remotes_len = remotes.len();
let handle = Arc::new(Handle {
task_hooks: TaskHooks {
task_spawn_callback: config.before_spawn.clone(),
task_terminate_callback: config.after_termination.clone(),
},
shared: Sh... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 542197cdb9031384b05ab81b64c6b6dc057a3dfc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/542197cdb9031384b05ab81b64c6b6dc057a3dfc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:9 | }
#[track_caller]
pub(crate) fn block_in_place<F, R>(f: F) -> R
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| {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 542197cdb9031384b05ab81b64c6b6dc057a3dfc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/542197cdb9031384b05ab81b64c6b6dc057a3dfc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:10 | let setup_result = with_current(|maybe_cx| {
match (
crate::runtime::context::current_enter_context(),
maybe_cx.is_some(),
) {
(context::EnterRuntime::Entered { .. }, true) => {
// We are on a thread pool runtime thread, so we just need to
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 542197cdb9031384b05ab81b64c6b6dc057a3dfc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/542197cdb9031384b05ab81b64c6b6dc057a3dfc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:11 | }
}
let cx = maybe_cx.expect("no .is_some() == false cases above should lead here");
// Get the worker core. If none is set, then blocking is fine!
let mut core = match cx.core.borrow_mut().take() {
Some(core) => core,
None => return Ok(()),
};
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 542197cdb9031384b05ab81b64c6b6dc057a3dfc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/542197cdb9031384b05ab81b64c6b6dc057a3dfc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:12 | });
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 {
take_core,
budget: coop::stop(),
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 542197cdb9031384b05ab81b64c6b6dc057a3dfc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/542197cdb9031384b05ab81b64c6b6dc057a3dfc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:13 | // Catching panics on worker threads in tests is quite tricky. Instead, when
// debug assertions are enabled, we just abort the process.
#[cfg(debug_assertions)]
let _abort_on_panic = AbortOnPanic;
// Acquire a core. If this fails, then another thread is running this
// worker and there is nothing ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 542197cdb9031384b05ab81b64c6b6dc057a3dfc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/542197cdb9031384b05ab81b64c6b6dc057a3dfc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:14 | impl Context {
fn run(&self, mut core: Box<Core>) -> RunResult {
// Reset `lifo_enabled` here in case the core was previously stolen from
// a task that had the LIFO slot disabled.
self.reset_lifo_enabled(&mut core);
// Start as "processing" tasks as polling tasks from the local que... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 542197cdb9031384b05ab81b64c6b6dc057a3dfc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/542197cdb9031384b05ab81b64c6b6dc057a3dfc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:15 | core = if !self.defer.is_empty() {
self.park_timeout(core, Some(Duration::from_millis(0)))
} else {
self.park(core)
};
core.stats.start_processing_scheduled_tasks();
}
}
core.pre_shutdown(&self.worker);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 542197cdb9031384b05ab81b64c6b6dc057a3dfc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/542197cdb9031384b05ab81b64c6b6dc057a3dfc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:16 | loop {
// Check if we still have the core. If not, the core was stolen
// by another worker.
let mut core = match self.core.borrow_mut().take() {
Some(core) => core,
None => {
// In this case, we cannot call ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 542197cdb9031384b05ab81b64c6b6dc057a3dfc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/542197cdb9031384b05ab81b64c6b6dc057a3dfc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:17 | 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 | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 542197cdb9031384b05ab81b64c6b6dc057a3dfc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/542197cdb9031384b05ab81b64c6b6dc057a3dfc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:18 | // Call `park` with a 0 timeout. This enables the I/O driver, timer, ...
// to run without actually putting the thread to sleep.
core = self.park_timeout(core, Some(Duration::from_millis(0)));
// Run regularly scheduled maintenance
core.maintenance(&self.worker);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 542197cdb9031384b05ab81b64c6b6dc057a3dfc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/542197cdb9031384b05ab81b64c6b6dc057a3dfc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:19 | core.maintenance(&self.worker);
if core.transition_from_parked(&self.worker) {
break;
}
}
}
if let Some(f) = &self.worker.handle.shared.config.after_unpark {
f();
}
core
}
fn park_timeout(&self, mut co... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 542197cdb9031384b05ab81b64c6b6dc057a3dfc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/542197cdb9031384b05ab81b64c6b6dc057a3dfc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:20 | }
core
}
pub(crate) fn defer(&self, waker: &Waker) {
self.defer.defer(waker);
}
#[allow(dead_code)]
pub(crate) fn get_worker_index(&self) -> usize {
self.worker.index
}
}
impl Core {
/// Increment the tick
fn tick(&mut self) {
self.tick = self.tick.wra... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 542197cdb9031384b05ab81b64c6b6dc057a3dfc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/542197cdb9031384b05ab81b64c6b6dc057a3dfc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:26 | /// Shuts down the core.
fn shutdown(&mut self, handle: &Handle) {
// Take the core
let mut park = self.park.take().expect("park missing");
// Drain the queue
while self.next_local_task().is_some() {}
park.shutdown(&handle.driver);
}
fn tune_global_queue_interval(&... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 542197cdb9031384b05ab81b64c6b6dc057a3dfc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/542197cdb9031384b05ab81b64c6b6dc057a3dfc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:27 | fn hooks(&self) -> TaskHarnessScheduleHooks {
TaskHarnessScheduleHooks {
task_terminate_callback: self.task_hooks.task_terminate_callback.clone(),
}
}
fn yield_now(&self, task: Notified) {
self.schedule_task(task, true);
}
}
impl Handle {
pub(super) fn schedule_task... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 542197cdb9031384b05ab81b64c6b6dc057a3dfc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/542197cdb9031384b05ab81b64c6b6dc057a3dfc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:28 | // Spawning from the worker thread. If scheduling a "yield" then the
// task must always be pushed to the back of the queue, enabling other
// tasks to be executed. If **not** a yield, then there is more
// flexibility and the task may go to the front of the queue.
let should_notify = if... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 542197cdb9031384b05ab81b64c6b6dc057a3dfc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/542197cdb9031384b05ab81b64c6b6dc057a3dfc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:29 | }
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.shared.inject.push(&mut synced.inject, task);
}
}... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 542197cdb9031384b05ab81b64c6b6dc057a3dfc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/542197cdb9031384b05ab81b64c6b6dc057a3dfc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:30 | }
}
fn notify_if_work_pending(&self) {
for remote in &self.shared.remotes[..] {
if !remote.steal.is_empty() {
self.notify_parked_local();
return;
}
}
if !self.shared.inject.is_empty() {
self.notify_parked_local();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 542197cdb9031384b05ab81b64c6b6dc057a3dfc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/542197cdb9031384b05ab81b64c6b6dc057a3dfc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:31 | }
// 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::eq(self, other)
}
}
impl... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 542197cdb9031384b05ab81b64c6b6dc057a3dfc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/542197cdb9031384b05ab81b64c6b6dc057a3dfc/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,201 | 1,259 |
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 | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:3 | cfg_taskdump! {
mod taskdump;
}
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 t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/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 worker is currently searching for more work. Searching
/// involves attempting to steal from other workers.
is_searching: bool,
/// True if the scheduler is being shutdown
is_shutdown: bool,
/// True if the scheduler is being traced
is_traced: bool,
/// Parker
///
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:5 | /// Collection of all active tasks spawned onto this executor.
pub(crate) owned: OwnedTasks<Arc<Handle>>,
/// 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 avo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:6 | /// Used to communicate with a worker from other threads.
struct Remote {
/// Steals tasks from this worker.
pub(super) steal: queue::Steal<Arc<Handle>>,
/// Unparks the associated worker thread
unpark: Unparker,
}
/// Thread-local context
pub(crate) struct Context {
/// Worker
worker: Arc<Wor... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:7 | const MAX_LIFO_POLLS_PER_TICK: usize = 3;
pub(super) fn create(
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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:8 | let (idle, idle_synced) = Idle::new(size);
let (inject, inject_synced) = inject::Shared::new();
let remotes_len = remotes.len();
let handle = Arc::new(Handle {
task_hooks: TaskHooks {
task_spawn_callback: config.before_spawn.clone(),
task_terminate_callback: config.after_ter... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:9 | (handle, launch)
}
#[track_caller]
pub(crate) fn block_in_place<F, R>(f: F) -> R
where
F: FnOnce() -> R,
{
// Try to steal the worker core back
struct Reset {
take_core: bool,
budget: coop::Budget,
}
impl Drop for Reset {
fn drop(&mut self) {
with_current(|maybe... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:10 | let mut had_entered = false;
let mut take_core = false;
let setup_result = with_current(|maybe_cx| {
match (
crate::runtime::context::current_enter_context(),
maybe_cx.is_some(),
) {
(context::EnterRuntime::Entered { .. }, true) => {
// We are... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:11 | // We can also skip all of the thread pool blocking setup steps.
return Ok(());
}
}
let cx = maybe_cx.expect("no .is_some() == false cases above should lead here");
// Get the worker core. If none is set, then blocking is fine!
let mut core = match cx.core.b... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:12 | runtime::spawn_blocking(move || run(worker));
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 {... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:13 | }
}
// Catching panics on worker threads in tests is quite tricky. Instead, when
// debug assertions are enabled, we just abort the process.
#[cfg(debug_assertions)]
let _abort_on_panic = AbortOnPanic;
// Acquire a core. If this fails, then another thread is running this
// worker and ther... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:14 | }
impl Context {
fn run(&self, mut core: Box<Core>) -> RunResult {
// Reset `lifo_enabled` here in case the core was previously stolen from
// a task that had the LIFO slot disabled.
self.reset_lifo_enabled(&mut core);
// Start as "processing" tasks as polling tasks from the local ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:15 | } else {
// Wait for work
core = if !self.defer.is_empty() {
self.park_timeout(core, Some(Duration::from_millis(0)))
} else {
self.park(core)
};
core.stats.start_processing_scheduled_tasks();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:16 | // As long as there is budget remaining and a task exists in the
// `lifo_slot`, then keep running.
loop {
// Check if we still have the core. If not, the core was stolen
// by another worker.
let mut core = match self.core.borrow_mut().take() {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:17 | // 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
//
// In ping-ping style workloads where task A notifies task B,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:18 | core.stats.end_processing_scheduled_tasks();
// Call `park` with a 0 timeout. This enables the I/O driver, timer, ...
// to run without actually putting the thread to sleep.
core = self.park_timeout(core, Some(Duration::from_millis(0)));
// Run regularly scheduled maint... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:19 | // Run regularly scheduled maintenance
core.maintenance(&self.worker);
if core.transition_from_parked(&self.worker) {
break;
}
}
}
if let Some(f) = &self.worker.handle.shared.config.after_unpark {
f();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:20 | if core.should_notify_others() {
self.worker.handle.notify_parked_local();
}
core
}
pub(crate) fn defer(&self, waker: &Waker) {
self.defer.defer(waker);
}
#[allow(dead_code)]
pub(crate) fn get_worker_index(&self) -> usize {
self.worker.index
}
}
im... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:22 | self.lifo_slot.take().or_else(|| self.run_queue.pop())
}
/// Function responsible for stealing tasks from another worker
///
/// Note: Only if less than half the workers are searching for tasks to steal
/// a new worker will actually try to steal. The idea is to make sure not all
/// workers wi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:23 | self.is_searching = worker.handle.shared.idle.transition_worker_to_searching();
}
self.is_searching
}
fn transition_from_searching(&mut self, worker: &Worker) {
if !self.is_searching {
return;
}
self.is_searching = false;
worker.handle.transition_wo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:24 | let is_last_searcher = worker.handle.shared.idle.transition_worker_to_parked(
&worker.handle.shared,
worker.index,
self.is_searching,
);
// The worker is no longer searching. Setting this is the local cache
// only.
self.is_searching = false;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:25 | return false;
}
// When unparked, the worker is in the searching state.
self.is_searching = true;
true
}
/// Runs maintenance work such as checking the pool's state.
fn maintenance(&mut self, worker: &Worker) {
self.stats
.submit(&worker.handle.shared.wo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:26 | .submit(&worker.handle.shared.worker_metrics[worker.index]);
}
/// Shuts down the core.
fn shutdown(&mut self, handle: &Handle) {
// Take the core
let mut park = self.park.take().expect("park missing");
// Drain the queue
while self.next_local_task().is_some() {}
p... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:27 | self.schedule_task(task, false);
}
fn hooks(&self) -> TaskHarnessScheduleHooks {
TaskHarnessScheduleHooks {
task_terminate_callback: self.task_hooks.task_terminate_callback.clone(),
}
}
fn yield_now(&self, task: Notified) {
self.schedule_task(task, true);
}
}
i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:28 | fn schedule_local(&self, core: &mut Core, task: Notified, is_yield: bool) {
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 **no... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:29 | // safety: passing in correct `idle::Synced`
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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:30 | for remote in &self.shared.remotes[..] {
remote.unpark.unpark(&self.driver);
}
}
fn notify_if_work_pending(&self) {
for remote in &self.shared.remotes[..] {
if !remote.steal.is_empty() {
self.notify_parked_local();
return;
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:31 | for mut core in cores.drain(..) {
core.shutdown(self);
}
// Drain the injection queue
//
// We already shut down every task, so we can simply drop the tasks.
while let Some(task) = self.next_remote_task() {
drop(task);
}
}
fn ptr_eq(&self... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/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::Mul... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread/worker.rs | 1,241 | 1,261 |
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 | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread/worker.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:7 | const MAX_LIFO_POLLS_PER_TICK: usize = 3;
pub(super) fn create(
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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:8 | let (idle, idle_synced) = Idle::new(size);
let (inject, inject_synced) = inject::Shared::new();
let remotes_len = remotes.len();
let handle = Arc::new(Handle {
shared: Shared {
remotes: remotes.into_boxed_slice(),
inject,
idle,
owned: OwnedTasks::new(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 17819062e27b48570dd7f510b8bf8cf7b0e52cf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/17819062e27b48570dd7f510b8bf8cf7b0e52cf4/tokio/src/runtime/scheduler/multi_thread/worker.rs | 281 | 340 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.