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:3 | // TODO: Move into slices
pub(super) fn create_set(pool_size: usize, parker: Parker) -> (Arc<slice::Set>, Vec<Worker>) {
// Create the parks...
let parkers: Vec<_> = (0..pool_size).map(|_| parker.clone()).collect();
let mut slices = Arc::new(slice::Set::new(&parkers));
// Establish the circular link b... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 55b5e1b6adcc3f85a35d16444e496b203648c99d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/55b5e1b6adcc3f85a35d16444e496b203648c99d/tokio/src/runtime/thread_pool/worker.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:4 | }
}
pub(super) fn run(self) {
// First, acquire a lock on the worker.
let guard = match self.acquire_lock() {
Some(guard) => guard,
None => return,
};
// Track the current worker
current::set(&self.slices, self.index, || {
// Enter a ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 55b5e1b6adcc3f85a35d16444e496b203648c99d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/55b5e1b6adcc3f85a35d16444e496b203648c99d/tokio/src/runtime/thread_pool/worker.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:5 | // Ensure that we reset ob before allow_blocking is dropped.
drop(_reset);
});
});
if self.gone.get() {
// Synchronize with the pool for load(Acquire) in is_closed to get
// up-to-date value.
self.slices.wait_for_unlocked();
i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 55b5e1b6adcc3f85a35d16444e496b203648c99d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/55b5e1b6adcc3f85a35d16444e496b203648c99d/tokio/src/runtime/thread_pool/worker.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:6 | _p: PhantomData,
})
} else {
None
}
}
/// Enters an in-place blocking section
fn block_in_place(&self) {
// If our Worker has already been given away, then blocking is fine!
if self.gone.get() {
return;
}
// If this method... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 55b5e1b6adcc3f85a35d16444e496b203648c99d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/55b5e1b6adcc3f85a35d16444e496b203648c99d/tokio/src/runtime/thread_pool/worker.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:7 | // that async code can continue running in that context. Luckily, since
// `Arc<slice::Set>` has a fallback for when
// current::get() is None, we can just let the task
// run until it yields, and then put it back into
// the pool.
let worker = Worker {
inner: self.i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 55b5e1b6adcc3f85a35d16444e496b203648c99d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/55b5e1b6adcc3f85a35d16444e496b203648c99d/tokio/src/runtime/thread_pool/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:8 | me.park();
}
}
me.shutdown();
Ok(())
}
fn is_running(&self) -> bool {
self.owned().is_running.get()
}
/// Returns `true` if the worker needs to park
fn process_available_work(self) -> Result<Self, WorkerGone> {
let mut me = self;
loop {... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 55b5e1b6adcc3f85a35d16444e496b203648c99d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/55b5e1b6adcc3f85a35d16444e496b203648c99d/tokio/src/runtime/thread_pool/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:9 | // Try to steal tasks from other workers
if let Some(task) = me.steal_work() {
me = me.run_task(task)?;
} else {
// No work to steal, perform some routine work
me.drain_tasks_pending_drop();
return Ok(me);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 55b5e1b6adcc3f85a35d16444e496b203648c99d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/55b5e1b6adcc3f85a35d16444e496b203648c99d/tokio/src/runtime/thread_pool/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:10 | let start = self.owned().rand.fastrand_n(num_slices as u32);
self.owned()
.work_queue
.steal(start as usize)
// Fallback on checking the local queue, which will also check the
// injector.
.or_else(|| self.owned().work_queue.pop_global_first())
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 55b5e1b6adcc3f85a35d16444e496b203648c99d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/55b5e1b6adcc3f85a35d16444e496b203648c99d/tokio/src/runtime/thread_pool/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:11 | /// Returns `true` if the worker must check for any work.
fn transition_to_parked(&mut self) -> bool {
let idx = self.index();
let is_searching = self.is_searching();
let ret = self
.slices()
.idle()
.transition_worker_to_parked(idx, is_searching);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 55b5e1b6adcc3f85a35d16444e496b203648c99d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/55b5e1b6adcc3f85a35d16444e496b203648c99d/tokio/src/runtime/thread_pool/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:12 | }
}
/// Runs the task. During the task execution, it is possible for worker to
/// transition to a new thread. In this case, the caller loses the guard to
/// access the generation and must stop processing.
fn run_task(mut self, task: Task<Shared>) -> Result<Self, WorkerGone> {
if self.is_s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 55b5e1b6adcc3f85a35d16444e496b203648c99d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/55b5e1b6adcc3f85a35d16444e496b203648c99d/tokio/src/runtime/thread_pool/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:13 | fn final_work_sweep(&mut self) {
if !self.owned().work_queue.is_empty() {
self.slices().notify_work();
}
}
fn park(&mut self) {
if self.transition_to_parked() {
// We are the final searching worker, check if any work arrived
// before parking
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 55b5e1b6adcc3f85a35d16444e496b203648c99d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/55b5e1b6adcc3f85a35d16444e496b203648c99d/tokio/src/runtime/thread_pool/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:14 | if self.owned().did_submit_task.get() {
self.slices().notify_work();
self.owned().did_submit_task.set(false)
}
}
fn drain_tasks_pending_drop(&mut self) {
for task in self.shared().pending_drop.drain() {
unsafe {
let owned = &mut *self.slices()... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 55b5e1b6adcc3f85a35d16444e496b203648c99d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/55b5e1b6adcc3f85a35d16444e496b203648c99d/tokio/src/runtime/thread_pool/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:15 | // Since this is a shutdown process, excessive notification is
// not a huge deal.
self.worker.slices.notify_all();
notify = false;
}
// Try draining more tasks
self.drain_tasks_pending_drop();
if self.owned().owned_tasks.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 55b5e1b6adcc3f85a35d16444e496b203648c99d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/55b5e1b6adcc3f85a35d16444e496b203648c99d/tokio/src/runtime/thread_pool/worker.rs | 561 | 617 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:16 | fn shared(&self) -> &Shared {
&self.slices().shared()[self.index()]
}
fn owned(&self) -> &Owned {
let index = self.index();
// safety: we own the slot
unsafe { &*self.slices().owned()[index].get() }
}
fn park_mut(&mut self) -> &mut Parker {
// Safety: `&mut self... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 55b5e1b6adcc3f85a35d16444e496b203648c99d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/55b5e1b6adcc3f85a35d16444e496b203648c99d/tokio/src/runtime/thread_pool/worker.rs | 601 | 617 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:5 | // Ensure that we reset ob before allow_blocking is dropped.
drop(_reset);
});
});
if self.gone.get() {
// Synchronize with the pool for load(Acquire) in is_closed to get
// up-to-date value.
self.slices.wait_for_unlocked();
i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/runtime/thread_pool/worker.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:6 | _p: PhantomData,
})
} else {
None
}
}
/// Enters an in-place blocking section
fn block_in_place(&self) {
// If our Worker has already been given away, then blocking is fine!
if self.gone.get() {
return;
}
// make sure no s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/runtime/thread_pool/worker.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:7 | // - Spawn the reconstructed `Worker` on another blocking thread
// - Clear any state indicating what worker we are on, since at this
// point we are effectively no longer "on" that worker.
// - Allow the caller of `blocking` to continue.
//
// Once the caller completes the... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/runtime/thread_pool/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:8 | fn is_running(&self) -> bool {
self.owned().is_running.get()
}
/// Returns `true` if the worker needs to park
fn process_available_work(self) -> Result<Self, WorkerGone> {
let mut me = self;
loop {
// Local queue loop
loop {
let task = match ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/runtime/thread_pool/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:9 | }
} else {
return Ok(me);
}
// Start checking the local queue again
}
}
/// Finds local work
fn find_local_work(&mut self) -> Option<Task<Shared>> {
let tick = self.tick_fetch_inc();
if tick % GLOBAL_POLL_INTERVAL == 0 {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/runtime/thread_pool/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:10 | .or_else(|| self.owned().work_queue.pop_global_first())
}
/// Runs maintenance work such as free pending tasks and check the pool's
/// state.
fn maintenance(&mut self) {
// Free any completed tasks
self.drain_tasks_pending_drop();
// Update the pool state cache
let clo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/runtime/thread_pool/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:11 | .idle()
.transition_worker_to_parked(idx, is_searching);
// The worker is no longer searching. Setting this is the local cache
// only.
self.owned().is_searching.set(false);
// When tasks are submitted locally (from the parker), defer any
// notifications in hopes t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/runtime/thread_pool/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:12 | if self.is_searching() {
self.transition_from_searching();
}
let gone = &self.worker.gone;
let executor = self.shared();
let task = task.run(&mut || {
if gone.get() {
None
} else {
Some(executor.into())
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/runtime/thread_pool/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:13 | fn park(&mut self) {
if self.transition_to_parked() {
// We are the final searching worker, check if any work arrived
// before parking
self.final_work_sweep();
}
// The state has been transitioned to parked, we can now wait by
// calling the parker. ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/runtime/thread_pool/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:14 | for task in self.shared().pending_drop.drain() {
unsafe {
let owned = &mut *self.slices().owned()[self.index()].get();
owned.release_task(&task);
}
drop(task);
}
}
/// Shutdowns the worker.
///
/// Once the shutdown flag has be... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/runtime/thread_pool/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:15 | self.drain_tasks_pending_drop();
if self.owned().owned_tasks.is_empty() {
break;
}
// Wait until task that this worker owns are released.
//
// `transition_to_parked` is not called as we are not working
// anymore. When a task is ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/runtime/thread_pool/worker.rs | 561 | 610 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:16 | // safety: we own the slot
unsafe { &*self.slices().owned()[index].get() }
}
fn park_mut(&mut self) -> &mut Parker {
// Safety: `&mut self` on `GenerationGuard` implies it is safe to
// perform the action.
unsafe { self.worker.inner.park.with_mut(|ptr| &mut *ptr) }
}
} | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/runtime/thread_pool/worker.rs | 601 | 610 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:5 | // Ensure that we reset ob before allow_blocking is dropped.
drop(_reset);
});
});
if self.gone.get() {
// Synchronize with the pool for load(Acquire) in is_closed to get
// up-to-date value.
self.slices.wait_for_unlocked();
i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5bbf9762681ae75c6489558e15f894d0466516a3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5bbf9762681ae75c6489558e15f894d0466516a3/tokio/src/runtime/thread_pool/worker.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:6 | _p: PhantomData,
})
} else {
None
}
}
/// Enter an in-place blocking section
fn block_in_place(&self) {
// If our Worker has already been given away, then blocking is fine!
if self.gone.get() {
return;
}
// make sure no su... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5bbf9762681ae75c6489558e15f894d0466516a3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5bbf9762681ae75c6489558e15f894d0466516a3/tokio/src/runtime/thread_pool/worker.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:8 | fn is_running(&self) -> bool {
self.owned().is_running.get()
}
/// Returns `true` if the worker needs to park
fn process_available_work(self) -> Result<Self, WorkerGone> {
let mut me = self;
loop {
// Local queue loop
loop {
let task = match ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5bbf9762681ae75c6489558e15f894d0466516a3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5bbf9762681ae75c6489558e15f894d0466516a3/tokio/src/runtime/thread_pool/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:9 | }
} else {
return Ok(me);
}
// Start checking the local queue again
}
}
/// Find local work
fn find_local_work(&mut self) -> Option<Task<Shared>> {
let tick = self.tick_fetch_inc();
if tick % GLOBAL_POLL_INTERVAL == 0 {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5bbf9762681ae75c6489558e15f894d0466516a3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5bbf9762681ae75c6489558e15f894d0466516a3/tokio/src/runtime/thread_pool/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:13 | fn park(&mut self) {
if self.transition_to_parked() {
// We are the final searching worker, check if any work arrived
// before parking
self.final_work_sweep();
}
// The state has been transitioned to parked, we can now wait by
// calling the parker. ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5bbf9762681ae75c6489558e15f894d0466516a3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5bbf9762681ae75c6489558e15f894d0466516a3/tokio/src/runtime/thread_pool/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:14 | for task in self.shared().pending_drop.drain() {
unsafe {
let owned = &mut *self.slices().owned()[self.index()].get();
owned.release_task(&task);
}
drop(task);
}
}
/// Shutdown the worker.
///
/// Once the shutdown flag has bee... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5bbf9762681ae75c6489558e15f894d0466516a3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5bbf9762681ae75c6489558e15f894d0466516a3/tokio/src/runtime/thread_pool/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:15 | self.drain_tasks_pending_drop();
if self.owned().owned_tasks.is_empty() {
break;
}
// Wait until task that this worker owns are released.
//
// `transition_to_parked` is not called as we are not working
// anymore. When a task is ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 5bbf9762681ae75c6489558e15f894d0466516a3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5bbf9762681ae75c6489558e15f894d0466516a3/tokio/src/runtime/thread_pool/worker.rs | 561 | 610 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:1 | use crate::loom::cell::CausalCell;
use crate::loom::sync::Arc;
use crate::park::Park;
use crate::runtime;
use crate::runtime::park::Parker;
use crate::runtime::thread_pool::{current, slice, Owned, Shared};
use crate::task::Task;
use std::cell::Cell;
use std::marker::PhantomData;
use std::sync::atomic::Ordering::Relaxe... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 6406328176cdecf15cad69b327597a4d4d0b8e20 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6406328176cdecf15cad69b327597a4d4d0b8e20/tokio/src/runtime/thread_pool/worker.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:2 | pub(crate) struct Worker {
/// Parks the thread. Requires the calling worker to have obtained unique
/// access via the generation synchronization action.
inner: Arc<Inner>,
/// Scheduler slices
slices: Arc<slice::Set>,
/// Slice assigned to this worker
index: usize,
/// Worker genera... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 6406328176cdecf15cad69b327597a4d4d0b8e20 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6406328176cdecf15cad69b327597a4d4d0b8e20/tokio/src/runtime/thread_pool/worker.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:3 | pub(super) fn create_set(pool_size: usize, parker: Parker) -> (Arc<slice::Set>, Vec<Worker>) {
// Create the parks...
let parkers: Vec<_> = (0..pool_size).map(|_| parker.clone()).collect();
let mut slices = Arc::new(slice::Set::new(&parkers));
// Establish the circular link between the individual work... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 6406328176cdecf15cad69b327597a4d4d0b8e20 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6406328176cdecf15cad69b327597a4d4d0b8e20/tokio/src/runtime/thread_pool/worker.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:4 | pub(super) fn run(self) {
// First, acquire a lock on the worker.
let guard = match self.acquire_lock() {
Some(guard) => guard,
None => return,
};
// Track the current worker
current::set(&self.slices, self.index, || {
// Enter a runtime conte... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 6406328176cdecf15cad69b327597a4d4d0b8e20 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6406328176cdecf15cad69b327597a4d4d0b8e20/tokio/src/runtime/thread_pool/worker.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:5 | drop(_reset);
});
});
if self.gone.get() {
// Synchronize with the pool for load(Acquire) in is_closed to get
// up-to-date value.
self.slices.wait_for_unlocked();
if self.slices.is_closed() {
// If the pool is shutting down, ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 6406328176cdecf15cad69b327597a4d4d0b8e20 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6406328176cdecf15cad69b327597a4d4d0b8e20/tokio/src/runtime/thread_pool/worker.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:6 | } else {
None
}
}
/// Enter an in-place blocking section
fn block_in_place(&self) {
// If our Worker has already been given away, then blocking is fine!
if self.gone.get() {
return;
}
// make sure no subsequent code thinks that it is on a wor... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 6406328176cdecf15cad69b327597a4d4d0b8e20 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6406328176cdecf15cad69b327597a4d4d0b8e20/tokio/src/runtime/thread_pool/worker.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:7 | // point we are effectively no longer "on" that worker.
// - Allow the caller of `blocking` to continue.
//
// Once the caller completes the blocking operations, we need to ensure
// that async code can continue running in that context. Luckily, since
// `Arc<slice::Set>` has... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 6406328176cdecf15cad69b327597a4d4d0b8e20 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6406328176cdecf15cad69b327597a4d4d0b8e20/tokio/src/runtime/thread_pool/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:8 | self.owned().is_running.get()
}
/// Returns `true` if the worker needs to park
fn process_available_work(self) -> Result<Self, WorkerGone> {
let mut me = self;
loop {
// Local queue loop
loop {
let task = match me.find_local_work() {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 6406328176cdecf15cad69b327597a4d4d0b8e20 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6406328176cdecf15cad69b327597a4d4d0b8e20/tokio/src/runtime/thread_pool/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:9 | return Ok(me);
}
// Start checking the local queue again
}
}
/// Find local work
fn find_local_work(&mut self) -> Option<Task<Shared>> {
let tick = self.tick_fetch_inc();
if tick % GLOBAL_POLL_INTERVAL == 0 {
// Sleep light...
self.p... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 6406328176cdecf15cad69b327597a4d4d0b8e20 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6406328176cdecf15cad69b327597a4d4d0b8e20/tokio/src/runtime/thread_pool/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:10 | /// Runs maintenance work such as free pending tasks and check the pool's
/// state.
fn maintenance(&mut self) {
// Free any completed tasks
self.drain_tasks_pending_drop();
// Update the pool state cache
let closed = self.owned().work_queue.is_closed();
self.owned().is_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 6406328176cdecf15cad69b327597a4d4d0b8e20 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6406328176cdecf15cad69b327597a4d4d0b8e20/tokio/src/runtime/thread_pool/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:11 | // The worker is no longer searching. Setting this is the local cache
// only.
self.owned().is_searching.set(false);
// When tasks are submitted locally (from the parker), defer any
// notifications in hopes that the curent worker will grab those tasks.
self.owned().defer_notifi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 6406328176cdecf15cad69b327597a4d4d0b8e20 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6406328176cdecf15cad69b327597a4d4d0b8e20/tokio/src/runtime/thread_pool/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:12 | }
let gone = &self.worker.gone;
let executor = self.shared();
let task = task.run(&mut || {
if gone.get() {
None
} else {
Some(executor.into())
}
});
if gone.get() {
// The Worker disappeared from ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 6406328176cdecf15cad69b327597a4d4d0b8e20 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6406328176cdecf15cad69b327597a4d4d0b8e20/tokio/src/runtime/thread_pool/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:13 | // We are the final searching worker, check if any work arrived
// before parking
self.final_work_sweep();
}
// The state has been transitioned to parked, we can now wait by
// calling the parker. This is done in a loop as spurious wakeups are
// permitted.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 6406328176cdecf15cad69b327597a4d4d0b8e20 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6406328176cdecf15cad69b327597a4d4d0b8e20/tokio/src/runtime/thread_pool/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:14 | let owned = &mut *self.slices().owned()[self.index()].get();
owned.release_task(&task);
}
drop(task);
}
}
/// Shutdown the worker.
///
/// Once the shutdown flag has been observed, it is guaranteed that no
/// further tasks may be pushed into the glob... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 6406328176cdecf15cad69b327597a4d4d0b8e20 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6406328176cdecf15cad69b327597a4d4d0b8e20/tokio/src/runtime/thread_pool/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:15 | if self.owned().owned_tasks.is_empty() {
break;
}
// Wait until task that this worker owns are released.
//
// `transition_to_parked` is not called as we are not working
// anymore. When a task is released, the owning worker is unparked
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 6406328176cdecf15cad69b327597a4d4d0b8e20 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6406328176cdecf15cad69b327597a4d4d0b8e20/tokio/src/runtime/thread_pool/worker.rs | 561 | 608 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:13 | // We are the final searching worker, check if any work arrived
// before parking
self.final_work_sweep();
}
// The state has been transitioned to parked, we can now wait by
// calling the parker. This is done in a loop as spurious wakeups are
// permitted.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 45da5f3510a61599c89dc458ecc859f13a81e255 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/45da5f3510a61599c89dc458ecc859f13a81e255/tokio/src/runtime/thread_pool/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:14 | let owned = &mut *self.slices().owned()[self.index()].get();
owned.release_task(&task);
}
drop(task);
}
}
/// Shutdown the worker.
///
/// Once the shutdown flag has been observed, it is guaranteed that no
/// further tasks may be pushed into the glob... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 45da5f3510a61599c89dc458ecc859f13a81e255 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/45da5f3510a61599c89dc458ecc859f13a81e255/tokio/src/runtime/thread_pool/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:15 | fn tick_fetch_inc(&mut self) -> u16 {
let tick = self.owned().tick.get();
self.owned().tick.set(tick.wrapping_add(1));
tick
}
fn is_searching(&self) -> bool {
self.owned().is_searching.get()
}
fn index(&self) -> usize {
self.worker.index
}
fn slices(&se... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 45da5f3510a61599c89dc458ecc859f13a81e255 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/45da5f3510a61599c89dc458ecc859f13a81e255/tokio/src/runtime/thread_pool/worker.rs | 561 | 594 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:1 | use crate::loom::cell::CausalCell;
use crate::loom::sync::Arc;
use crate::park::Park;
use crate::runtime::park::Parker;
use crate::runtime::thread_pool::{current, slice, Owned, Shared};
use crate::runtime::{self, blocking};
use crate::task::Task;
use std::cell::Cell;
use std::marker::PhantomData;
use std::sync::atomic... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 67bf9c36f347031ca05872d102a7f9abc8b465f0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/67bf9c36f347031ca05872d102a7f9abc8b465f0/tokio/src/runtime/thread_pool/worker.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:3 | pub(super) fn create_set(pool_size: usize, parker: Parker) -> (Arc<slice::Set>, Vec<Worker>) {
// Create the parks...
let parkers: Vec<_> = (0..pool_size).map(|_| parker.clone()).collect();
let mut slices = Arc::new(slice::Set::new(&parkers));
// Establish the circular link between the individual work... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 67bf9c36f347031ca05872d102a7f9abc8b465f0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/67bf9c36f347031ca05872d102a7f9abc8b465f0/tokio/src/runtime/thread_pool/worker.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:4 | pub(super) fn run(self, blocking_pool: blocking::Spawner) {
// First, acquire a lock on the worker.
let guard = match self.acquire_lock() {
Some(guard) => guard,
None => return,
};
// Track the current worker
current::set(&self.slices, self.index, || {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 67bf9c36f347031ca05872d102a7f9abc8b465f0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/67bf9c36f347031ca05872d102a7f9abc8b465f0/tokio/src/runtime/thread_pool/worker.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:5 | // Ensure that we reset ob before allow_blocking is dropped.
drop(_reset);
});
})
});
if self.gone.get() {
// Synchronize with the pool for load(Acquire) in is_closed to get
// up-to-date value.
self.slices.wait_for_unl... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 67bf9c36f347031ca05872d102a7f9abc8b465f0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/67bf9c36f347031ca05872d102a7f9abc8b465f0/tokio/src/runtime/thread_pool/worker.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:6 | _p: PhantomData,
})
} else {
None
}
}
/// Enter an in-place blocking section
fn block_in_place(&self, blocking_pool: &blocking::Spawner) {
// If our Worker has already been given away, then blocking is fine!
if self.gone.get() {
return;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 67bf9c36f347031ca05872d102a7f9abc8b465f0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/67bf9c36f347031ca05872d102a7f9abc8b465f0/tokio/src/runtime/thread_pool/worker.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:7 | // - Spawn the reconstructed `Worker` on another blocking thread
// - Clear any state indicating what worker we are on, since at this
// point we are effectively no longer "on" that worker.
// - Allow the caller of `blocking` to continue.
//
// Once the caller completes the... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 67bf9c36f347031ca05872d102a7f9abc8b465f0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/67bf9c36f347031ca05872d102a7f9abc8b465f0/tokio/src/runtime/thread_pool/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:8 | }
fn is_running(&self) -> bool {
self.owned().is_running.get()
}
/// Returns `true` if the worker needs to park
fn process_available_work(self) -> Result<Self, WorkerGone> {
let mut me = self;
loop {
// Local queue loop
loop {
let task =... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 67bf9c36f347031ca05872d102a7f9abc8b465f0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/67bf9c36f347031ca05872d102a7f9abc8b465f0/tokio/src/runtime/thread_pool/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:9 | return Ok(me);
}
} else {
return Ok(me);
}
// Start checking the local queue again
}
}
/// Find local work
fn find_local_work(&mut self) -> Option<Task<Shared>> {
let tick = self.tick_fetch_inc();
if tick % GLOBAL... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 67bf9c36f347031ca05872d102a7f9abc8b465f0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/67bf9c36f347031ca05872d102a7f9abc8b465f0/tokio/src/runtime/thread_pool/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:10 | // injector.
.or_else(|| self.owned().work_queue.pop_global_first())
}
/// Runs maintenance work such as free pending tasks and check the pool's
/// state.
fn maintenance(&mut self) {
// Free any completed tasks
self.drain_tasks_pending_drop();
// Update the pool st... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 67bf9c36f347031ca05872d102a7f9abc8b465f0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/67bf9c36f347031ca05872d102a7f9abc8b465f0/tokio/src/runtime/thread_pool/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:11 | .slices()
.idle()
.transition_worker_to_parked(idx, is_searching);
// The worker is no longer searching. Setting this is the local cache
// only.
self.owned().is_searching.set(false);
// When tasks are submitted locally (from the parker), defer any
// no... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 67bf9c36f347031ca05872d102a7f9abc8b465f0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/67bf9c36f347031ca05872d102a7f9abc8b465f0/tokio/src/runtime/thread_pool/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:12 | fn run_task(mut self, task: Task<Shared>) -> Result<Self, WorkerGone> {
if self.is_searching() {
self.transition_from_searching();
}
let gone = &self.worker.gone;
let executor = self.shared();
let task = task.run(&mut || {
if gone.get() {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 67bf9c36f347031ca05872d102a7f9abc8b465f0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/67bf9c36f347031ca05872d102a7f9abc8b465f0/tokio/src/runtime/thread_pool/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:13 | fn park(&mut self) {
if self.transition_to_parked() {
// We are the final searching worker, check if any work arrived
// before parking
self.final_work_sweep();
}
// The state has been transitioned to parked, we can now wait by
// calling the parker. ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 67bf9c36f347031ca05872d102a7f9abc8b465f0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/67bf9c36f347031ca05872d102a7f9abc8b465f0/tokio/src/runtime/thread_pool/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:14 | fn drain_tasks_pending_drop(&mut self) {
for task in self.shared().pending_drop.drain() {
unsafe {
let owned = &mut *self.slices().owned()[self.index()].get();
owned.release_task(&task);
}
drop(task);
}
}
/// Shutdown the worke... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 67bf9c36f347031ca05872d102a7f9abc8b465f0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/67bf9c36f347031ca05872d102a7f9abc8b465f0/tokio/src/runtime/thread_pool/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:15 | }
/// Increment the tick, returning the value from before the increment.
fn tick_fetch_inc(&mut self) -> u16 {
let tick = self.owned().tick.get();
self.owned().tick.set(tick.wrapping_add(1));
tick
}
fn is_searching(&self) -> bool {
self.owned().is_searching.get()
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 67bf9c36f347031ca05872d102a7f9abc8b465f0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/67bf9c36f347031ca05872d102a7f9abc8b465f0/tokio/src/runtime/thread_pool/worker.rs | 561 | 597 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:1 | use crate::loom::cell::CausalCell;
use crate::loom::sync::Arc;
use crate::park::Park;
use crate::runtime::park::Parker;
use crate::runtime::thread_pool::{current, slice, Owned, Shared, Spawner};
use crate::runtime::{self, blocking};
use crate::task::Task;
use std::cell::Cell;
use std::marker::PhantomData;
use std::syn... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8656b7b8eb6f3635ec40694eb71f14fb84211e05 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8656b7b8eb6f3635ec40694eb71f14fb84211e05/tokio/src/runtime/thread_pool/worker.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:3 | pub(super) fn create_set(pool_size: usize, parker: Parker) -> (Arc<slice::Set>, Vec<Worker>) {
// Create the parks...
let parkers: Vec<_> = (0..pool_size).map(|_| parker.clone()).collect();
let mut slices = Arc::new(slice::Set::new(&parkers));
// Establish the circular link between the individual work... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8656b7b8eb6f3635ec40694eb71f14fb84211e05 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8656b7b8eb6f3635ec40694eb71f14fb84211e05/tokio/src/runtime/thread_pool/worker.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:4 | pub(super) fn run(self, blocking_pool: blocking::Spawner) {
// First, acquire a lock on the worker.
let guard = match self.acquire_lock() {
Some(guard) => guard,
None => return,
};
let spawner = Spawner::new(self.slices.clone());
// Track the current wor... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8656b7b8eb6f3635ec40694eb71f14fb84211e05 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8656b7b8eb6f3635ec40694eb71f14fb84211e05/tokio/src/runtime/thread_pool/worker.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:5 | let _ = guard.run();
// Ensure that we reset ob before allow_blocking is dropped.
drop(_reset);
});
})
})
});
if self.gone.get() {
// Synchronize with the pool for load(Acquire) in is_closed to ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8656b7b8eb6f3635ec40694eb71f14fb84211e05 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8656b7b8eb6f3635ec40694eb71f14fb84211e05/tokio/src/runtime/thread_pool/worker.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:6 | if prev == self.generation {
Some(GenerationGuard {
worker: self,
_p: PhantomData,
})
} else {
None
}
}
/// Enter an in-place blocking section
fn block_in_place(&self, blocking_pool: &blocking::Spawner) {
// If our ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8656b7b8eb6f3635ec40694eb71f14fb84211e05 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8656b7b8eb6f3635ec40694eb71f14fb84211e05/tokio/src/runtime/thread_pool/worker.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:7 | //
// Here's what we'll have to do:
//
// - Reconstruct our `Worker` struct
// - Spawn the reconstructed `Worker` on another blocking thread
// - Clear any state indicating what worker we are on, since at this
// point we are effectively no longer "on" that worker.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8656b7b8eb6f3635ec40694eb71f14fb84211e05 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8656b7b8eb6f3635ec40694eb71f14fb84211e05/tokio/src/runtime/thread_pool/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:8 | }
me.shutdown();
Ok(())
}
fn is_running(&self) -> bool {
self.owned().is_running.get()
}
/// Returns `true` if the worker needs to park
fn process_available_work(self) -> Result<Self, WorkerGone> {
let mut me = self;
loop {
// Local queue loop
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8656b7b8eb6f3635ec40694eb71f14fb84211e05 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8656b7b8eb6f3635ec40694eb71f14fb84211e05/tokio/src/runtime/thread_pool/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:9 | me = me.run_task(task)?;
} else {
// No work to steal, perform some routine work
me.drain_tasks_pending_drop();
return Ok(me);
}
} else {
return Ok(me);
}
// Start checking th... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8656b7b8eb6f3635ec40694eb71f14fb84211e05 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8656b7b8eb6f3635ec40694eb71f14fb84211e05/tokio/src/runtime/thread_pool/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:10 | self.owned()
.work_queue
.steal(start as usize)
// Fallback on checking the local queue, which will also check the
// injector.
.or_else(|| self.owned().work_queue.pop_global_first())
}
/// Runs maintenance work such as free pending tasks and check th... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8656b7b8eb6f3635ec40694eb71f14fb84211e05 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8656b7b8eb6f3635ec40694eb71f14fb84211e05/tokio/src/runtime/thread_pool/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:11 | fn transition_to_parked(&mut self) -> bool {
let idx = self.index();
let is_searching = self.is_searching();
let ret = self
.slices()
.idle()
.transition_worker_to_parked(idx, is_searching);
// The worker is no longer searching. Setting this is the lo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8656b7b8eb6f3635ec40694eb71f14fb84211e05 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8656b7b8eb6f3635ec40694eb71f14fb84211e05/tokio/src/runtime/thread_pool/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:12 | /// Runs the task. During the task execution, it is possible for worker to
/// transition to a new thread. In this case, the caller loses the guard to
/// access the generation and must stop processing.
fn run_task(mut self, task: Task<Shared>) -> Result<Self, WorkerGone> {
if self.is_searching() {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8656b7b8eb6f3635ec40694eb71f14fb84211e05 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8656b7b8eb6f3635ec40694eb71f14fb84211e05/tokio/src/runtime/thread_pool/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:13 | if !self.owned().work_queue.is_empty() {
self.slices().notify_work();
}
}
fn park(&mut self) {
if self.transition_to_parked() {
// We are the final searching worker, check if any work arrived
// before parking
self.final_work_sweep();
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8656b7b8eb6f3635ec40694eb71f14fb84211e05 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8656b7b8eb6f3635ec40694eb71f14fb84211e05/tokio/src/runtime/thread_pool/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:14 | self.owned().did_submit_task.set(false)
}
}
fn drain_tasks_pending_drop(&mut self) {
for task in self.shared().pending_drop.drain() {
unsafe {
let owned = &mut *self.slices().owned()[self.index()].get();
owned.release_task(&task);
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8656b7b8eb6f3635ec40694eb71f14fb84211e05 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8656b7b8eb6f3635ec40694eb71f14fb84211e05/tokio/src/runtime/thread_pool/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:15 | // Try draining more tasks
self.drain_tasks_pending_drop();
}
}
/// Increment the tick, returning the value from before the increment.
fn tick_fetch_inc(&mut self) -> u16 {
let tick = self.owned().tick.get();
self.owned().tick.set(tick.wrapping_add(1));
tick
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8656b7b8eb6f3635ec40694eb71f14fb84211e05 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8656b7b8eb6f3635ec40694eb71f14fb84211e05/tokio/src/runtime/thread_pool/worker.rs | 561 | 601 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:1 | use crate::loom::cell::CausalCell;
use crate::loom::sync::Arc;
use crate::park::Park;
use crate::runtime::{self, blocking};
use crate::runtime::park::Parker;
use crate::runtime::thread_pool::{current, slice, Owned, Shared, Spawner};
use crate::task::Task;
use std::cell::Cell;
use std::marker::PhantomData;
use std::syn... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/thread_pool/worker.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:2 | pub(crate) struct Worker {
/// Parks the thread. Requires the calling worker to have obtained unique
/// access via the generation synchronization action.
inner: Arc<Inner>,
/// Scheduler slices
slices: Arc<slice::Set>,
/// Slice assigned to this worker
index: usize,
/// Worker genera... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/thread_pool/worker.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:3 | pub(super) fn create_set(
pool_size: usize,
parker: Parker,
) -> (Arc<slice::Set>, Vec<Worker>) {
// Create the parks...
let parkers: Vec<_> = (0..pool_size).map(|_| parker.clone()).collect();
let mut slices = Arc::new(slice::Set::new(&parkers));
// Establish the circular link between the indi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/thread_pool/worker.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:4 | index: usize,
park: Parker,
) -> Self {
Worker {
inner: Arc::new(Inner {
park: CausalCell::new(park),
}),
slices,
index,
generation: 0,
gone: Cell::new(false),
}
}
pub(super) fn run(self, blockin... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/thread_pool/worker.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:5 | let _reset = Reset(ob);
let allow_blocking: &dyn Fn() = &|| self.block_in_place(&blocking_pool);
ob.set(Some(unsafe {
// NOTE: We cannot use a safe cast to raw pointer here, since we are
// _also_ erasing the lifet... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/thread_pool/worker.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:6 | /// Acquire the lock
fn acquire_lock(&self) -> Option<GenerationGuard<'_>> {
// Safety: Only getting `&self` access to access atomic field
let owned = unsafe { &*self.slices.owned()[self.index].get() };
// The lock is only to establish mutual exclusion. Other synchronization
// hand... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/thread_pool/worker.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:7 | // block our reactor from making progress. Since we are _in the middle_
// of running a task, this isn't trivial, as the Worker is "active".
// We do have the luxury of knowing that we are on the worker thread,
// so we can assert exclusive access to any Worker-specific state.
//
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/thread_pool/worker.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:8 | }
}
impl GenerationGuard<'_> {
fn run(self) -> Result<(), WorkerGone> {
let mut me = self;
while me.is_running() {
me = me.process_available_work()?;
if me.is_running() {
me.park();
}
}
me.shutdown();
Ok(())
}
f... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/thread_pool/worker.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:9 | }
};
me = me.run_task(task)?;
}
// No more **local** work to process, try transitioning to searching
// in order to attempt to steal work from other workers.
//
// On `false`, the worker has entered the parked state
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/thread_pool/worker.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:10 | }
// Check the global queue
self.owned().work_queue.pop_global_first()
} else {
self.owned().work_queue.pop_local_first()
}
}
fn steal_work(&mut self) -> Option<Task<Shared>> {
let num_slices = self.worker.slices.len();
let start = self.owned... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/thread_pool/worker.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:11 | }
fn transition_from_searching(&mut self) {
self.owned().is_searching.set(false);
if self.slices().idle().transition_worker_from_searching() {
// We are the final searching worker. Because work was found, we
// need to notify another worker.
self.slices().notify... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/thread_pool/worker.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:12 | true
} else {
let ret = !self.slices().idle().is_parked(self.index());
if ret {
self.owned().is_searching.set(true);
self.owned().defer_notification.set(false);
}
ret
}
}
/// Runs the task. During the task executi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/thread_pool/worker.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:13 | Err(WorkerGone)
} else {
if let Some(task) = task {
self.owned().submit_local_yield(task);
self.slices().notify_work();
}
Ok(self)
}
}
fn final_work_sweep(&mut self) {
if !self.owned().work_queue.is_empty() {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/thread_pool/worker.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:14 | fn park_light(&mut self) {
// When tasks are submitted locally (from the parker), defer any
// notifications in hopes that the curent worker will grab those tasks.
self.owned().defer_notification.set(true);
self.park_mut()
.park_timeout(Duration::from_millis(0))
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/thread_pool/worker.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:15 | // Notify all workers in case they have pending tasks to drop
//
// Not super efficient, but we are also shutting down.
self.worker.slices.notify_all();
// The worker can only shutdown once there are no further owned tasks.
while !self.owned().owned_tasks.is_empty() {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/thread_pool/worker.rs | 561 | 614 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:16 | }
fn owned(&self) -> &Owned {
let index = self.index();
// safety: we own the slot
unsafe { &*self.slices().owned()[index].get() }
}
fn park_mut(&mut self) -> &mut Parker {
// Safety: `&mut self` on `GenerationGuard` implies it is safe to
// perform the action.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/thread_pool/worker.rs | 601 | 614 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:1 | use crate::blocking;
use crate::loom::cell::CausalCell;
use crate::loom::sync::Arc;
use crate::runtime::park::{Park, Unpark};
use crate::runtime::thread_pool::{current, shutdown, slice, Callback, Owned, Shared, Spawner};
use crate::task::Task;
use std::cell::Cell;
use std::marker::PhantomData;
use std::sync::atomic::O... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0d38936b35779b604770120da2e98560bbb6241f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d38936b35779b604770120da2e98560bbb6241f/tokio/src/runtime/thread_pool/worker.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:2 | /// Parks the thread. Requires the calling worker to have obtained unique
/// access via the generation synchronization action.
inner: Arc<Inner<P>>,
/// Scheduler slices
slices: Arc<slice::Set<P::Unpark>>,
/// Slice assigned to this worker
index: usize,
/// Handle to the blocking pool
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0d38936b35779b604770120da2e98560bbb6241f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d38936b35779b604770120da2e98560bbb6241f/tokio/src/runtime/thread_pool/worker.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:3 | worker: &'a Worker<P>,
/// Prevent `Sync` access
_p: PhantomData<Cell<()>>,
}
struct WorkerGone;
// TODO: Move into slices
pub(super) fn create_set<F, P>(
pool_size: usize,
mk_park: F,
blocking_pool: blocking::Spawner,
around_worker: Callback,
shutdown_tx: shutdown::Sender,
) -> (Arc<slic... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0d38936b35779b604770120da2e98560bbb6241f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d38936b35779b604770120da2e98560bbb6241f/tokio/src/runtime/thread_pool/worker.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:4 | shutdown_tx.clone(),
)
})
.collect();
(slices, workers)
}
/// After how many ticks is the global queue polled. This helps to ensure
/// fairness.
///
/// The number is fairly arbitrary. I believe this value was copied from golang.
const GLOBAL_POLL_INTERVAL: u16 = 61;
impl<P> Worker<P... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0d38936b35779b604770120da2e98560bbb6241f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d38936b35779b604770120da2e98560bbb6241f/tokio/src/runtime/thread_pool/worker.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/thread_pool/worker.rs:5 | }
pub(super) fn run(self)
where
P: Park<Unpark = Box<dyn Unpark>>,
{
(self.around_worker)(self.index, &mut || {
// First, acquire a lock on the worker.
let guard = match self.acquire_lock() {
Some(guard) => guard,
None => return,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/thread_pool/worker.rs | MIT | 0d38936b35779b604770120da2e98560bbb6241f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d38936b35779b604770120da2e98560bbb6241f/tokio/src/runtime/thread_pool/worker.rs | 161 | 220 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.