id stringlengths 22 133 | text stringlengths 40 40.2k | arch stringclasses 1
value | syntax stringclasses 1
value | kind stringclasses 4
values | repo stringclasses 27
values | path stringlengths 5 116 | license stringclasses 6
values | commit stringlengths 40 40 | source_host stringclasses 1
value | category stringclasses 16
values | source_url stringlengths 85 196 | line_start int64 1 4.28k | line_end int64 4 4.31k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:17 | }
/// Returns `true` if the transition happened.
fn transition_from_parked(&mut self, worker: &Worker) -> bool {
// If a task is in the lifo slot, then we must unpark regardless of
// being notified
if self.lifo_slot.is_some() {
// When a worker wakes, it should only transit... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cba5c1009e3a1e6a0e87afcd380f2427485785ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cba5c1009e3a1e6a0e87afcd380f2427485785ec/tokio/src/runtime/scheduler/multi_thread/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:18 | self.metrics
.submit(&worker.handle.shared.worker_metrics[worker.index]);
}
/// Shuts down the core.
fn shutdown(&mut self) {
// Take the core
let mut park = self.park.take().expect("park missing");
// Drain the queue
while self.next_local_task().is_some() {}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cba5c1009e3a1e6a0e87afcd380f2427485785ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cba5c1009e3a1e6a0e87afcd380f2427485785ec/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:19 | CURRENT.with(|maybe_cx| {
if let Some(cx) = maybe_cx {
// Make sure the task is part of the **current** scheduler.
if self.ptr_eq(&cx.worker.handle.shared) {
// And the current thread still holds a core
if let Some(core) = cx.core.borro... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cba5c1009e3a1e6a0e87afcd380f2427485785ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cba5c1009e3a1e6a0e87afcd380f2427485785ec/tokio/src/runtime/scheduler/multi_thread/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:20 | 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 notification is delayed until the park is complete.
if should_notify && ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cba5c1009e3a1e6a0e87afcd380f2427485785ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cba5c1009e3a1e6a0e87afcd380f2427485785ec/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:21 | self.notify_parked();
}
}
fn transition_worker_from_searching(&self) {
if self.idle.transition_worker_from_searching() {
// We are the final searching worker. Because work was found, we
// need to notify another worker.
self.notify_parked();
}
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cba5c1009e3a1e6a0e87afcd380f2427485785ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cba5c1009e3a1e6a0e87afcd380f2427485785ec/tokio/src/runtime/scheduler/multi_thread/worker.rs | 801 | 854 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:22 | }
}
cfg_metrics! {
impl Shared {
pub(super) fn injection_queue_depth(&self) -> usize {
self.inject.len()
}
pub(super) fn worker_local_queue_depth(&self, worker: usize) -> usize {
self.remotes[worker].steal.len()
}
}
} | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cba5c1009e3a1e6a0e87afcd380f2427485785ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cba5c1009e3a1e6a0e87afcd380f2427485785ec/tokio/src/runtime/scheduler/multi_thread/worker.rs | 841 | 854 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:10 | };
// Set the worker context.
let cx = Context {
worker,
core: RefCell::new(None),
};
let _enter = crate::runtime::enter(true);
CURRENT.set(&cx, || {
// This should always be an error. It only returns a `Result` to support
// using `?` to short circuit.
ass... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cdd6eeaf70351220df05126a7f0c353b0058dc95 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cdd6eeaf70351220df05126a7f0c353b0058dc95/tokio/src/runtime/scheduler/multi_thread/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:11 | }
core.pre_shutdown(&self.worker);
// Signal shutdown
self.worker.handle.shared.shutdown(core);
Err(())
}
fn run_task(&self, task: Notified, mut core: Box<Core>) -> RunResult {
let task = self.worker.handle.shared.owned.assert_owner(task);
// Make sure the wor... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cdd6eeaf70351220df05126a7f0c353b0058dc95 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cdd6eeaf70351220df05126a7f0c353b0058dc95/tokio/src/runtime/scheduler/multi_thread/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:13 | /// after all the IOs get dispatched
fn park(&self, mut core: Box<Core>) -> Box<Core> {
if let Some(f) = &self.worker.handle.shared.config.before_park {
f();
}
if core.transition_to_parked(&self.worker) {
while !core.is_shutdown {
core.metrics.about_t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cdd6eeaf70351220df05126a7f0c353b0058dc95 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cdd6eeaf70351220df05126a7f0c353b0058dc95/tokio/src/runtime/scheduler/multi_thread/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:14 | // Remove `core` from context
core = self.core.borrow_mut().take().expect("core missing");
// Place `park` back in `core`
core.park = Some(park);
// If there are tasks available to steal, but this worker is not
// looking for tasks to steal, notify another worker.
if !c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cdd6eeaf70351220df05126a7f0c353b0058dc95 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cdd6eeaf70351220df05126a7f0c353b0058dc95/tokio/src/runtime/scheduler/multi_thread/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:15 | /// workers will be trying to steal at the same time.
fn steal_work(&mut self, worker: &Worker) -> Option<Notified> {
if !self.transition_to_searching(worker) {
return None;
}
let num = worker.handle.shared.remotes.len();
// Start from a random worker
let start =... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cdd6eeaf70351220df05126a7f0c353b0058dc95 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cdd6eeaf70351220df05126a7f0c353b0058dc95/tokio/src/runtime/scheduler/multi_thread/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:16 | if !self.is_searching {
return;
}
self.is_searching = false;
worker.handle.shared.transition_worker_from_searching();
}
/// Prepares the worker state for parking.
///
/// Returns true if the transition happened, false if there is work to do first.
fn transition_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cdd6eeaf70351220df05126a7f0c353b0058dc95 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cdd6eeaf70351220df05126a7f0c353b0058dc95/tokio/src/runtime/scheduler/multi_thread/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:17 | // being notified
if self.lifo_slot.is_some() {
// When a worker wakes, it should only transition to the "searching"
// state when the wake originates from another worker *or* a new task
// is pushed. We do *not* want the worker to transition to "searching"
// whe... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cdd6eeaf70351220df05126a7f0c353b0058dc95 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cdd6eeaf70351220df05126a7f0c353b0058dc95/tokio/src/runtime/scheduler/multi_thread/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:18 | /// Shuts down the core.
fn shutdown(&mut self) {
// Take the core
let mut park = self.park.take().expect("park missing");
// Drain the queue
while self.next_local_task().is_some() {}
park.shutdown();
}
}
impl Worker {
/// Returns a reference to the scheduler's inj... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cdd6eeaf70351220df05126a7f0c353b0058dc95 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cdd6eeaf70351220df05126a7f0c353b0058dc95/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:19 | if let Some(core) = cx.core.borrow_mut().as_mut() {
self.schedule_local(core, task, is_yield);
return;
}
}
}
// Otherwise, use the inject queue.
self.inject.push(task);
self.scheduler_met... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cdd6eeaf70351220df05126a7f0c353b0058dc95 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cdd6eeaf70351220df05126a7f0c353b0058dc95/tokio/src/runtime/scheduler/multi_thread/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:20 | // Only notify if not currently parked. If `park` is `None`, then the
// scheduling is from a resource driver. As notifications often come in
// batches, the notification is delayed until the park is complete.
if should_notify && core.park.is_some() {
self.notify_parked();
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cdd6eeaf70351220df05126a7f0c353b0058dc95 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cdd6eeaf70351220df05126a7f0c353b0058dc95/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:21 | if self.idle.transition_worker_from_searching() {
// We are the final searching worker. Because work was found, we
// need to notify another worker.
self.notify_parked();
}
}
/// Signals that a worker has observed the shutdown signal and has replaced
/// its core... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | cdd6eeaf70351220df05126a7f0c353b0058dc95 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cdd6eeaf70351220df05126a7f0c353b0058dc95/tokio/src/runtime/scheduler/multi_thread/worker.rs | 801 | 849 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:2 | //! inject queue.
//!
//! The first case can only happen if the OwnedTasks::bind call happens before
//! or during step 1 of shutdown. In this case, the runtime will clean up the
//! task in step 3 of shutdown.
//!
//! In the latter case, the task was not spawned and the task is immediately
//! cancelled by the spaw... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/scheduler/multi_thread/worker.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:3 | /// Used to hand-off a worker's core to another thread.
core: AtomicCell<Core>,
}
/// Core data
struct Core {
/// Used to schedule bookkeeping tasks every so often.
tick: u32,
/// When a task is scheduled from a worker, it is stored in this slot. The
/// worker will check this slot for a task **be... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/scheduler/multi_thread/worker.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:4 | pub(super) struct Shared {
/// Per-worker remote state. All other workers have access to this and is
/// how they communicate between each other.
remotes: Box<[Remote]>,
/// Global task queue used for:
/// 1. Submit work to the scheduler while **not** currently on a worker thread.
/// 2. Subm... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/scheduler/multi_thread/worker.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:5 | /// Thread-local context
struct Context {
/// Worker
worker: Arc<Worker>,
/// Core data
core: RefCell<Option<Box<Core>>>,
}
/// Starts the workers
pub(crate) struct Launch(Vec<Arc<Worker>>);
/// Running a task may consume the core. If the core is still available when
/// running the task completes, i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/scheduler/multi_thread/worker.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:6 | tick: 0,
lifo_slot: None,
run_queue,
is_searching: false,
is_shutdown: false,
park: Some(park),
metrics: MetricsBatch::new(),
rand: FastRand::new(config.seed_generator.next_seed()),
}));
remotes.push(Remote { steal, unp... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/scheduler/multi_thread/worker.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:7 | F: FnOnce() -> R,
{
// Try to steal the worker core back
struct Reset(coop::Budget);
impl Drop for Reset {
fn drop(&mut self) {
CURRENT.with(|maybe_cx| {
if let Some(cx) = maybe_cx {
let core = cx.worker.core.take();
let mut cx_cor... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/scheduler/multi_thread/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:8 | // LocalSet, where it is _not_ okay to block.
panic!("can call blocking only when running on the multi-threaded runtime");
}
}
(EnterContext::NotEntered, true) => {
// This is a nested call to block_in_place (we already exited).
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/scheduler/multi_thread/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:9 | });
if had_entered {
// Unset the current task's budget. Blocking sections are not
// constrained by task budgets.
let _reset = Reset(coop::stop());
crate::runtime::enter::exit(f)
} else {
f()
}
}
impl Launch {
pub(crate) fn launch(mut self) {
for worke... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/scheduler/multi_thread/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:10 | assert!(cx.run(core).is_err());
});
}
impl Context {
fn run(&self, mut core: Box<Core>) -> RunResult {
while !core.is_shutdown {
// Increment the tick
core.tick();
// Run maintenance, if needed
core = self.maintenance(core);
// First, check ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/scheduler/multi_thread/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:11 | // another idle worker to try to steal work.
core.transition_from_searching(&self.worker);
// Make the core available to the runtime context
core.metrics.incr_poll_count();
*self.core.borrow_mut() = Some(core);
// Run the task
coop::budget(|| {
task.run();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/scheduler/multi_thread/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:12 | }
})
}
fn maintenance(&self, mut core: Box<Core>) -> Box<Core> {
if core.tick % self.worker.shared.config.event_interval == 0 {
// Call `park` with a 0 timeout. This enables the I/O driver, timer, ...
// to run without actually putting the thread to sleep.
co... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/scheduler/multi_thread/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:13 | core.maintenance(&self.worker);
if core.transition_from_parked(&self.worker) {
break;
}
}
}
if let Some(f) = &self.worker.shared.config.after_unpark {
f();
}
core
}
fn park_timeout(&self, mut core: Box... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/scheduler/multi_thread/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:14 | core
}
}
impl Core {
/// Increment the tick
fn tick(&mut self) {
self.tick = self.tick.wrapping_add(1);
}
/// Return the next notified task available to this worker.
fn next_task(&mut self, worker: &Worker) -> Option<Notified> {
if self.tick % worker.shared.config.global_queue_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/scheduler/multi_thread/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:15 | // Don't steal from ourself! We know we don't have work.
if i == worker.index {
continue;
}
let target = &worker.shared.remotes[i];
if let Some(task) = target
.steal
.steal_into(&mut self.run_queue, &mut self.metrics)
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/scheduler/multi_thread/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:16 | if self.lifo_slot.is_some() || self.run_queue.has_tasks() {
return false;
}
// When the final worker transitions **out** of searching to parked, it
// must check all the queues one last time in case work materialized
// between the last work scan and transitioning out of sea... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/scheduler/multi_thread/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:17 | // When unparked, the worker is in the searching state.
self.is_searching = true;
true
}
/// Runs maintenance work such as checking the pool's state.
fn maintenance(&mut self, worker: &Worker) {
self.metrics
.submit(&worker.shared.worker_metrics[worker.index]);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/scheduler/multi_thread/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:18 | fn inject(&self) -> &Inject<Arc<Shared>> {
&self.shared.inject
}
}
impl task::Schedule for Arc<Shared> {
fn release(&self, task: &Task) -> Option<Task> {
self.owned.remove(task)
}
fn schedule(&self, task: Notified) {
(**self).schedule(task, false);
}
fn yield_now(&self... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:19 | if let Some(cx) = maybe_cx {
// Make sure the task is part of the **current** scheduler.
if self.ptr_eq(&cx.worker.shared) {
// And the current thread still holds a core
if let Some(core) = cx.core.borrow_mut().as_mut() {
se... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/scheduler/multi_thread/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:20 | ret
};
// Only notify if not currently parked. If `park` is `None`, then the
// scheduling is from a resource driver. As notifications often come in
// batches, the notification is delayed until the park is complete.
if should_notify && core.park.is_some() {
self.not... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:21 | }
}
fn transition_worker_from_searching(&self) {
if self.idle.transition_worker_from_searching() {
// We are the final searching worker. Because work was found, we
// need to notify another worker.
self.notify_parked();
}
}
/// Signals that a worker ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | b5709baa917494043e21589adb10347c57361f1f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b5709baa917494043e21589adb10347c57361f1f/tokio/src/runtime/scheduler/multi_thread/worker.rs | 801 | 853 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:2 | //! inject queue.
//!
//! The first case can only happen if the OwnedTasks::bind call happens before
//! or during step 1 of shutdown. In this case, the runtime will clean up the
//! task in step 3 of shutdown.
//!
//! In the latter case, the task was not spawned and the task is immediately
//! cancelled by the spaw... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 56ffea09e5ab682e49eab0374da651f277e72566 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/56ffea09e5ab682e49eab0374da651f277e72566/tokio/src/runtime/scheduler/multi_thread/worker.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:3 | /// Used to hand-off a worker's core to another thread.
core: AtomicCell<Core>,
}
/// Core data
struct Core {
/// Used to schedule bookkeeping tasks every so often.
tick: u32,
/// When a task is scheduled from a worker, it is stored in this slot. The
/// worker will check this slot for a task **be... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 56ffea09e5ab682e49eab0374da651f277e72566 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/56ffea09e5ab682e49eab0374da651f277e72566/tokio/src/runtime/scheduler/multi_thread/worker.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:4 | /// State shared across all workers
pub(super) struct Shared {
/// Per-worker remote state. All other workers have access to this and is
/// how they communicate between each other.
remotes: Box<[Remote]>,
/// Global task queue used for:
/// 1. Submit work to the scheduler while **not** currently ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 56ffea09e5ab682e49eab0374da651f277e72566 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/56ffea09e5ab682e49eab0374da651f277e72566/tokio/src/runtime/scheduler/multi_thread/worker.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:5 | }
/// Thread-local context
struct Context {
/// Worker
worker: Arc<Worker>,
/// Core data
core: RefCell<Option<Box<Core>>>,
}
/// Starts the workers
pub(crate) struct Launch(Vec<Arc<Worker>>);
/// Running a task may consume the core. If the core is still available when
/// running the task completes... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 56ffea09e5ab682e49eab0374da651f277e72566 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/56ffea09e5ab682e49eab0374da651f277e72566/tokio/src/runtime/scheduler/multi_thread/worker.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:6 | cores.push(Box::new(Core {
tick: 0,
lifo_slot: None,
run_queue,
is_searching: false,
is_shutdown: false,
park: Some(park),
metrics: MetricsBatch::new(),
rand: FastRand::new(seed()),
}));
remotes.push(Remote ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 56ffea09e5ab682e49eab0374da651f277e72566 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/56ffea09e5ab682e49eab0374da651f277e72566/tokio/src/runtime/scheduler/multi_thread/worker.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:7 | where
F: FnOnce() -> R,
{
// Try to steal the worker core back
struct Reset(coop::Budget);
impl Drop for Reset {
fn drop(&mut self) {
CURRENT.with(|maybe_cx| {
if let Some(cx) = maybe_cx {
let core = cx.worker.core.take();
let ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 56ffea09e5ab682e49eab0374da651f277e72566 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/56ffea09e5ab682e49eab0374da651f277e72566/tokio/src/runtime/scheduler/multi_thread/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:8 | // This probably means we are on the current_thread runtime or in a
// LocalSet, where it is _not_ okay to block.
panic!("can call blocking only when running on the multi-threaded runtime");
}
}
(EnterContext::NotEntered, true) => {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 56ffea09e5ab682e49eab0374da651f277e72566 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/56ffea09e5ab682e49eab0374da651f277e72566/tokio/src/runtime/scheduler/multi_thread/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:9 | runtime::spawn_blocking(move || run(worker));
});
if had_entered {
// Unset the current task's budget. Blocking sections are not
// constrained by task budgets.
let _reset = Reset(coop::stop());
crate::runtime::enter::exit(f)
} else {
f()
}
}
impl Launch {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 56ffea09e5ab682e49eab0374da651f277e72566 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/56ffea09e5ab682e49eab0374da651f277e72566/tokio/src/runtime/scheduler/multi_thread/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:10 | // using `?` to short circuit.
assert!(cx.run(core).is_err());
});
}
impl Context {
fn run(&self, mut core: Box<Core>) -> RunResult {
while !core.is_shutdown {
// Increment the tick
core.tick();
// Run maintenance, if needed
core = self.maintenan... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 56ffea09e5ab682e49eab0374da651f277e72566 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/56ffea09e5ab682e49eab0374da651f277e72566/tokio/src/runtime/scheduler/multi_thread/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:11 | // Make sure the worker is not in the **searching** state. This enables
// another idle worker to try to steal work.
core.transition_from_searching(&self.worker);
// Make the core available to the runtime context
core.metrics.incr_poll_count();
*self.core.borrow_mut() = Some(cor... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 56ffea09e5ab682e49eab0374da651f277e72566 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/56ffea09e5ab682e49eab0374da651f277e72566/tokio/src/runtime/scheduler/multi_thread/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:12 | }
}
})
}
fn maintenance(&self, mut core: Box<Core>) -> Box<Core> {
if core.tick % self.worker.shared.config.event_interval == 0 {
// Call `park` with a 0 timeout. This enables the I/O driver, timer, ...
// to run without actually putting the thread to sleep.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 56ffea09e5ab682e49eab0374da651f277e72566 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/56ffea09e5ab682e49eab0374da651f277e72566/tokio/src/runtime/scheduler/multi_thread/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:13 | // Run regularly scheduled maintenance
core.maintenance(&self.worker);
if core.transition_from_parked(&self.worker) {
break;
}
}
}
if let Some(f) = &self.worker.shared.config.after_unpark {
f();
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 56ffea09e5ab682e49eab0374da651f277e72566 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/56ffea09e5ab682e49eab0374da651f277e72566/tokio/src/runtime/scheduler/multi_thread/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:14 | core
}
}
impl Core {
/// Increment the tick
fn tick(&mut self) {
self.tick = self.tick.wrapping_add(1);
}
/// Return the next notified task available to this worker.
fn next_task(&mut self, worker: &Worker) -> Option<Notified> {
if self.tick % worker.shared.config.global_queue_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 56ffea09e5ab682e49eab0374da651f277e72566 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/56ffea09e5ab682e49eab0374da651f277e72566/tokio/src/runtime/scheduler/multi_thread/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:16 | // Workers should not park if they have work to do
if self.lifo_slot.is_some() || self.run_queue.has_tasks() {
return false;
}
// When the final worker transitions **out** of searching to parked, it
// must check all the queues one last time in case work materialized
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 56ffea09e5ab682e49eab0374da651f277e72566 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/56ffea09e5ab682e49eab0374da651f277e72566/tokio/src/runtime/scheduler/multi_thread/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:17 | // When unparked, the worker is in the searching state.
self.is_searching = true;
true
}
/// Runs maintenance work such as checking the pool's state.
fn maintenance(&mut self, worker: &Worker) {
self.metrics
.submit(&worker.shared.worker_metrics[worker.index]);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 56ffea09e5ab682e49eab0374da651f277e72566 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/56ffea09e5ab682e49eab0374da651f277e72566/tokio/src/runtime/scheduler/multi_thread/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:18 | /// Returns a reference to the scheduler's injection queue.
fn inject(&self) -> &Inject<Arc<Shared>> {
&self.shared.inject
}
}
impl task::Schedule for Arc<Shared> {
fn release(&self, task: &Task) -> Option<Task> {
self.owned.remove(task)
}
fn schedule(&self, task: Notified) {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 56ffea09e5ab682e49eab0374da651f277e72566 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/56ffea09e5ab682e49eab0374da651f277e72566/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:19 | CURRENT.with(|maybe_cx| {
if let Some(cx) = maybe_cx {
// Make sure the task is part of the **current** scheduler.
if self.ptr_eq(&cx.worker.shared) {
// And the current thread still holds a core
if let Some(core) = cx.core.borrow_mut()... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 56ffea09e5ab682e49eab0374da651f277e72566 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/56ffea09e5ab682e49eab0374da651f277e72566/tokio/src/runtime/scheduler/multi_thread/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:20 | 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 notification is delayed until the park is complete.
if should_notify && ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 56ffea09e5ab682e49eab0374da651f277e72566 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/56ffea09e5ab682e49eab0374da651f277e72566/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:2 | //! inject queue.
//!
//! The first case can only happen if the OwnedTasks::bind call happens before
//! or during step 1 of shutdown. In this case, the runtime will clean up the
//! task in step 3 of shutdown.
//!
//! In the latter case, the task was not spawned and the task is immediately
//! cancelled by the spaw... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a4f18b93b674a30771a4a0c023a65b099fa0920 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a4f18b93b674a30771a4a0c023a65b099fa0920/tokio/src/runtime/scheduler/multi_thread/worker.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:3 | /// Used to hand-off a worker's core to another thread.
core: AtomicCell<Core>,
}
/// Core data
struct Core {
/// Used to schedule bookkeeping tasks every so often.
tick: u32,
/// When a task is scheduled from a worker, it is stored in this slot. The
/// worker will check this slot for a task **be... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a4f18b93b674a30771a4a0c023a65b099fa0920 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a4f18b93b674a30771a4a0c023a65b099fa0920/tokio/src/runtime/scheduler/multi_thread/worker.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:4 | /// State shared across all workers
pub(super) struct Shared {
/// Handle to the I/O driver, timer, blocking spawner, ...
handle_inner: HandleInner,
/// Per-worker remote state. All other workers have access to this and is
/// how they communicate between each other.
remotes: Box<[Remote]>,
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a4f18b93b674a30771a4a0c023a65b099fa0920 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a4f18b93b674a30771a4a0c023a65b099fa0920/tokio/src/runtime/scheduler/multi_thread/worker.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:5 | /// Unparks the associated worker thread
unpark: Unparker,
}
/// Thread-local context
struct Context {
/// Worker
worker: Arc<Worker>,
/// Core data
core: RefCell<Option<Box<Core>>>,
}
/// Starts the workers
pub(crate) struct Launch(Vec<Arc<Worker>>);
/// Running a task may consume the core. If ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a4f18b93b674a30771a4a0c023a65b099fa0920 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a4f18b93b674a30771a4a0c023a65b099fa0920/tokio/src/runtime/scheduler/multi_thread/worker.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:6 | // Create the local queues
for _ in 0..size {
let (steal, run_queue) = queue::local();
let park = park.clone();
let unpark = park.unpark();
cores.push(Box::new(Core {
tick: 0,
lifo_slot: None,
run_queue,
is_searching: false,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a4f18b93b674a30771a4a0c023a65b099fa0920 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a4f18b93b674a30771a4a0c023a65b099fa0920/tokio/src/runtime/scheduler/multi_thread/worker.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:7 | index,
core: AtomicCell::new(Some(core)),
}));
}
(shared, launch)
}
pub(crate) fn block_in_place<F, R>(f: F) -> R
where
F: FnOnce() -> R,
{
// Try to steal the worker core back
struct Reset(coop::Budget);
impl Drop for Reset {
fn drop(&mut self) {
CURRE... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a4f18b93b674a30771a4a0c023a65b099fa0920 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a4f18b93b674a30771a4a0c023a65b099fa0920/tokio/src/runtime/scheduler/multi_thread/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:8 | }
(EnterContext::Entered { allow_blocking }, false) => {
// We are on an executor, but _not_ on the thread pool. That is
// _only_ okay if we are in a thread pool runtime's block_on
// method:
if allow_blocking {
had_entere... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a4f18b93b674a30771a4a0c023a65b099fa0920 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a4f18b93b674a30771a4a0c023a65b099fa0920/tokio/src/runtime/scheduler/multi_thread/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:9 | // First, move the core back into the worker's shared core slot.
cx.worker.core.set(core);
// Next, clone the worker handle and send it to a new thread for
// processing.
//
// Once the blocking task is done executing, we will attempt to
// steal the core back.
l... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a4f18b93b674a30771a4a0c023a65b099fa0920 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a4f18b93b674a30771a4a0c023a65b099fa0920/tokio/src/runtime/scheduler/multi_thread/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:10 | let cx = Context {
worker,
core: RefCell::new(None),
};
let _enter = crate::runtime::enter(true);
CURRENT.set(&cx, || {
// This should always be an error. It only returns a `Result` to support
// using `?` to short circuit.
assert!(cx.run(core).is_err());
});
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a4f18b93b674a30771a4a0c023a65b099fa0920 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a4f18b93b674a30771a4a0c023a65b099fa0920/tokio/src/runtime/scheduler/multi_thread/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:11 | // Signal shutdown
self.worker.shared.shutdown(core);
Err(())
}
fn run_task(&self, task: Notified, mut core: Box<Core>) -> RunResult {
let task = self.worker.shared.owned.assert_owner(task);
// Make sure the worker is not in the **searching** state. This enables
// anot... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a4f18b93b674a30771a4a0c023a65b099fa0920 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a4f18b93b674a30771a4a0c023a65b099fa0920/tokio/src/runtime/scheduler/multi_thread/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:12 | *self.core.borrow_mut() = Some(core);
let task = self.worker.shared.owned.assert_owner(task);
task.run();
} else {
// Not enough budget left to run the LIFO task, push it to
// the back of the queue and return.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a4f18b93b674a30771a4a0c023a65b099fa0920 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a4f18b93b674a30771a4a0c023a65b099fa0920/tokio/src/runtime/scheduler/multi_thread/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:13 | f();
}
if core.transition_to_parked(&self.worker) {
while !core.is_shutdown {
core.metrics.about_to_park();
core = self.park_timeout(core, None);
core.metrics.returned_from_park();
// Run regularly scheduled maintenance
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a4f18b93b674a30771a4a0c023a65b099fa0920 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a4f18b93b674a30771a4a0c023a65b099fa0920/tokio/src/runtime/scheduler/multi_thread/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:14 | // Place `park` back in `core`
core.park = Some(park);
// If there are tasks available to steal, but this worker is not
// looking for tasks to steal, notify another worker.
if !core.is_searching && core.run_queue.is_stealable() {
self.worker.shared.notify_parked();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a4f18b93b674a30771a4a0c023a65b099fa0920 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a4f18b93b674a30771a4a0c023a65b099fa0920/tokio/src/runtime/scheduler/multi_thread/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:15 | return None;
}
let num = worker.shared.remotes.len();
// Start from a random worker
let start = self.rand.fastrand_n(num as u32) as usize;
for i in 0..num {
let i = (start + i) % num;
// Don't steal from ourself! We know we don't have work.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a4f18b93b674a30771a4a0c023a65b099fa0920 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a4f18b93b674a30771a4a0c023a65b099fa0920/tokio/src/runtime/scheduler/multi_thread/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:16 | self.is_searching = false;
worker.shared.transition_worker_from_searching();
}
/// Prepares the worker state for parking.
///
/// Returns true if the transition happened, false if there is work to do first.
fn transition_to_parked(&mut self, worker: &Worker) -> bool {
// Workers sho... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a4f18b93b674a30771a4a0c023a65b099fa0920 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a4f18b93b674a30771a4a0c023a65b099fa0920/tokio/src/runtime/scheduler/multi_thread/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:17 | // 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.shared.idle.unpark_worker_by_id(worker.index);
return true;
}
if worker.shared.idle.is_parked(worker.index) {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a4f18b93b674a30771a4a0c023a65b099fa0920 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a4f18b93b674a30771a4a0c023a65b099fa0920/tokio/src/runtime/scheduler/multi_thread/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:18 | // Drain the queue
while self.next_local_task().is_some() {}
park.shutdown();
}
}
impl Worker {
/// Returns a reference to the scheduler's injection queue.
fn inject(&self) -> &Inject<Arc<Shared>> {
&self.shared.inject
}
}
impl task::Schedule for Arc<Shared> {
fn release(&... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a4f18b93b674a30771a4a0c023a65b099fa0920 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a4f18b93b674a30771a4a0c023a65b099fa0920/tokio/src/runtime/scheduler/multi_thread/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:19 | T: Future + Send + 'static,
T::Output: Send + 'static,
{
let (handle, notified) = me.owned.bind(future, me.clone(), id);
if let Some(notified) = notified {
me.schedule(notified, false);
}
handle
}
pub(super) fn schedule(&self, task: Notified, is_yield: ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a4f18b93b674a30771a4a0c023a65b099fa0920 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a4f18b93b674a30771a4a0c023a65b099fa0920/tokio/src/runtime/scheduler/multi_thread/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:20 | core.run_queue
.push_back(task, &self.inject, &mut core.metrics);
true
} else {
// Push to the LIFO slot
let prev = core.lifo_slot.take();
let ret = prev.is_some();
if let Some(prev) = prev {
core.run_queue
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a4f18b93b674a30771a4a0c023a65b099fa0920 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a4f18b93b674a30771a4a0c023a65b099fa0920/tokio/src/runtime/scheduler/multi_thread/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:21 | remote.unpark.unpark();
}
}
fn notify_if_work_pending(&self) {
for remote in &self.remotes[..] {
if !remote.steal.is_empty() {
self.notify_parked();
return;
}
}
if !self.inject.is_empty() {
self.notify_parked()... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a4f18b93b674a30771a4a0c023a65b099fa0920 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a4f18b93b674a30771a4a0c023a65b099fa0920/tokio/src/runtime/scheduler/multi_thread/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:22 | core.shutdown();
}
// Drain the injection queue
//
// We already shut down every task, so we can simply drop the tasks.
while let Some(task) = self.inject.pop() {
drop(task);
}
}
fn ptr_eq(&self, other: &Shared) -> bool {
std::ptr::eq(self, o... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 3a4f18b93b674a30771a4a0c023a65b099fa0920 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3a4f18b93b674a30771a4a0c023a65b099fa0920/tokio/src/runtime/scheduler/multi_thread/worker.rs | 841 | 867 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:21 | remote.unpark.unpark();
}
}
fn notify_if_work_pending(&self) {
for remote in &self.remotes[..] {
if !remote.steal.is_empty() {
self.notify_parked();
return;
}
}
if !self.inject.is_empty() {
self.notify_parked()... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 99aa8d12b7ad2ef011a7a9f652f7455b3f175821 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/99aa8d12b7ad2ef011a7a9f652f7455b3f175821/tokio/src/runtime/scheduler/multi_thread/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker.rs:22 | core.shutdown();
}
// Drain the injection queue
//
// We already shut down every task, so we can simply drop the tasks.
while let Some(task) = self.inject.pop() {
drop(task);
}
}
fn ptr_eq(&self, other: &Shared) -> bool {
std::ptr::eq(self, o... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker.rs | MIT | 99aa8d12b7ad2ef011a7a9f652f7455b3f175821 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/99aa8d12b7ad2ef011a7a9f652f7455b3f175821/tokio/src/runtime/scheduler/multi_thread/worker.rs | 841 | 880 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread/worker/metrics.rs:1 | use super::Shared;
impl Shared {
pub(crate) fn injection_queue_depth(&self) -> usize {
self.inject.len()
}
}
cfg_unstable_metrics! {
impl Shared {
pub(crate) fn worker_local_queue_depth(&self, worker: usize) -> usize {
self.remotes[worker].steal.len()
}
}
} | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread/worker/metrics.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/runtime/scheduler/multi_thread/worker/metrics.rs | 1 | 15 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/counters.rs:1 | #[cfg(tokio_internal_mt_counters)]
mod imp {
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::Relaxed;
static NUM_MAINTENANCE: AtomicUsize = AtomicUsize::new(0);
static NUM_NOTIFY_LOCAL: AtomicUsize = AtomicUsize::new(0);
static NUM_NOTIFY_REMOTE: AtomicUsize = AtomicUsize::new(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/counters.rs | MIT | 4165601b1bbaa7c29cbfb319fe75a9adddf4085e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4165601b1bbaa7c29cbfb319fe75a9adddf4085e/tokio/src/runtime/scheduler/multi_thread_alt/counters.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/counters.rs:2 | let num_no_avail_core = NUM_NO_AVAIL_CORE.load(Relaxed);
let num_relay_search = NUM_RELAY_SEARCH.load(Relaxed);
let num_spin_stall = NUM_SPIN_STALL.load(Relaxed);
let num_no_local_work = NUM_NO_LOCAL_WORK.load(Relaxed);
println!("---");
println!("notifies (re... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/counters.rs | MIT | 4165601b1bbaa7c29cbfb319fe75a9adddf4085e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4165601b1bbaa7c29cbfb319fe75a9adddf4085e/tokio/src/runtime/scheduler/multi_thread_alt/counters.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/counters.rs:3 | NUM_UNPARKS_REMOTE.fetch_add(1, Relaxed);
}
pub(crate) fn inc_num_maintenance() {
NUM_MAINTENANCE.fetch_add(1, Relaxed);
}
pub(crate) fn inc_lifo_schedules() {
NUM_LIFO_SCHEDULES.fetch_add(1, Relaxed);
}
pub(crate) fn inc_lifo_capped() {
NUM_LIFO_CAPPED.fetch_add(1, Re... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/counters.rs | MIT | 4165601b1bbaa7c29cbfb319fe75a9adddf4085e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4165601b1bbaa7c29cbfb319fe75a9adddf4085e/tokio/src/runtime/scheduler/multi_thread_alt/counters.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/counters.rs:4 | NUM_GLOBAL_QUEUE_INTERVAL.fetch_add(1, Relaxed);
}
pub(crate) fn inc_notify_no_core() {
NUM_NO_AVAIL_CORE.fetch_add(1, Relaxed);
}
pub(crate) fn inc_num_relay_search() {
NUM_RELAY_SEARCH.fetch_add(1, Relaxed);
}
pub(crate) fn inc_num_spin_stall() {
NUM_SPIN_STALL.fetch... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/counters.rs | MIT | 4165601b1bbaa7c29cbfb319fe75a9adddf4085e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4165601b1bbaa7c29cbfb319fe75a9adddf4085e/tokio/src/runtime/scheduler/multi_thread_alt/counters.rs | 121 | 166 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/handle.rs:1 | use crate::future::Future;
use crate::loom::sync::Arc;
use crate::runtime::scheduler::multi_thread_alt::worker;
use crate::runtime::{
blocking, driver,
task::{self, JoinHandle},
TaskHooks, TaskMeta,
};
use crate::util::RngSeedGenerator;
use std::fmt;
cfg_unstable_metrics! {
mod metrics;
}
/// Handle ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/handle.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread_alt/handle.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/handle.rs:2 | {
Self::bind_new_task(me, future, id)
}
pub(crate) fn shutdown(&self) {
self.shared.close(self);
self.driver.unpark();
}
pub(super) fn bind_new_task<T>(me: &Arc<Self>, future: T, id: task::Id) -> JoinHandle<T::Output>
where
T: Future + Send + 'static,
T::Out... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/handle.rs | MIT | b37f0de28a17ced6a9e6738062770d6fea8c5364 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b37f0de28a17ced6a9e6738062770d6fea8c5364/tokio/src/runtime/scheduler/multi_thread_alt/handle.rs | 41 | 85 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/handle.rs:1 | use crate::future::Future;
use crate::loom::sync::Arc;
use crate::runtime::scheduler::multi_thread_alt::worker;
use crate::runtime::{
blocking, driver,
task::{self, JoinHandle},
};
use crate::util::RngSeedGenerator;
use std::fmt;
cfg_unstable_metrics! {
mod metrics;
}
/// Handle to the multi thread sched... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/handle.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/handle.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/handle.rs:2 | pub(crate) fn shutdown(&self) {
self.shared.close(self);
self.driver.unpark();
}
pub(super) fn bind_new_task<T>(me: &Arc<Self>, future: T, id: task::Id) -> JoinHandle<T::Output>
where
T: Future + Send + 'static,
T::Output: Send + 'static,
{
let (handle, notified)... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/handle.rs | MIT | 86658bd87dc470f8e36eb6b893cc403820cfb7ee | github | async-runtime | https://github.com/tokio-rs/tokio/blob/86658bd87dc470f8e36eb6b893cc403820cfb7ee/tokio/src/runtime/scheduler/multi_thread_alt/handle.rs | 41 | 75 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/handle.rs:1 | use crate::future::Future;
use crate::loom::sync::Arc;
use crate::runtime::scheduler::multi_thread_alt::worker;
use crate::runtime::{
blocking, driver,
task::{self, JoinHandle},
};
use crate::util::RngSeedGenerator;
use std::fmt;
cfg_metrics! {
mod metrics;
}
/// Handle to the multi thread scheduler
pub(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/handle.rs | MIT | dd23f08c3a35495b4b53defa81ec0ca2c75a5f7d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dd23f08c3a35495b4b53defa81ec0ca2c75a5f7d/tokio/src/runtime/scheduler/multi_thread_alt/handle.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/handle.rs:1 | use crate::future::Future;
use crate::loom::sync::Arc;
use crate::runtime::scheduler::multi_thread_alt::worker;
use crate::runtime::{
blocking, driver,
task::{self, JoinHandle},
};
use crate::util::RngSeedGenerator;
use std::fmt;
cfg_metrics! {
mod metrics;
}
/// Handle to the multi thread scheduler
pub(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/handle.rs | MIT | 4165601b1bbaa7c29cbfb319fe75a9adddf4085e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4165601b1bbaa7c29cbfb319fe75a9adddf4085e/tokio/src/runtime/scheduler/multi_thread_alt/handle.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/handle.rs:2 | pub(crate) fn shutdown(&self) {
self.shared.close();
self.driver.unpark();
}
pub(super) fn bind_new_task<T>(me: &Arc<Self>, future: T, id: task::Id) -> JoinHandle<T::Output>
where
T: Future + Send + 'static,
T::Output: Send + 'static,
{
let (handle, notified) = m... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/handle.rs | MIT | 4165601b1bbaa7c29cbfb319fe75a9adddf4085e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4165601b1bbaa7c29cbfb319fe75a9adddf4085e/tokio/src/runtime/scheduler/multi_thread_alt/handle.rs | 41 | 75 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/handle/metrics.rs:1 | use super::Handle;
use crate::runtime::{SchedulerMetrics, WorkerMetrics};
impl Handle {
pub(crate) fn num_workers(&self) -> usize {
self.shared.worker_metrics.len()
}
pub(crate) fn num_blocking_threads(&self) -> usize {
// workers are currently spawned using spawn_blocking
self.bl... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/handle/metrics.rs | MIT | 1be8a8e691f48accda58874bf3a9241cea54daf4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1be8a8e691f48accda58874bf3a9241cea54daf4/tokio/src/runtime/scheduler/multi_thread_alt/handle/metrics.rs | 1 | 50 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/handle/metrics.rs:1 | use super::Handle;
use crate::runtime::{SchedulerMetrics, WorkerMetrics};
impl Handle {
pub(crate) fn num_workers(&self) -> usize {
self.shared.worker_metrics.len()
}
pub(crate) fn num_blocking_threads(&self) -> usize {
// workers are currently spawned using spawn_blocking
self.bl... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/handle/metrics.rs | MIT | 68d0e3cb5fc0b5e4348e5eeab79e44fc91f0f2d4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/68d0e3cb5fc0b5e4348e5eeab79e44fc91f0f2d4/tokio/src/runtime/scheduler/multi_thread_alt/handle/metrics.rs | 1 | 50 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/handle/metrics.rs:1 | use super::Handle;
use crate::runtime::{SchedulerMetrics, WorkerMetrics};
impl Handle {
pub(crate) fn num_workers(&self) -> usize {
self.shared.worker_metrics.len()
}
pub(crate) fn num_blocking_threads(&self) -> usize {
// workers are currently spawned using spawn_blocking
self.bl... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/handle/metrics.rs | MIT | 9a75d6f7f70fd81f589a8209c548944bc3d05f84 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9a75d6f7f70fd81f589a8209c548944bc3d05f84/tokio/src/runtime/scheduler/multi_thread_alt/handle/metrics.rs | 1 | 50 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/handle/metrics.rs:1 | use super::Handle;
use crate::runtime::{SchedulerMetrics, WorkerMetrics};
impl Handle {
pub(crate) fn num_workers(&self) -> usize {
self.shared.worker_metrics.len()
}
pub(crate) fn num_blocking_threads(&self) -> usize {
// workers are currently spawned using spawn_blocking
self.bl... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/handle/metrics.rs | MIT | 341b5daa6e4592d285674de4eb116c928fc9f29c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/341b5daa6e4592d285674de4eb116c928fc9f29c/tokio/src/runtime/scheduler/multi_thread_alt/handle/metrics.rs | 1 | 48 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/handle/metrics.rs:1 | use super::Handle;
use crate::runtime::{SchedulerMetrics, WorkerMetrics};
impl Handle {
pub(crate) fn num_workers(&self) -> usize {
self.shared.worker_metrics.len()
}
pub(crate) fn num_blocking_threads(&self) -> usize {
self.blocking_spawner.num_threads()
}
pub(crate) fn num_idle... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/handle/metrics.rs | MIT | 4165601b1bbaa7c29cbfb319fe75a9adddf4085e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4165601b1bbaa7c29cbfb319fe75a9adddf4085e/tokio/src/runtime/scheduler/multi_thread_alt/handle/metrics.rs | 1 | 41 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/idle.rs:1 | //! Coordinates idling workers
#![allow(dead_code)]
use crate::loom::sync::atomic::{AtomicBool, AtomicUsize};
use crate::loom::sync::MutexGuard;
use crate::runtime::scheduler::multi_thread_alt::{worker, Core, Handle, Shared};
use std::sync::atomic::Ordering::{AcqRel, Acquire, Release};
pub(super) struct Idle {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/idle.rs | MIT | dd23f08c3a35495b4b53defa81ec0ca2c75a5f7d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dd23f08c3a35495b4b53defa81ec0ca2c75a5f7d/tokio/src/runtime/scheduler/multi_thread_alt/idle.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/idle.rs:2 | /// Cores available for workers
available_cores: Vec<Box<Core>>,
}
impl Idle {
pub(super) fn new(cores: Vec<Box<Core>>, num_workers: usize) -> (Idle, Synced) {
let idle = Idle {
num_searching: AtomicUsize::new(0),
num_idle: AtomicUsize::new(cores.len()),
idle_map: Id... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/idle.rs | MIT | dd23f08c3a35495b4b53defa81ec0ca2c75a5f7d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dd23f08c3a35495b4b53defa81ec0ca2c75a5f7d/tokio/src/runtime/scheduler/multi_thread_alt/idle.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/idle.rs:3 | /// Try to acquire an available core
pub(super) fn try_acquire_available_core(&self, synced: &mut Synced) -> Option<Box<Core>> {
let ret = synced.available_cores.pop();
if let Some(core) = &ret {
// Decrement the number of idle cores
let num_idle = self.num_idle.load(Acquire... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/idle.rs | MIT | dd23f08c3a35495b4b53defa81ec0ca2c75a5f7d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dd23f08c3a35495b4b53defa81ec0ca2c75a5f7d/tokio/src/runtime/scheduler/multi_thread_alt/idle.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/idle.rs:4 | return;
}
super::counters::inc_num_unparks_local();
// Acquire the lock
let synced = shared.synced.lock();
self.notify_synced(synced, shared);
}
/// Notifies a single worker
pub(super) fn notify_remote(&self, synced: MutexGuard<'_, worker::Synced>, shared: &Shared)... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/idle.rs | MIT | dd23f08c3a35495b4b53defa81ec0ca2c75a5f7d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dd23f08c3a35495b4b53defa81ec0ca2c75a5f7d/tokio/src/runtime/scheduler/multi_thread_alt/idle.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/scheduler/multi_thread_alt/idle.rs:5 | // Notify the worker
shared.condvars[worker].notify_one();
return;
} else {
synced.idle.sleepers.push(worker);
}
}
super::counters::inc_notify_no_core();
// Set the `needs_searching` flag, this happens *while* the lock is ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/scheduler/multi_thread_alt/idle.rs | MIT | dd23f08c3a35495b4b53defa81ec0ca2c75a5f7d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dd23f08c3a35495b4b53defa81ec0ca2c75a5f7d/tokio/src/runtime/scheduler/multi_thread_alt/idle.rs | 161 | 220 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.