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/thread_pool/worker.rs:18 | 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 injection queue.
fn inject(&self) -> &Inject<Arc<Shared>> {
&self.shared.injec... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | b023522a37a48d16de02e654b6c88ffe1eccb280 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b023522a37a48d16de02e654b6c88ffe1eccb280/tokio/src/runtime/thread_pool/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:19 | where
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: Notifi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | b023522a37a48d16de02e654b6c88ffe1eccb280 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b023522a37a48d16de02e654b6c88ffe1eccb280/tokio/src/runtime/thread_pool/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:20 | let should_notify = if is_yield || self.config.disable_lifo_slot {
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();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | b023522a37a48d16de02e654b6c88ffe1eccb280 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b023522a37a48d16de02e654b6c88ffe1eccb280/tokio/src/runtime/thread_pool/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:21 | for remote in &self.remotes[..] {
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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | b023522a37a48d16de02e654b6c88ffe1eccb280 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b023522a37a48d16de02e654b6c88ffe1eccb280/tokio/src/runtime/thread_pool/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:22 | for mut core in cores.drain(..) {
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: &... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | b023522a37a48d16de02e654b6c88ffe1eccb280 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b023522a37a48d16de02e654b6c88ffe1eccb280/tokio/src/runtime/thread_pool/worker.rs | 841 | 881 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:19 | where
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: Notifi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | df28ac092f0464d9c00eeb7f58e3b85dcb5bce52 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df28ac092f0464d9c00eeb7f58e3b85dcb5bce52/tokio/src/runtime/thread_pool/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:20 | let should_notify = if is_yield {
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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | df28ac092f0464d9c00eeb7f58e3b85dcb5bce52 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/df28ac092f0464d9c00eeb7f58e3b85dcb5bce52/tokio/src/runtime/thread_pool/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/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/thread_pool/worker.rs | MIT | 0b8a3c34a1a119a61801b4e7e287f91684d11941 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b8a3c34a1a119a61801b4e7e287f91684d11941/tokio/src/runtime/thread_pool/worker.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:3 | index: usize,
/// 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 s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0b8a3c34a1a119a61801b4e7e287f91684d11941 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b8a3c34a1a119a61801b4e7e287f91684d11941/tokio/src/runtime/thread_pool/worker.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:4 | /// How many ticks before pulling a task from the global/remote queue?
global_queue_interval: u32,
/// How many ticks before yielding to the driver for timer and I/O events?
event_interval: u32,
}
/// State shared across all workers
pub(super) struct Shared {
/// Handle to the I/O driver, timer, block... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0b8a3c34a1a119a61801b4e7e287f91684d11941 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b8a3c34a1a119a61801b4e7e287f91684d11941/tokio/src/runtime/thread_pool/worker.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:5 | pub(super) scheduler_metrics: SchedulerMetrics,
pub(super) worker_metrics: Box<[WorkerMetrics]>,
}
/// Used to communicate with a worker from other threads.
struct Remote {
/// Steals tasks from this worker.
steal: queue::Steal<Arc<Shared>>,
/// Unparks the associated worker thread
unpark: Unpark... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0b8a3c34a1a119a61801b4e7e287f91684d11941 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b8a3c34a1a119a61801b4e7e287f91684d11941/tokio/src/runtime/thread_pool/worker.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:6 | pub(super) fn create(
size: usize,
park: Parker,
handle_inner: HandleInner,
before_park: Option<Callback>,
after_unpark: Option<Callback>,
global_queue_interval: u32,
event_interval: u32,
) -> (Arc<Shared>, Launch) {
let mut cores = Vec::with_capacity(size);
let mut remotes = Vec::wi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0b8a3c34a1a119a61801b4e7e287f91684d11941 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b8a3c34a1a119a61801b4e7e287f91684d11941/tokio/src/runtime/thread_pool/worker.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:7 | inject: Inject::new(),
idle: Idle::new(size),
owned: OwnedTasks::new(),
shutdown_cores: Mutex::new(vec![]),
before_park,
after_unpark,
scheduler_metrics: SchedulerMetrics::new(),
worker_metrics: worker_metrics.into_boxed_slice(),
});
let mut launch = Laun... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0b8a3c34a1a119a61801b4e7e287f91684d11941 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b8a3c34a1a119a61801b4e7e287f91684d11941/tokio/src/runtime/thread_pool/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:8 | // runtime.
coop::set(self.0);
}
});
}
}
let mut had_entered = false;
CURRENT.with(|maybe_cx| {
match (crate::runtime::enter::context(), maybe_cx.is_some()) {
(EnterContext::Entered { .. }, true) => {
// We are on ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0b8a3c34a1a119a61801b4e7e287f91684d11941 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b8a3c34a1a119a61801b4e7e287f91684d11941/tokio/src/runtime/thread_pool/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:9 | let cx = maybe_cx.expect("no .is_some() == false cases above should lead here");
// Get the worker core. If none is set, then blocking is fine!
let core = match cx.core.borrow_mut().take() {
Some(core) => core,
None => return,
};
// The parker should be set here... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0b8a3c34a1a119a61801b4e7e287f91684d11941 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b8a3c34a1a119a61801b4e7e287f91684d11941/tokio/src/runtime/thread_pool/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:10 | for worker in self.0.drain(..) {
runtime::spawn_blocking(move || run(worker));
}
}
}
fn run(worker: Arc<Worker>) {
// Acquire a core. If this fails, then another thread is running this
// worker and there is nothing further to do.
let core = match worker.core.take() {
Some(c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0b8a3c34a1a119a61801b4e7e287f91684d11941 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b8a3c34a1a119a61801b4e7e287f91684d11941/tokio/src/runtime/thread_pool/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:11 | core = self.run_task(task, core)?;
continue;
}
// There is no more **local** work to process, try to steal work
// from other workers.
if let Some(task) = core.steal_work(&self.worker) {
core = self.run_task(task, core)?;
} els... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0b8a3c34a1a119a61801b4e7e287f91684d11941 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b8a3c34a1a119a61801b4e7e287f91684d11941/tokio/src/runtime/thread_pool/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:12 | // by another worker.
let mut core = match self.core.borrow_mut().take() {
Some(core) => core,
None => return Err(()),
};
// Check for a task in the LIFO slot
let task = match core.lifo_slot.take() {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0b8a3c34a1a119a61801b4e7e287f91684d11941 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b8a3c34a1a119a61801b4e7e287f91684d11941/tokio/src/runtime/thread_pool/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:13 | }
/// Parks the worker thread while waiting for tasks to execute.
///
/// This function checks if indeed there's no more work left to be done before parking.
/// Also important to notice that, before parking, the worker thread will try to take
/// ownership of the Driver (IO/Time) and dispatch any ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0b8a3c34a1a119a61801b4e7e287f91684d11941 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b8a3c34a1a119a61801b4e7e287f91684d11941/tokio/src/runtime/thread_pool/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:14 | // Take the parker out of core
let mut park = core.park.take().expect("park missing");
// Store `core` in context
*self.core.borrow_mut() = Some(core);
// Park thread
if let Some(timeout) = duration {
park.park_timeout(timeout).expect("park failed");
} else ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0b8a3c34a1a119a61801b4e7e287f91684d11941 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b8a3c34a1a119a61801b4e7e287f91684d11941/tokio/src/runtime/thread_pool/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:15 | self.next_local_task().or_else(|| worker.inject().pop())
}
}
fn next_local_task(&mut self) -> Option<Notified> {
self.lifo_slot.take().or_else(|| self.run_queue.pop())
}
/// Function responsible for stealing tasks from another worker
///
/// Note: Only if less than half the wor... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0b8a3c34a1a119a61801b4e7e287f91684d11941 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b8a3c34a1a119a61801b4e7e287f91684d11941/tokio/src/runtime/thread_pool/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:16 | worker.shared.inject.pop()
}
fn transition_to_searching(&mut self, worker: &Worker) -> bool {
if !self.is_searching {
self.is_searching = worker.shared.idle.transition_worker_to_searching();
}
self.is_searching
}
fn transition_from_searching(&mut self, worker: &Wor... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0b8a3c34a1a119a61801b4e7e287f91684d11941 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b8a3c34a1a119a61801b4e7e287f91684d11941/tokio/src/runtime/thread_pool/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:17 | if is_last_searcher {
worker.shared.notify_if_work_pending();
}
true
}
/// Returns `true` if the transition happened.
fn transition_from_parked(&mut self, worker: &Worker) -> bool {
// If a task is in the lifo slot, then we must unpark regardless of
// being not... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0b8a3c34a1a119a61801b4e7e287f91684d11941 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b8a3c34a1a119a61801b4e7e287f91684d11941/tokio/src/runtime/thread_pool/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:18 | /// 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) {
// Signal to all tasks to shut down.
worker.shared.owned.close_and_shutdown_all();
self.metric... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0b8a3c34a1a119a61801b4e7e287f91684d11941 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b8a3c34a1a119a61801b4e7e287f91684d11941/tokio/src/runtime/thread_pool/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:19 | (**self).schedule(task, true);
}
}
impl Shared {
pub(crate) fn as_handle_inner(&self) -> &HandleInner {
&self.handle_inner
}
pub(super) fn bind_new_task<T>(
me: &Arc<Self>,
future: T,
id: crate::runtime::task::Id,
) -> JoinHandle<T::Output>
where
T: Futu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0b8a3c34a1a119a61801b4e7e287f91684d11941 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b8a3c34a1a119a61801b4e7e287f91684d11941/tokio/src/runtime/thread_pool/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:20 | // Otherwise, use the inject queue.
self.inject.push(task);
self.scheduler_metrics.inc_remote_schedule_count();
self.notify_parked();
})
}
fn schedule_local(&self, core: &mut Core, task: Notified, is_yield: bool) {
core.metrics.inc_local_schedule_count();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0b8a3c34a1a119a61801b4e7e287f91684d11941 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b8a3c34a1a119a61801b4e7e287f91684d11941/tokio/src/runtime/thread_pool/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:21 | pub(super) fn close(&self) {
if self.inject.close() {
self.notify_all();
}
}
fn notify_parked(&self) {
if let Some(index) = self.idle.worker_to_notify() {
self.remotes[index].unpark.unpark();
}
}
fn notify_all(&self) {
for remote in &self... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0b8a3c34a1a119a61801b4e7e287f91684d11941 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b8a3c34a1a119a61801b4e7e287f91684d11941/tokio/src/runtime/thread_pool/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:22 | /// 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(&self, core: Box<Core>) {
let mut cores = self.shutdown_cores.lock();
cores.push(core... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0b8a3c34a1a119a61801b4e7e287f91684d11941 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b8a3c34a1a119a61801b4e7e287f91684d11941/tokio/src/runtime/thread_pool/worker.rs | 841 | 895 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:23 | }
}
}
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/thread_pool/worker.rs | MIT | 0b8a3c34a1a119a61801b4e7e287f91684d11941 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0b8a3c34a1a119a61801b4e7e287f91684d11941/tokio/src/runtime/thread_pool/worker.rs | 881 | 895 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/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/thread_pool/worker.rs | MIT | 1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1/tokio/src/runtime/thread_pool/worker.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:3 | index: usize,
/// 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: u8,
/// When a task is scheduled from a worker, it is stored in this slot. The
/// worker will check this sl... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1/tokio/src/runtime/thread_pool/worker.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/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/thread_pool/worker.rs | MIT | 1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1/tokio/src/runtime/thread_pool/worker.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:5 | struct Remote {
/// Steals tasks from this worker.
steal: queue::Steal<Arc<Shared>>,
/// 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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1/tokio/src/runtime/thread_pool/worker.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:6 | ) -> (Arc<Shared>, Launch) {
let mut cores = Vec::with_capacity(size);
let mut remotes = Vec::with_capacity(size);
let mut worker_metrics = Vec::with_capacity(size);
// Create the local queues
for _ in 0..size {
let (steal, run_queue) = queue::local();
let park = park.clone();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1/tokio/src/runtime/thread_pool/worker.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:7 | let mut launch = Launch(vec![]);
for (index, core) in cores.drain(..).enumerate() {
launch.0.push(Arc::new(Worker {
shared: shared.clone(),
index,
core: AtomicCell::new(Some(core)),
}));
}
(shared, launch)
}
pub(crate) fn block_in_place<F, R>(f: F) -> R... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1/tokio/src/runtime/thread_pool/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:8 | match (crate::runtime::enter::context(), maybe_cx.is_some()) {
(EnterContext::Entered { .. }, true) => {
// We are on a thread pool runtime thread, so we just need to
// set up blocking.
had_entered = true;
}
(EnterContext::Entered { al... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1/tokio/src/runtime/thread_pool/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:9 | assert!(core.park.is_some());
// In order to block, the core must be sent to another thread for
// execution.
//
// 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
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1/tokio/src/runtime/thread_pool/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:10 | }
fn run(worker: Arc<Worker>) {
// 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,
};
// Set the worker context.
let cx = Context {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1/tokio/src/runtime/thread_pool/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:11 | // There is no more **local** work to process, try to steal work
// from other workers.
if let Some(task) = core.steal_work(&self.worker) {
core = self.run_task(task, core)?;
} else {
// Wait for work
core = self.park(core);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1/tokio/src/runtime/thread_pool/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:12 | };
// Check for a task in the LIFO slot
let task = match core.lifo_slot.take() {
Some(task) => task,
None => return Ok(core),
};
if coop::has_budget_remaining() {
// Run the LIFO task, then loop... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1/tokio/src/runtime/thread_pool/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:13 | /// This function checks if indeed there's no more work left to be done before parking.
/// Also important to notice that, before parking, the worker thread will try to take
/// ownership of the Driver (IO/Time) and dispatch any events that might have fired.
/// Whenever a worker thread executes the Driver ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1/tokio/src/runtime/thread_pool/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:14 | *self.core.borrow_mut() = Some(core);
// Park thread
if let Some(timeout) = duration {
park.park_timeout(timeout).expect("park failed");
} else {
park.park().expect("park failed");
}
// Remove `core` from context
core = self.core.borrow_mut().tak... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1/tokio/src/runtime/thread_pool/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:15 | fn next_local_task(&mut self) -> Option<Notified> {
self.lifo_slot.take().or_else(|| self.run_queue.pop())
}
/// Function responsible for stealing tasks from another worker
///
/// Note: Only if less than half the workers are searching for tasks to steal
/// a new worker will actually try t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1/tokio/src/runtime/thread_pool/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:16 | if !self.is_searching {
self.is_searching = worker.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;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1/tokio/src/runtime/thread_pool/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:17 | true
}
/// Returns `true` if the transition happened.
fn transition_from_parked(&mut self, worker: &Worker) -> bool {
// If a task is in the lifo slot, then we must unpark regardless of
// being notified
if self.lifo_slot.is_some() {
// When a worker wakes, it should onl... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1/tokio/src/runtime/thread_pool/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:18 | // Signal to all tasks to shut down.
worker.shared.owned.close_and_shutdown_all();
self.metrics
.submit(&worker.shared.worker_metrics[worker.index]);
}
/// Shuts down the core.
fn shutdown(&mut self) {
// Take the core
let mut park = self.park.take().expect("par... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1/tokio/src/runtime/thread_pool/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:19 | impl Shared {
pub(crate) fn as_handle_inner(&self) -> &HandleInner {
&self.handle_inner
}
pub(super) fn bind_new_task<T>(
me: &Arc<Self>,
future: T,
id: crate::runtime::task::Id,
) -> JoinHandle<T::Output>
where
T: Future + Send + 'static,
T::Output: ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1/tokio/src/runtime/thread_pool/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:20 | })
}
fn schedule_local(&self, core: &mut Core, task: Notified, is_yield: bool) {
core.metrics.inc_local_schedule_count();
// Spawning from the worker thread. If scheduling a "yield" then the
// task must always be pushed to the back of the queue, enabling other
// tasks to be e... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1/tokio/src/runtime/thread_pool/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:21 | }
}
fn notify_parked(&self) {
if let Some(index) = self.idle.worker_to_notify() {
self.remotes[index].unpark.unpark();
}
}
fn notify_all(&self) {
for remote in &self.remotes[..] {
remote.unpark.unpark();
}
}
fn notify_if_work_pending(&se... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1/tokio/src/runtime/thread_pool/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:22 | fn shutdown(&self, core: Box<Core>) {
let mut cores = self.shutdown_cores.lock();
cores.push(core);
if cores.len() != self.remotes.len() {
return;
}
debug_assert!(self.owned.is_empty());
for mut core in cores.drain(..) {
core.shutdown();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1/tokio/src/runtime/thread_pool/worker.rs | 841 | 891 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:23 | 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/thread_pool/worker.rs | MIT | 1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1d3f12304e29dbb8fe3ef4089d01d5acb9edaae1/tokio/src/runtime/thread_pool/worker.rs | 881 | 891 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:18 | // Signal to all tasks to shut down.
worker.shared.owned.close_and_shutdown_all();
self.metrics
.submit(&worker.shared.worker_metrics[worker.index]);
}
/// Shuts down the core.
fn shutdown(&mut self) {
// Take the core
let mut park = self.park.take().expect("par... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1472af5bd4e441ed68648660603cffdae55fbdbd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1472af5bd4e441ed68648660603cffdae55fbdbd/tokio/src/runtime/thread_pool/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:19 | impl Shared {
pub(crate) fn as_handle_inner(&self) -> &HandleInner {
&self.handle_inner
}
pub(super) fn bind_new_task<T>(me: &Arc<Self>, future: T) -> JoinHandle<T::Output>
where
T: Future + Send + 'static,
T::Output: Send + 'static,
{
let (handle, notified) = me.own... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1472af5bd4e441ed68648660603cffdae55fbdbd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1472af5bd4e441ed68648660603cffdae55fbdbd/tokio/src/runtime/thread_pool/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:20 | core.metrics.inc_local_schedule_count();
// Spawning from the worker thread. If scheduling a "yield" then the
// task must always be pushed to the back of the queue, enabling other
// tasks to be executed. If **not** a yield, then there is more
// flexibility and the task may go to the ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1472af5bd4e441ed68648660603cffdae55fbdbd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1472af5bd4e441ed68648660603cffdae55fbdbd/tokio/src/runtime/thread_pool/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:21 | if let Some(index) = self.idle.worker_to_notify() {
self.remotes[index].unpark.unpark();
}
}
fn notify_all(&self) {
for remote in &self.remotes[..] {
remote.unpark.unpark();
}
}
fn notify_if_work_pending(&self) {
for remote in &self.remotes[..] {... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1472af5bd4e441ed68648660603cffdae55fbdbd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1472af5bd4e441ed68648660603cffdae55fbdbd/tokio/src/runtime/thread_pool/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:22 | if cores.len() != self.remotes.len() {
return;
}
debug_assert!(self.owned.is_empty());
for mut core in cores.drain(..) {
core.shutdown();
}
// Drain the injection queue
//
// We already shut down every task, so we can simply drop the tas... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 1472af5bd4e441ed68648660603cffdae55fbdbd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1472af5bd4e441ed68648660603cffdae55fbdbd/tokio/src/runtime/thread_pool/worker.rs | 841 | 887 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:15 | fn next_local_task(&mut self) -> Option<Notified> {
self.lifo_slot.take().or_else(|| self.run_queue.pop())
}
/// Function responsible for stealing tasks from another worker
///
/// Note: Only if less than half the workers are searching for tasks to steal
/// a new worker will actually try t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 911a0efa87e36f0dffb13e3d52340d5c08415db1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/911a0efa87e36f0dffb13e3d52340d5c08415db1/tokio/src/runtime/thread_pool/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:16 | if !self.is_searching {
self.is_searching = worker.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;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 911a0efa87e36f0dffb13e3d52340d5c08415db1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/911a0efa87e36f0dffb13e3d52340d5c08415db1/tokio/src/runtime/thread_pool/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/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/thread_pool/worker.rs | MIT | 5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6/tokio/src/runtime/thread_pool/worker.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:3 | /// Index holding this worker's remote state
index: usize,
/// 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: u8,
/// When a task is scheduled from a worker, it is stored in... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6/tokio/src/runtime/thread_pool/worker.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/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** current... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6/tokio/src/runtime/thread_pool/worker.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:5 | steal: queue::Steal<Arc<Shared>>,
/// 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>>);
/// R... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6/tokio/src/runtime/thread_pool/worker.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:6 | let mut worker_metrics = Vec::with_capacity(size);
// Create the local queues
for _ in 0..size {
let (steal, run_queue) = queue::local();
let park = park.clone();
let unpark = park.unpark();
cores.push(Box::new(Core {
tick: 0,
lifo_slot: None,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6/tokio/src/runtime/thread_pool/worker.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6/tokio/src/runtime/thread_pool/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:10 | // worker and there is nothing further to do.
let core = match worker.core.take() {
Some(core) => core,
None => return,
};
// Set the worker context.
let cx = Context {
worker,
core: RefCell::new(None),
};
let _enter = crate::runtime::enter(true);
CURRENT.s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6/tokio/src/runtime/thread_pool/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:11 | } else {
// Wait for work
core = self.park(core);
}
}
core.pre_shutdown(&self.worker);
// Signal shutdown
self.worker.shared.shutdown(core);
Err(())
}
fn run_task(&self, task: Notified, mut core: Box<Core>) -> RunResult {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6/tokio/src/runtime/thread_pool/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:12 | Some(task) => task,
None => return Ok(core),
};
if coop::has_budget_remaining() {
// Run the LIFO task, then loop
core.metrics.incr_poll_count();
*self.core.borrow_mut() = Some(core);
let... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6/tokio/src/runtime/thread_pool/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:13 | /// in its own local queue until the queue saturates (ntasks > LOCAL_QUEUE_CAPACITY).
/// When the local queue is saturated, the overflow tasks are added to the injection queue
/// from where other workers can pick them up.
/// Also, we rely on the workstealing algorithm to spread the tasks amongst workers
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6/tokio/src/runtime/thread_pool/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:14 | park.park_timeout(timeout).expect("park failed");
} else {
park.park().expect("park failed");
}
// Remove `core` from context
core = self.core.borrow_mut().take().expect("core missing");
// Place `park` back in `core`
core.park = Some(park);
// If t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6/tokio/src/runtime/thread_pool/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:15 | /// 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 will be trying to steal at the same time.
fn steal_work(&mut sel... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6/tokio/src/runtime/thread_pool/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:16 | self.is_searching
}
fn transition_from_searching(&mut self, worker: &Worker) {
if !self.is_searching {
return;
}
self.is_searching = false;
worker.shared.transition_worker_from_searching();
}
/// Prepares the worker state for parking.
///
/// Return... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6/tokio/src/runtime/thread_pool/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/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 transition to ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6/tokio/src/runtime/thread_pool/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:18 | .submit(&worker.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() {}
park.shutdown();
}
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6/tokio/src/runtime/thread_pool/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:19 | T::Output: Send + 'static,
{
let (handle, notified) = me.owned.bind(future, me.clone());
if let Some(notified) = notified {
me.schedule(notified, false);
}
handle
}
pub(super) fn schedule(&self, task: Notified, is_yield: bool) {
CURRENT.with(|maybe_cx| ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6/tokio/src/runtime/thread_pool/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:20 | .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
.push_back(prev, &self.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6/tokio/src/runtime/thread_pool/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:21 | }
}
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();
}
}
fn transi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6/tokio/src/runtime/thread_pool/worker.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:22 | }
// 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, other)
}
}
cfg_metric... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5b947ca2c78ac96f61ef4d4d17d9a1fc16e446c6/tokio/src/runtime/thread_pool/worker.rs | 841 | 866 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:3 | /// Index holding this worker's remote state
index: usize,
/// 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: u8,
/// When a task is scheduled from a worker, it is stored in... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7/tokio/src/runtime/thread_pool/worker.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/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]>,
/// Submits work to the scheduler while **not** currently on a worker thread.
inject: Inje... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7/tokio/src/runtime/thread_pool/worker.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/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/thread_pool/worker.rs | MIT | fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7/tokio/src/runtime/thread_pool/worker.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/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/thread_pool/worker.rs | MIT | fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7/tokio/src/runtime/thread_pool/worker.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:7 | 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) {
CURRENT.with(|maybe_cx| ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7/tokio/src/runtime/thread_pool/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/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_entered = true;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7/tokio/src/runtime/thread_pool/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:9 | 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.
let worker = cx.worker.clone();
runtime::spawn_blocking(move || ru... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7/tokio/src/runtime/thread_pool/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:10 | Some(core) => core,
None => return,
};
// 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
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7/tokio/src/runtime/thread_pool/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:11 | core = self.park(core);
}
}
core.pre_shutdown(&self.worker);
// 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... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7/tokio/src/runtime/thread_pool/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:12 | };
if coop::has_budget_remaining() {
// Run the LIFO task, then loop
core.metrics.incr_poll_count();
*self.core.borrow_mut() = Some(core);
let task = self.worker.shared.owned.assert_owner(task);
task.run... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7/tokio/src/runtime/thread_pool/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:13 | core = self.park_timeout(core, None);
core.metrics.returned_from_park();
// Run regularly scheduled maintenance
core.maintenance(&self.worker);
if core.transition_from_parked(&self.worker) {
break;
}
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7/tokio/src/runtime/thread_pool/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:14 | if !core.is_searching && core.run_queue.is_stealable() {
self.worker.shared.notify_parked();
}
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.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7/tokio/src/runtime/thread_pool/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:15 | 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)
{
return Some(task);
}
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7/tokio/src/runtime/thread_pool/worker.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:16 | return false;
}
// When the final worker transitions **out** of searching to parked, it
// must check all the queues one last time in case work materialized
// between the last work scan and transitioning out of searching.
let is_last_searcher = worker
.shared
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7/tokio/src/runtime/thread_pool/worker.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:17 | 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]);
if !self.is_shutdown {
// Check if the scheduler has... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7/tokio/src/runtime/thread_pool/worker.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:18 | &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, task: Notified) {
(**self).schedule(task,... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7/tokio/src/runtime/thread_pool/worker.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:19 | self.schedule_local(core, task, is_yield);
return;
}
}
}
// Otherwise, use the inject queue.
self.inject.push(task);
self.scheduler_metrics.inc_remote_schedule_count();
self.notify_parked();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7/tokio/src/runtime/thread_pool/worker.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:20 | // 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();
}
}
pub(super) fn close(&self) {
if self.inject.close() {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7/tokio/src/runtime/thread_pool/worker.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:21 | // 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 back into its handle.
///
/// If all workers have rea... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fb9a01b3628bdd78efd5561f54e1af4b6b2fa4f7/tokio/src/runtime/thread_pool/worker.rs | 801 | 848 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/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/thread_pool/worker.rs | MIT | 24f4ee31f0266a97547a81f510726da9c1bb9ec9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24f4ee31f0266a97547a81f510726da9c1bb9ec9/tokio/src/runtime/thread_pool/worker.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/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/thread_pool/worker.rs | MIT | 4eed411519783ef6f58cbf74f886f91142b5cfa6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4eed411519783ef6f58cbf74f886f91142b5cfa6/tokio/src/runtime/thread_pool/worker.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:3 | /// Index holding this worker's remote state
index: usize,
/// 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: u8,
/// When a task is scheduled from a worker, it is stored in... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 4eed411519783ef6f58cbf74f886f91142b5cfa6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4eed411519783ef6f58cbf74f886f91142b5cfa6/tokio/src/runtime/thread_pool/worker.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:4 | rand: FastRand,
}
/// 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]>,
/// Submits work to the scheduler while **not** currently on a worker thread.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 4eed411519783ef6f58cbf74f886f91142b5cfa6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4eed411519783ef6f58cbf74f886f91142b5cfa6/tokio/src/runtime/thread_pool/worker.rs | 121 | 180 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.