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/park.rs:2 | /// Shared across multiple Parker handles
struct Shared {
/// Shared driver. Only one thread at a time can use this
driver: TryLock<time::Driver>,
/// Unpark handle
handle: <time::Driver as Park>::Unpark,
}
impl Parker {
pub(crate) fn new(driver: time::Driver) -> Parker {
let handle = driv... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/park.rs | MIT | c0953d41a5cd2e0514b551771668139679332328 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c0953d41a5cd2e0514b551771668139679332328/tokio/src/runtime/park.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/park.rs:3 | impl Park for Parker {
type Unpark = Unparker;
type Error = ();
fn unpark(&self) -> Unparker {
Unparker { inner: self.inner.clone() }
}
fn park(&mut self) -> Result<(), Self::Error> {
self.inner.park();
Ok(())
}
fn park_timeout(&mut self, duration: Duration) -> Res... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/park.rs | MIT | c0953d41a5cd2e0514b551771668139679332328 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c0953d41a5cd2e0514b551771668139679332328/tokio/src/runtime/park.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/park.rs:4 | return;
}
thread::yield_now();
}
if let Some(mut driver) = self.shared.driver.try_lock() {
self.park_driver(&mut driver);
} else {
self.park_condvar();
}
}
fn park_condvar(&self) {
// Otherwise we need to coordinate going... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/park.rs | MIT | c0953d41a5cd2e0514b551771668139679332328 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c0953d41a5cd2e0514b551771668139679332328/tokio/src/runtime/park.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/park.rs:5 | }
// spurious wakeup, go back to sleep
}
}
fn park_driver(&self, driver: &mut time::Driver) {
match self.state.compare_exchange(EMPTY, PARKED_DRIVER, SeqCst, SeqCst) {
Ok(_) => {}
Err(NOTIFIED) => {
// We must read here, even though we know i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/park.rs | MIT | c0953d41a5cd2e0514b551771668139679332328 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c0953d41a5cd2e0514b551771668139679332328/tokio/src/runtime/park.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/park.rs:6 | match self.state.swap(NOTIFIED, SeqCst) {
EMPTY => {}, // no one was waiting
NOTIFIED => {}, // already unparked
PARKED_CONDVAR => self.unpark_condvar(),
PARKED_DRIVER => self.unpark_driver(),
actual => panic!("inconsistent state in unpark; actual = {}", actua... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/park.rs | MIT | c0953d41a5cd2e0514b551771668139679332328 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c0953d41a5cd2e0514b551771668139679332328/tokio/src/runtime/park.rs | 201 | 230 |
tokio-rs/tokio:tokio/src/runtime/park.rs:1 | //! Parks the runtime.
//!
//! A combination of the various resource driver park handles.
use crate::loom::sync::{Arc, Mutex, Condvar};
use crate::loom::sync::atomic::AtomicUsize;
use crate::park::{Park, Unpark};
use crate::runtime::time;
use crate::util::TryLock;
use std::sync::atomic::Ordering::SeqCst;
use std::tim... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/park.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/park.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/park.rs:2 | /// Shared across multiple Parker handles
struct Shared {
/// Shared driver. Only one thread at a time can use this
driver: TryLock<time::Driver>,
/// Unpark handle
handle: <time::Driver as Park>::Unpark,
}
impl Parker {
pub(crate) fn new(driver: time::Driver) -> Parker {
let handle = driv... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/park.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/park.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/park.rs:3 | impl Park for Parker {
type Unpark = Unparker;
type Error = ();
fn unpark(&self) -> Unparker {
Unparker { inner: self.inner.clone() }
}
fn park(&mut self) -> Result<(), Self::Error> {
self.inner.park();
Ok(())
}
fn park_timeout(&mut self, duration: Duration) -> Res... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/park.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/park.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/park.rs:4 | if let Some(mut driver) = self.shared.driver.try_lock() {
self.park_driver(&mut driver);
} else {
self.park_condvar();
}
}
fn park_condvar(&self) {
// Otherwise we need to coordinate going to sleep
let mut m = self.mutex.lock().unwrap();
match se... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/park.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/park.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/park.rs:5 | fn park_driver(&self, driver: &mut time::Driver) {
match self.state.compare_exchange(EMPTY, PARKED_DRIVER, SeqCst, SeqCst) {
Ok(_) => {}
Err(NOTIFIED) => {
// We must read here, even though we know it will be `NOTIFIED`.
// This is because `unpark` may hav... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/park.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/park.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/park.rs:6 | actual => panic!("inconsistent state in unpark; actual = {}", actual),
}
}
fn unpark_condvar(&self) {
// There is a period between when the parked thread sets `state` to
// `PARKED` (or last checked `state` in the case of a spurious wake
// up) and when it actually waits on `cva... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/park.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/runtime/park.rs | 201 | 225 |
tokio-rs/tokio:tokio/src/runtime/park/thread.rs:1 | use crate::loom::sync::atomic::AtomicUsize;
use crate::loom::sync::{Arc, Condvar, Mutex};
use crate::runtime::park::{Park, Unpark};
use std::marker::PhantomData;
use std::rc::Rc;
use std::sync::atomic::Ordering;
use std::time::Duration;
/// Blocks the current thread using a condition variable.
///
/// Implements the ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/park/thread.rs | MIT | 0d38936b35779b604770120da2e98560bbb6241f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d38936b35779b604770120da2e98560bbb6241f/tokio/src/runtime/park/thread.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/park/thread.rs:2 | #[derive(Clone, Debug)]
pub(crate) struct UnparkThread {
inner: Arc<Inner>,
}
#[derive(Debug)]
struct Inner {
state: AtomicUsize,
mutex: Mutex<()>,
condvar: Condvar,
}
const IDLE: usize = 0;
const NOTIFY: usize = 1;
const SLEEP: usize = 2;
thread_local! {
static CURRENT_PARKER: ParkThread = ParkT... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/park/thread.rs | MIT | 0d38936b35779b604770120da2e98560bbb6241f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d38936b35779b604770120da2e98560bbb6241f/tokio/src/runtime/park/thread.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/park/thread.rs:3 | UnparkThread { inner }
}
fn park(&mut self) -> Result<(), Self::Error> {
self.inner.park(None)
}
fn park_timeout(&mut self, duration: Duration) -> Result<(), Self::Error> {
self.inner.park(Some(duration))
}
}
// ==== impl Inner ====
impl Inner {
/// Park the current thread fo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/park/thread.rs | MIT | 0d38936b35779b604770120da2e98560bbb6241f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d38936b35779b604770120da2e98560bbb6241f/tokio/src/runtime/park/thread.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/park/thread.rs:4 | m = match timeout {
Some(timeout) => self.condvar.wait_timeout(m, timeout).unwrap().0,
None => self.condvar.wait(m).unwrap(),
};
// Transition back to idle. If the state has transitioned to `NOTIFY`,
// this will consume that notification
self.state.store(IDLE, O... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/park/thread.rs | MIT | 0d38936b35779b604770120da2e98560bbb6241f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d38936b35779b604770120da2e98560bbb6241f/tokio/src/runtime/park/thread.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/park/thread.rs:5 | }
}
// ===== impl ParkThread =====
impl CachedParkThread {
/// Create a new `ParkThread` handle for the current thread.
///
/// This type cannot be moved to other threads, so it should be created on
/// the thread that the caller intends to park.
#[cfg(feature = "rt-threaded")]
pub(crate) fn n... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/park/thread.rs | MIT | 0d38936b35779b604770120da2e98560bbb6241f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d38936b35779b604770120da2e98560bbb6241f/tokio/src/runtime/park/thread.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/park/thread.rs:6 | self.with_current(|park_thread| park_thread.inner.park(Some(duration)))?;
Ok(())
}
}
impl Default for ParkThread {
fn default() -> Self {
Self::new()
}
}
// ===== impl UnparkThread =====
impl Unpark for UnparkThread {
fn unpark(&self) {
self.inner.unpark();
}
}
#[cfg(feat... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/park/thread.rs | MIT | 0d38936b35779b604770120da2e98560bbb6241f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d38936b35779b604770120da2e98560bbb6241f/tokio/src/runtime/park/thread.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/park/thread.rs:7 | }
unsafe fn from_raw(ptr: *const ()) -> Arc<Inner> {
Arc::from_raw(ptr as *const Inner)
}
}
unsafe fn unparker_to_raw_waker(unparker: Arc<Inner>) -> RawWaker {
RawWaker::new(
Inner::into_raw(unparker),
&RawWakerVTable::new(clone, wake, wake_by_ref, d... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/park/thread.rs | MIT | 0d38936b35779b604770120da2e98560bbb6241f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0d38936b35779b604770120da2e98560bbb6241f/tokio/src/runtime/park/thread.rs | 241 | 280 |
tokio-rs/tokio:tokio/src/runtime/park/thread.rs:4 | m = match timeout {
Some(timeout) => self.condvar.wait_timeout(m, timeout).unwrap().0,
None => self.condvar.wait(m).unwrap(),
};
// Transition back to idle. If the state has transitioned to `NOTIFY`,
// this will consume that notification
self.state.store(IDLE, O... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/park/thread.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/runtime/park/thread.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/park/thread.rs:5 | }
}
// ===== impl ParkThread =====
impl CachedParkThread {
/// Create a new `ParkThread` handle for the current thread.
///
/// This type cannot be moved to other threads, so it should be created on
/// the thread that the caller intends to park.
#[cfg(feature = "rt-full")]
pub(crate) fn new()... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/park/thread.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/runtime/park/thread.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/park/thread.rs:6 | self.with_current(|park_thread| park_thread.inner.park(Some(duration)))?;
Ok(())
}
}
impl Default for ParkThread {
fn default() -> Self {
Self::new()
}
}
// ===== impl UnparkThread =====
impl Unpark for UnparkThread {
fn unpark(&self) {
self.inner.unpark();
}
}
#[cfg(feat... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/park/thread.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/runtime/park/thread.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/process.rs:1 | #![cfg_attr(not(feature = "rt"), allow(dead_code))]
//! Process driver.
use crate::process::unix::GlobalOrphanQueue;
use crate::runtime::driver;
use crate::runtime::signal::{Driver as SignalDriver, Handle as SignalHandle};
use std::time::Duration;
/// Responsible for cleaning up orphaned child processes on Unix pla... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/process.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/runtime/process.rs | 1 | 44 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:1 | //! Run-queue structures to support a work-stealing scheduler
use crate::loom::cell::UnsafeCell;
use crate::loom::sync::atomic::{AtomicU16, AtomicU32};
use crate::loom::sync::Arc;
use crate::runtime::task::{self, Inject};
use crate::runtime::MetricsBatch;
use std::mem::MaybeUninit;
use std::ptr;
use std::sync::atomic... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 24f4ee31f0266a97547a81f510726da9c1bb9ec9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24f4ee31f0266a97547a81f510726da9c1bb9ec9/tokio/src/runtime/queue.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:2 | unsafe impl<T> Send for Inner<T> {}
unsafe impl<T> Sync for Inner<T> {}
#[cfg(not(loom))]
const LOCAL_QUEUE_CAPACITY: usize = 256;
// Shrink the size of the local queue when using loom. This shouldn't impact
// logic, but allows loom to test more edge cases in a reasonable a mount of
// time.
#[cfg(loom)]
const LOCAL... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 24f4ee31f0266a97547a81f510726da9c1bb9ec9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24f4ee31f0266a97547a81f510726da9c1bb9ec9/tokio/src/runtime/queue.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:3 | let local = Local {
inner: inner.clone(),
};
let remote = Steal(inner);
(remote, local)
}
impl<T> Local<T> {
/// Returns true if the queue has entries that can be stealed.
pub(super) fn is_stealable(&self) -> bool {
!self.inner.is_empty()
}
/// Returns false if there are ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 24f4ee31f0266a97547a81f510726da9c1bb9ec9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24f4ee31f0266a97547a81f510726da9c1bb9ec9/tokio/src/runtime/queue.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:7 | Some(task)
}
}
}
// safety: The CAS above ensures that no consumer will look at these
// values again, and we are the only producer.
let batch_iter = BatchTaskIter {
buffer: &*self.inner.buffer,
head: head as u32,
i: 0,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 24f4ee31f0266a97547a81f510726da9c1bb9ec9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24f4ee31f0266a97547a81f510726da9c1bb9ec9/tokio/src/runtime/queue.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:8 | pack(next_real, next_real)
} else {
assert_ne!(steal, next_real);
pack(steal, next_real)
};
// Attempt to claim a task.
let res = self
.inner
.head
.compare_exchange(head, next, AcqRel, Acqui... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 24f4ee31f0266a97547a81f510726da9c1bb9ec9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/24f4ee31f0266a97547a81f510726da9c1bb9ec9/tokio/src/runtime/queue.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:1 | //! Run-queue structures to support a work-stealing scheduler
use crate::loom::cell::UnsafeCell;
use crate::loom::sync::atomic::{AtomicU16, AtomicU32};
use crate::loom::sync::Arc;
use crate::runtime::stats::WorkerStatsBatcher;
use crate::runtime::task::{self, Inject};
use std::mem::MaybeUninit;
use std::ptr;
use std:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 957ed3eac07222a2d86ccfde8f29f29599f6f563 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/957ed3eac07222a2d86ccfde8f29f29599f6f563/tokio/src/runtime/queue.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:3 | let local = Local {
inner: inner.clone(),
};
let remote = Steal(inner);
(remote, local)
}
impl<T> Local<T> {
/// Returns true if the queue has entries that can be stealed.
pub(super) fn is_stealable(&self) -> bool {
!self.inner.is_empty()
}
/// Returns false if there are ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 957ed3eac07222a2d86ccfde8f29f29599f6f563 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/957ed3eac07222a2d86ccfde8f29f29599f6f563/tokio/src/runtime/queue.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:4 | } else {
// Push the current task and half of the queue into the
// inject queue.
match self.push_overflow(task, real, tail, inject) {
Ok(_) => return,
// Lost the race, try again
Err(v) => {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 957ed3eac07222a2d86ccfde8f29f29599f6f563 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/957ed3eac07222a2d86ccfde8f29f29599f6f563/tokio/src/runtime/queue.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:5 | &mut self,
task: task::Notified<T>,
head: u16,
tail: u16,
inject: &Inject<T>,
) -> Result<(), task::Notified<T>> {
/// How many elements are we taking from the local queue.
///
/// This is one less than the number of tasks pushed to the inject
/// queu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 957ed3eac07222a2d86ccfde8f29f29599f6f563 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/957ed3eac07222a2d86ccfde8f29f29599f6f563/tokio/src/runtime/queue.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:6 | ),
Release,
Relaxed,
)
.is_err()
{
// We failed to claim the tasks, losing the race. Return out of
// this function and try the full `push` routine again. The queue
// may not be full anymore.
return Err(task... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 957ed3eac07222a2d86ccfde8f29f29599f6f563 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/957ed3eac07222a2d86ccfde8f29f29599f6f563/tokio/src/runtime/queue.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:7 | // values again, and we are the only producer.
let batch_iter = BatchTaskIter {
buffer: &*self.inner.buffer,
head: head as u32,
i: 0,
};
inject.push_batch(batch_iter.chain(std::iter::once(task)));
Ok(())
}
/// Pops a task from the local queue... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 957ed3eac07222a2d86ccfde8f29f29599f6f563 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/957ed3eac07222a2d86ccfde8f29f29599f6f563/tokio/src/runtime/queue.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:8 | .head
.compare_exchange(head, next, AcqRel, Acquire);
match res {
Ok(_) => break real as usize & MASK,
Err(actual) => head = actual,
}
};
Some(self.inner.buffer[idx].with(|ptr| unsafe { ptr::read(ptr).assume_init() }))
}
}
im... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 957ed3eac07222a2d86ccfde8f29f29599f6f563 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/957ed3eac07222a2d86ccfde8f29f29599f6f563/tokio/src/runtime/queue.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:9 | // tasks in `dst`.
let mut n = self.steal_into2(dst, dst_tail);
stats.incr_steal_count(n);
if n == 0 {
// No tasks were stolen
return None;
}
// We are returning a task here
n -= 1;
let ret_pos = dst_tail.wrapping_add(n);
let ret... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 957ed3eac07222a2d86ccfde8f29f29599f6f563 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/957ed3eac07222a2d86ccfde8f29f29599f6f563/tokio/src/runtime/queue.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:10 | // If these two do not match, another thread is concurrently
// stealing from the queue.
if src_head_steal != src_head_real {
return 0;
}
// Number of available tasks to steal
let n = src_tail.wrapping_sub(src_head_real);
let n = n... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 957ed3eac07222a2d86ccfde8f29f29599f6f563 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/957ed3eac07222a2d86ccfde8f29f29599f6f563/tokio/src/runtime/queue.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:11 | // Compute the positions
let src_pos = first.wrapping_add(i);
let dst_pos = dst_tail.wrapping_add(i);
// Map to slots
let src_idx = src_pos as usize & MASK;
let dst_idx = dst_pos as usize & MASK;
// Read the task
//
// saf... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 957ed3eac07222a2d86ccfde8f29f29599f6f563 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/957ed3eac07222a2d86ccfde8f29f29599f6f563/tokio/src/runtime/queue.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:12 | prev_packed = actual;
}
}
}
}
}
impl<T> Clone for Steal<T> {
fn clone(&self) -> Steal<T> {
Steal(self.0.clone())
}
}
impl<T> Drop for Local<T> {
fn drop(&mut self) {
if !std::thread::panicking() {
assert!(self.pop().is_none(), "queue not ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 957ed3eac07222a2d86ccfde8f29f29599f6f563 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/957ed3eac07222a2d86ccfde8f29f29599f6f563/tokio/src/runtime/queue.rs | 441 | 489 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:2 | unsafe impl<T> Send for Inner<T> {}
unsafe impl<T> Sync for Inner<T> {}
#[cfg(not(loom))]
const LOCAL_QUEUE_CAPACITY: usize = 256;
// Shrink the size of the local queue when using loom. This shouldn't impact
// logic, but allows loom to test more edge cases in a reasonable a mount of
// time.
#[cfg(loom)]
const LOCAL... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 98578a6f4a494e709f00018b1cd5b0e3dd9a0f72 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/98578a6f4a494e709f00018b1cd5b0e3dd9a0f72/tokio/src/runtime/queue.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:3 | let local = Local {
inner: inner.clone(),
};
let remote = Steal(inner);
(remote, local)
}
impl<T> Local<T> {
/// Returns true if the queue has entries that can be stealed.
pub(super) fn is_stealable(&self) -> bool {
!self.inner.is_empty()
}
/// Pushes a task to the back o... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 98578a6f4a494e709f00018b1cd5b0e3dd9a0f72 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/98578a6f4a494e709f00018b1cd5b0e3dd9a0f72/tokio/src/runtime/queue.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:4 | }
}
}
};
// Map the position to a slot index.
let idx = tail as usize & MASK;
self.inner.buffer[idx].with_mut(|ptr| {
// Write the task to the slot
//
// Safety: There is only one producer and the above `if`
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 98578a6f4a494e709f00018b1cd5b0e3dd9a0f72 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/98578a6f4a494e709f00018b1cd5b0e3dd9a0f72/tokio/src/runtime/queue.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:5 | /// This is one less than the number of tasks pushed to the inject
/// queue as we are also inserting the `task` argument.
const NUM_TASKS_TAKEN: u16 = (LOCAL_QUEUE_CAPACITY / 2) as u16;
assert_eq!(
tail.wrapping_sub(head) as usize,
LOCAL_QUEUE_CAPACITY,
"que... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 98578a6f4a494e709f00018b1cd5b0e3dd9a0f72 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/98578a6f4a494e709f00018b1cd5b0e3dd9a0f72/tokio/src/runtime/queue.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:6 | // may not be full anymore.
return Err(task);
}
/// An iterator that takes elements out of the run queue.
struct BatchTaskIter<'a, T: 'static> {
buffer: &'a [UnsafeCell<MaybeUninit<task::Notified<T>>>; LOCAL_QUEUE_CAPACITY],
head: u32,
i: u32,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 98578a6f4a494e709f00018b1cd5b0e3dd9a0f72 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/98578a6f4a494e709f00018b1cd5b0e3dd9a0f72/tokio/src/runtime/queue.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:7 | Ok(())
}
/// Pops a task from the local queue.
pub(super) fn pop(&mut self) -> Option<task::Notified<T>> {
let mut head = self.inner.head.load(Acquire);
let idx = loop {
let (steal, real) = unpack(head);
// safety: this is the **only** thread that updates this cell... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 98578a6f4a494e709f00018b1cd5b0e3dd9a0f72 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/98578a6f4a494e709f00018b1cd5b0e3dd9a0f72/tokio/src/runtime/queue.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:8 | Some(self.inner.buffer[idx].with(|ptr| unsafe { ptr::read(ptr).assume_init() }))
}
}
impl<T> Steal<T> {
pub(super) fn is_empty(&self) -> bool {
self.0.is_empty()
}
/// Steals half the tasks from self and place them into `dst`.
pub(super) fn steal_into(
&self,
dst: &mut Loca... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 98578a6f4a494e709f00018b1cd5b0e3dd9a0f72 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/98578a6f4a494e709f00018b1cd5b0e3dd9a0f72/tokio/src/runtime/queue.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:9 | // We are returning a task here
n -= 1;
let ret_pos = dst_tail.wrapping_add(n);
let ret_idx = ret_pos as usize & MASK;
// safety: the value was written as part of `steal_into2` and not
// exposed to stealers, so no other thread can access it.
let ret = dst.inner.buffer[... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 98578a6f4a494e709f00018b1cd5b0e3dd9a0f72 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/98578a6f4a494e709f00018b1cd5b0e3dd9a0f72/tokio/src/runtime/queue.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:10 | let n = n - n / 2;
if n == 0 {
// No tasks available to steal
return 0;
}
// Update the real head index to acquire the tasks.
let steal_to = src_head_real.wrapping_add(n);
assert_ne!(src_head_steal, steal_to);
next... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 98578a6f4a494e709f00018b1cd5b0e3dd9a0f72 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/98578a6f4a494e709f00018b1cd5b0e3dd9a0f72/tokio/src/runtime/queue.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:11 | // Read the task
//
// safety: We acquired the task with the atomic exchange above.
let task = self.0.buffer[src_idx].with(|ptr| unsafe { ptr::read((*ptr).as_ptr()) });
// Write the task to the new slot
//
// safety: `dst` queue is empty and we ar... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 98578a6f4a494e709f00018b1cd5b0e3dd9a0f72 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/98578a6f4a494e709f00018b1cd5b0e3dd9a0f72/tokio/src/runtime/queue.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:12 | impl<T> Clone for Steal<T> {
fn clone(&self) -> Steal<T> {
Steal(self.0.clone())
}
}
impl<T> Drop for Local<T> {
fn drop(&mut self) {
if !std::thread::panicking() {
assert!(self.pop().is_none(), "queue not empty");
}
}
}
impl<T> Inner<T> {
fn is_empty(&self) -> ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 98578a6f4a494e709f00018b1cd5b0e3dd9a0f72 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/98578a6f4a494e709f00018b1cd5b0e3dd9a0f72/tokio/src/runtime/queue.rs | 441 | 481 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:1 | //! Run-queue structures to support a work-stealing scheduler
use crate::loom::cell::UnsafeCell;
use crate::loom::sync::atomic::{AtomicU16, AtomicU32};
use crate::loom::sync::Arc;
use crate::runtime::task::{self, Inject};
use std::mem::MaybeUninit;
use std::ptr;
use std::sync::atomic::Ordering::{AcqRel, Acquire, Rela... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 2087f3e0ebb08d633d59c5f964b3901e68b3c038 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2087f3e0ebb08d633d59c5f964b3901e68b3c038/tokio/src/runtime/queue.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:3 | inner: inner.clone(),
};
let remote = Steal(inner);
(remote, local)
}
impl<T> Local<T> {
/// Returns true if the queue has entries that can be stealed.
pub(super) fn is_stealable(&self) -> bool {
!self.inner.is_empty()
}
/// Pushes a task to the back of the local queue, skipping ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 2087f3e0ebb08d633d59c5f964b3901e68b3c038 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2087f3e0ebb08d633d59c5f964b3901e68b3c038/tokio/src/runtime/queue.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:4 | }
}
};
// Map the position to a slot index.
let idx = tail as usize & MASK;
self.inner.buffer[idx].with_mut(|ptr| {
// Write the task to the slot
//
// Safety: There is only one producer and the above `if`
// condition ensures... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 2087f3e0ebb08d633d59c5f964b3901e68b3c038 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2087f3e0ebb08d633d59c5f964b3901e68b3c038/tokio/src/runtime/queue.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:5 | /// queue as we are also inserting the `task` argument.
const NUM_TASKS_TAKEN: u16 = (LOCAL_QUEUE_CAPACITY / 2) as u16;
assert_eq!(
tail.wrapping_sub(head) as usize,
LOCAL_QUEUE_CAPACITY,
"queue is not full; tail = {}; head = {}",
tail,
head
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 2087f3e0ebb08d633d59c5f964b3901e68b3c038 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2087f3e0ebb08d633d59c5f964b3901e68b3c038/tokio/src/runtime/queue.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:6 | return Err(task);
}
/// An iterator that takes elements out of the run queue.
struct BatchTaskIter<'a, T: 'static> {
buffer: &'a [UnsafeCell<MaybeUninit<task::Notified<T>>>; LOCAL_QUEUE_CAPACITY],
head: u32,
i: u32,
}
impl<'a, T: 'static> Iter... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 2087f3e0ebb08d633d59c5f964b3901e68b3c038 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2087f3e0ebb08d633d59c5f964b3901e68b3c038/tokio/src/runtime/queue.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:7 | }
/// Pops a task from the local queue.
pub(super) fn pop(&mut self) -> Option<task::Notified<T>> {
let mut head = self.inner.head.load(Acquire);
let idx = loop {
let (steal, real) = unpack(head);
// safety: this is the **only** thread that updates this cell.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 2087f3e0ebb08d633d59c5f964b3901e68b3c038 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2087f3e0ebb08d633d59c5f964b3901e68b3c038/tokio/src/runtime/queue.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:8 | Some(self.inner.buffer[idx].with(|ptr| unsafe { ptr::read(ptr).assume_init() }))
}
}
impl<T> Steal<T> {
pub(super) fn is_empty(&self) -> bool {
self.0.is_empty()
}
/// Steals half the tasks from self and place them into `dst`.
pub(super) fn steal_into(&self, dst: &mut Local<T>) -> Option<t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 2087f3e0ebb08d633d59c5f964b3901e68b3c038 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2087f3e0ebb08d633d59c5f964b3901e68b3c038/tokio/src/runtime/queue.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:9 | // safety: the value was written as part of `steal_into2` and not
// exposed to stealers, so no other thread can access it.
let ret = dst.inner.buffer[ret_idx].with(|ptr| unsafe { ptr::read((*ptr).as_ptr()) });
if n == 0 {
// The `dst` queue is empty, but a single task was stolen
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 2087f3e0ebb08d633d59c5f964b3901e68b3c038 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2087f3e0ebb08d633d59c5f964b3901e68b3c038/tokio/src/runtime/queue.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:10 | // Update the real head index to acquire the tasks.
let steal_to = src_head_real.wrapping_add(n);
assert_ne!(src_head_steal, steal_to);
next_packed = pack(src_head_steal, steal_to);
// Claim all those tasks. This is done by incrementing the "real"
// head but... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 2087f3e0ebb08d633d59c5f964b3901e68b3c038 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2087f3e0ebb08d633d59c5f964b3901e68b3c038/tokio/src/runtime/queue.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:11 | //
// safety: `dst` queue is empty and we are the only producer to
// this queue.
dst.inner.buffer[dst_idx]
.with_mut(|ptr| unsafe { ptr::write((*ptr).as_mut_ptr(), task) });
}
let mut prev_packed = next_packed;
// Update `src_head_steal` to ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 2087f3e0ebb08d633d59c5f964b3901e68b3c038 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2087f3e0ebb08d633d59c5f964b3901e68b3c038/tokio/src/runtime/queue.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:12 | impl<T> Drop for Local<T> {
fn drop(&mut self) {
if !std::thread::panicking() {
assert!(self.pop().is_none(), "queue not empty");
}
}
}
impl<T> Inner<T> {
fn is_empty(&self) -> bool {
let (_, head) = unpack(self.head.load(Acquire));
let tail = self.tail.load(Acqu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 2087f3e0ebb08d633d59c5f964b3901e68b3c038 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2087f3e0ebb08d633d59c5f964b3901e68b3c038/tokio/src/runtime/queue.rs | 441 | 475 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:3 | inner: inner.clone(),
};
let remote = Steal(inner);
(remote, local)
}
impl<T> Local<T> {
/// Returns true if the queue has entries that can be stealed.
pub(super) fn is_stealable(&self) -> bool {
!self.inner.is_empty()
}
/// Pushes a task to the back of the local queue, skipping ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 3b38ebd7f5d50611193f942c31c57262f263be33 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3b38ebd7f5d50611193f942c31c57262f263be33/tokio/src/runtime/queue.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:4 | Ok(_) => return,
// Lost the race, try again
Err(v) => {
task = v;
}
}
}
};
// Map the position to a slot index.
let idx = tail as usize & MASK;
self.inner.buffer[idx].with_m... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 3b38ebd7f5d50611193f942c31c57262f263be33 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3b38ebd7f5d50611193f942c31c57262f263be33/tokio/src/runtime/queue.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:5 | inject: &Inject<T>,
) -> Result<(), task::Notified<T>> {
/// How many elements are we taking from the local queue.
///
/// This is one less than the number of tasks pushed to the inject
/// queue as we are also inserting the `task` argument.
const NUM_TASKS_TAKEN: u16 = (LOCA... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 3b38ebd7f5d50611193f942c31c57262f263be33 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3b38ebd7f5d50611193f942c31c57262f263be33/tokio/src/runtime/queue.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:6 | .is_err()
{
// We failed to claim the tasks, losing the race. Return out of
// this function and try the full `push` routine again. The queue
// may not be full anymore.
return Err(task);
}
/// An iterator that takes elements out of the run queue.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 3b38ebd7f5d50611193f942c31c57262f263be33 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3b38ebd7f5d50611193f942c31c57262f263be33/tokio/src/runtime/queue.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:7 | i: 0,
};
inject.push_batch(batch_iter.chain(std::iter::once(task)));
Ok(())
}
/// Pops a task from the local queue.
pub(super) fn pop(&mut self) -> Option<task::Notified<T>> {
let mut head = self.inner.head.load(Acquire);
let idx = loop {
let (steal, re... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 3b38ebd7f5d50611193f942c31c57262f263be33 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3b38ebd7f5d50611193f942c31c57262f263be33/tokio/src/runtime/queue.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:8 | Ok(_) => break real as usize & MASK,
Err(actual) => head = actual,
}
};
Some(self.inner.buffer[idx].with(|ptr| unsafe { ptr::read(ptr).assume_init() }))
}
}
impl<T> Steal<T> {
pub(super) fn is_empty(&self) -> bool {
self.0.is_empty()
}
/// Steals ha... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 3b38ebd7f5d50611193f942c31c57262f263be33 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3b38ebd7f5d50611193f942c31c57262f263be33/tokio/src/runtime/queue.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:9 | // We are returning a task here
n -= 1;
let ret_pos = dst_tail.wrapping_add(n);
let ret_idx = ret_pos as usize & MASK;
// safety: the value was written as part of `steal_into2` and not
// exposed to stealers, so no other thread can access it.
let ret = dst.inner.buffer[... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 3b38ebd7f5d50611193f942c31c57262f263be33 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3b38ebd7f5d50611193f942c31c57262f263be33/tokio/src/runtime/queue.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:10 | if n == 0 {
// No tasks available to steal
return 0;
}
// Update the real head index to acquire the tasks.
let steal_to = src_head_real.wrapping_add(n);
assert_ne!(src_head_steal, steal_to);
next_packed = pack(src_head_steal, s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 3b38ebd7f5d50611193f942c31c57262f263be33 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3b38ebd7f5d50611193f942c31c57262f263be33/tokio/src/runtime/queue.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:11 | //
// safety: We acquired the task with the atomic exchange above.
let task = self.0.buffer[src_idx].with(|ptr| unsafe { ptr::read((*ptr).as_ptr()) });
// Write the task to the new slot
//
// safety: `dst` queue is empty and we are the only producer to
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 3b38ebd7f5d50611193f942c31c57262f263be33 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3b38ebd7f5d50611193f942c31c57262f263be33/tokio/src/runtime/queue.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:12 | fn clone(&self) -> Steal<T> {
Steal(self.0.clone())
}
}
impl<T> Drop for Local<T> {
fn drop(&mut self) {
if !std::thread::panicking() {
assert!(self.pop().is_none(), "queue not empty");
}
}
}
impl<T> Inner<T> {
fn is_empty(&self) -> bool {
let (_, head) = un... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 3b38ebd7f5d50611193f942c31c57262f263be33 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3b38ebd7f5d50611193f942c31c57262f263be33/tokio/src/runtime/queue.rs | 441 | 480 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:1 | //! Run-queue structures to support a work-stealing scheduler
use crate::loom::cell::UnsafeCell;
use crate::loom::sync::atomic::{AtomicU16, AtomicU32, AtomicUsize};
use crate::loom::sync::{Arc, Mutex};
use crate::runtime::task;
use std::marker::PhantomData;
use std::mem::MaybeUninit;
use std::ptr::{self, NonNull};
us... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/queue.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:2 | /// capacity`.
///
/// When both `u16` values are the same, there is no active stealer.
///
/// Tracking an in-progress stealer prevents a wrapping scenario.
head: AtomicU32,
/// Only updated by producer thread but read by many threads.
tail: AtomicU16,
/// Elements
buffer: Box<[Un... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/queue.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:3 | /// Create a new local run-queue
pub(super) fn local<T: 'static>() -> (Steal<T>, Local<T>) {
let mut buffer = Vec::with_capacity(LOCAL_QUEUE_CAPACITY);
for _ in 0..LOCAL_QUEUE_CAPACITY {
buffer.push(UnsafeCell::new(MaybeUninit::uninit()));
}
let inner = Arc::new(Inner {
head: AtomicU32... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/queue.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:4 | let tail = unsafe { self.inner.tail.unsync_load() };
if tail.wrapping_sub(steal) < LOCAL_QUEUE_CAPACITY as u16 {
// There is capacity for the task
break tail;
} else if steal != real {
// Concurrently stealing, this will free up capacity, so only
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/queue.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:5 | });
// Make the task available. Synchronizes with a load in
// `steal_into2`.
self.inner.tail.store(tail.wrapping_add(1), Release);
}
/// Moves a batch of tasks into the inject queue.
///
/// This will temporarily make some of the tasks unavailable to stealers.
/// Once `pu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/queue.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:6 | // There isn't really any need for memory ordering... Relaxed would
// work. This is because all tasks are pushed into the queue from the
// current thread (or memory has been acquired if the local queue handle
// moved).
if self
.inner
.head
.compare_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/queue.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:7 | // safety: the above CAS prevents a stealer from accessing these
// tasks and we are the only producer.
self.inner.buffer[i_idx].with_mut(|ptr| unsafe {
let ptr = (*ptr).as_ptr();
(*ptr).header().set_next(Some(next))
});
}
// safety: t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/queue.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:8 | pack(next_real, next_real)
} else {
assert_ne!(steal, next_real);
pack(steal, next_real)
};
// Attempt to claim a task.
let res = self
.inner
.head
.compare_exchange(head, next, AcqRel, Acqui... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/queue.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:9 | // going to abort.
return None;
}
// Steal the tasks into `dst`'s buffer. This does not yet expose the
// tasks in `dst`.
let mut n = self.steal_into2(dst, dst_tail);
if n == 0 {
// No tasks were stolen
return None;
}
// We a... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/queue.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:10 | let n = loop {
let (src_head_steal, src_head_real) = unpack(prev_packed);
let src_tail = self.0.tail.load(Acquire);
// If these two do not match, another thread is concurrently
// stealing from the queue.
if src_head_steal != src_head_real {
r... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/queue.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:11 | let (first, _) = unpack(next_packed);
// Take all the tasks
for i in 0..n {
// Compute the positions
let src_pos = first.wrapping_add(i);
let dst_pos = dst_tail.wrapping_add(i);
// Map to slots
let src_idx = src_pos as usize & MASK;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/queue.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:12 | Err(actual) => {
let (actual_steal, actual_real) = unpack(actual);
assert_ne!(actual_steal, actual_real);
prev_packed = actual;
}
}
}
}
}
impl<T> Clone for Steal<T> {
fn clone(&self) -> Steal<T> {
Steal(se... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/queue.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:13 | head: None,
tail: None,
}),
len: AtomicUsize::new(0),
_p: PhantomData,
}
}
pub(super) fn is_empty(&self) -> bool {
self.len() == 0
}
/// Close the injection queue, returns `true` if the queue is open when the
/// transition is mad... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/queue.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:14 | T: crate::runtime::task::Schedule,
{
// Acquire queue lock
let mut p = self.pointers.lock();
if p.is_closed {
return Err(task);
}
// safety: only mutated with the lock held
let len = unsafe { self.len.unsync_load() };
let task = task.into_raw();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/queue.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:15 | if let Some(tail) = p.tail {
set_next(tail, Some(batch_head));
} else {
p.head = Some(batch_head);
}
p.tail = Some(batch_tail);
// Increment the count.
//
// safety: All updates to the len atomic are guarded by the mutex. As
// such, a no... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/queue.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:16 | // safety: All updates to the len atomic are guarded by the mutex. As
// such, a non-atomic load followed by a store is safe.
self.len
.store(unsafe { self.len.unsync_load() } - 1, Release);
// safety: a `Notified` is pushed into the queue and now it is popped!
Some(unsafe {... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/queue.rs | 601 | 646 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:3 | /// Create a new local run-queue
pub(super) fn local<T: 'static>() -> (Steal<T>, Local<T>) {
let mut buffer = Vec::with_capacity(LOCAL_QUEUE_CAPACITY);
for _ in 0..LOCAL_QUEUE_CAPACITY {
buffer.push(UnsafeCell::new(MaybeUninit::uninit()));
}
let inner = Arc::new(Inner {
head: AtomicU32... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 7601dc6d2a5c2902e78e220f44646960f910f38f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7601dc6d2a5c2902e78e220f44646960f910f38f/tokio/src/runtime/queue.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:4 | let tail = unsafe { self.inner.tail.unsync_load() };
if tail.wrapping_sub(steal) < LOCAL_QUEUE_CAPACITY as u16 {
// There is capacity for the task
break tail;
} else if steal != real {
// Concurrently stealing, this will free up capacity, so only
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | 7601dc6d2a5c2902e78e220f44646960f910f38f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7601dc6d2a5c2902e78e220f44646960f910f38f/tokio/src/runtime/queue.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:3 | /// Create a new local run-queue
pub(super) fn local<T: 'static>() -> (Steal<T>, Local<T>) {
let mut buffer = Vec::with_capacity(LOCAL_QUEUE_CAPACITY);
for _ in 0..LOCAL_QUEUE_CAPACITY {
buffer.push(UnsafeCell::new(MaybeUninit::uninit()));
}
let inner = Arc::new(Inner {
head: AtomicU32... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | a39e6c2439927ed9c73043401959b0b02d054630 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a39e6c2439927ed9c73043401959b0b02d054630/tokio/src/runtime/queue.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:4 | let tail = unsafe { self.inner.tail.unsync_load() };
if tail.wrapping_sub(steal) < LOCAL_QUEUE_CAPACITY as u16 {
// There is capacity for the task
break tail;
} else if steal != real {
// Concurrently stealing, this will free up capacity, so
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | a39e6c2439927ed9c73043401959b0b02d054630 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a39e6c2439927ed9c73043401959b0b02d054630/tokio/src/runtime/queue.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:5 | }
/// Moves a batch of tasks into the inject queue.
///
/// This will temporarily make some of the tasks unavailable to stealers.
/// Once `push_overflow` is done, a notification is sent out, so if other
/// workers "missed" some of the tasks during a steal, they will get
/// another opportunit... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | a39e6c2439927ed9c73043401959b0b02d054630 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a39e6c2439927ed9c73043401959b0b02d054630/tokio/src/runtime/queue.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:6 | .inner
.head
.compare_exchange(
prev,
pack(head.wrapping_add(n), head.wrapping_add(n)),
Release,
Relaxed,
)
.is_err()
{
// We failed to claim the tasks, losing the race. Return out of
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | a39e6c2439927ed9c73043401959b0b02d054630 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a39e6c2439927ed9c73043401959b0b02d054630/tokio/src/runtime/queue.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:7 | (*ptr).header().set_next(Some(next))
});
}
// safety: the above CAS prevents a stealer from accessing these tasks
// and we are the only producer.
let head = self.inner.buffer[head as usize & MASK]
.with(|ptr| unsafe { ptr::read((*ptr).as_ptr()) });
// P... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | a39e6c2439927ed9c73043401959b0b02d054630 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a39e6c2439927ed9c73043401959b0b02d054630/tokio/src/runtime/queue.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:8 | // Attempt to claim a task.
let res = self
.inner
.head
.compare_exchange(head, next, AcqRel, Acquire);
match res {
Ok(_) => break real as usize & MASK,
Err(actual) => head = actual,
}
};
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | a39e6c2439927ed9c73043401959b0b02d054630 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a39e6c2439927ed9c73043401959b0b02d054630/tokio/src/runtime/queue.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:9 | // tasks in `dst`.
let mut n = self.steal_into2(dst, dst_tail);
if n == 0 {
// No tasks were stolen
return None;
}
// We are returning a task here
n -= 1;
let ret_pos = dst_tail.wrapping_add(n);
let ret_idx = ret_pos as usize & MASK;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | a39e6c2439927ed9c73043401959b0b02d054630 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a39e6c2439927ed9c73043401959b0b02d054630/tokio/src/runtime/queue.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:10 | // stealing from the queue.
if src_head_steal != src_head_real {
return 0;
}
// Number of available tasks to steal
let n = src_tail.wrapping_sub(src_head_real);
let n = n - n / 2;
if n == 0 {
// No tasks available ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | a39e6c2439927ed9c73043401959b0b02d054630 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a39e6c2439927ed9c73043401959b0b02d054630/tokio/src/runtime/queue.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:11 | let src_pos = first.wrapping_add(i);
let dst_pos = dst_tail.wrapping_add(i);
// Map to slots
let src_idx = src_pos as usize & MASK;
let dst_idx = dst_pos as usize & MASK;
// Read the task
//
// safety: We acquired the task with the at... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | a39e6c2439927ed9c73043401959b0b02d054630 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a39e6c2439927ed9c73043401959b0b02d054630/tokio/src/runtime/queue.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:12 | prev_packed = actual;
}
}
}
}
}
impl<T> Clone for Steal<T> {
fn clone(&self) -> Steal<T> {
Steal(self.0.clone())
}
}
impl<T> Drop for Local<T> {
fn drop(&mut self) {
if !std::thread::panicking() {
assert!(self.pop().is_none(), "queue not ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | a39e6c2439927ed9c73043401959b0b02d054630 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a39e6c2439927ed9c73043401959b0b02d054630/tokio/src/runtime/queue.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:13 | }
}
pub(super) fn is_empty(&self) -> bool {
self.len() == 0
}
/// Close the injection queue, returns `true` if the queue is open when the
/// transition is made.
pub(super) fn close(&self) -> bool {
let mut p = self.pointers.lock();
if p.is_closed {
return ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | a39e6c2439927ed9c73043401959b0b02d054630 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a39e6c2439927ed9c73043401959b0b02d054630/tokio/src/runtime/queue.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/runtime/queue.rs:14 | task.shutdown();
return;
}
// safety: only mutated with the lock held
let len = unsafe { self.len.unsync_load() };
let task = task.into_raw();
// The next pointer should already be null
debug_assert!(get_next(task).is_none());
if let Some(tail) = p.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/queue.rs | MIT | a39e6c2439927ed9c73043401959b0b02d054630 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a39e6c2439927ed9c73043401959b0b02d054630/tokio/src/runtime/queue.rs | 521 | 580 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.