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/task/local.rs:28 | self.owned.remove(task)
}
/// Returns true if the `LocalSet` does not have any spawned tasks
unsafe fn owned_is_empty(&self) -> bool {
// The caller ensures it is called from the same thread that owns
// the LocalSet.
self.assert_called_from_owner_thread();
self.owned.is_em... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 63577cd8d3f2b1a1c787870125ab808eaa1eaa99 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/63577cd8d3f2b1a1c787870125ab808eaa1eaa99/tokio/src/task/local.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/task/local.rs:29 | context::thread_id()
.map(|id| id == self.owner)
.unwrap_or(true),
"`LocalSet`'s local run queue must not be accessed by another thread!"
);
}
}
// This is `Send` because it is stored in `Shared`. It is up to the caller to
// ensure they are on the same thread th... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 63577cd8d3f2b1a1c787870125ab808eaa1eaa99 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/63577cd8d3f2b1a1c787870125ab808eaa1eaa99/tokio/src/task/local.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/task/local.rs:30 | // This test has to be defined in the `local.rs` file as a lib test, rather
// than in `tests/`, because it makes assertions about the local set's
// internal state.
#[test]
fn wakes_to_local_queue() {
use super::*;
use crate::sync::Notify;
let rt = crate::runtime::Builder::new_c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 63577cd8d3f2b1a1c787870125ab808eaa1eaa99 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/63577cd8d3f2b1a1c787870125ab808eaa1eaa99/tokio/src/task/local.rs | 1,161 | 1,201 |
tokio-rs/tokio:tokio/src/task/local.rs:1 | //! Runs `!Send` futures on the current thread.
use crate::loom::cell::UnsafeCell;
use crate::loom::sync::{Arc, Mutex};
use crate::runtime::task::{self, JoinHandle, LocalOwnedTasks, Task};
use crate::runtime::{context, ThreadId};
use crate::sync::AtomicWaker;
use crate::util::RcCell;
use std::cell::Cell;
use std::coll... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 5e6d4c7999805a74d3dde95cd39ffdbb20bc2636 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5e6d4c7999805a74d3dde95cd39ffdbb20bc2636/tokio/src/task/local.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/task/local.rs:6 | /// async fn main() {
/// let spawner = LocalSpawner::new();
///
/// let (send, response) = oneshot::channel();
/// spawner.spawn(Task::AddOne(10, send));
/// let eleven = response.await.unwrap();
/// assert_eq!(eleven, 11);
/// }
/// ```
///
/// [`Send`]: tra... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 5e6d4c7999805a74d3dde95cd39ffdbb20bc2636 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5e6d4c7999805a74d3dde95cd39ffdbb20bc2636/tokio/src/task/local.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/task/local.rs:7 | ///
/// This field must *only* be accessed from the thread that owns the
/// `LocalSet` (i.e., `Thread::current().id() == owner`).
local_state: LocalState,
/// Remote run queue sender.
queue: Mutex<Option<VecDeque<task::Notified<Arc<Shared>>>>>,
/// Wake the `LocalSet` task.
waker: AtomicW... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 5e6d4c7999805a74d3dde95cd39ffdbb20bc2636 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5e6d4c7999805a74d3dde95cd39ffdbb20bc2636/tokio/src/task/local.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/task/local.rs:8 | } });
struct LocalData {
ctx: RcCell<Context>,
}
cfg_rt! {
/// Spawns a `!Send` future on the current [`LocalSet`].
///
/// The spawned future will run on the same thread that called `spawn_local`.
///
/// The provided future will start running in the background immediately
/// when `spawn... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 5e6d4c7999805a74d3dde95cd39ffdbb20bc2636 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5e6d4c7999805a74d3dde95cd39ffdbb20bc2636/tokio/src/task/local.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/task/local.rs:9 | /// // ...
/// }).await.unwrap();
/// }).await;
/// }
/// ```
///
/// [`LocalSet`]: struct@crate::task::LocalSet
/// [`tokio::spawn`]: fn@crate::task::spawn
#[track_caller]
pub fn spawn_local<F>(future: F) -> JoinHandle<F::Output>
where
F: Future +... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 5e6d4c7999805a74d3dde95cd39ffdbb20bc2636 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5e6d4c7999805a74d3dde95cd39ffdbb20bc2636/tokio/src/task/local.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/task/local.rs:10 | pub struct LocalEnterGuard(Option<Rc<Context>>);
impl Drop for LocalEnterGuard {
fn drop(&mut self) {
CURRENT.with(|LocalData { ctx, .. }| {
ctx.set(self.0.take());
})
}
}
impl fmt::Debug for LocalEnterGuard {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 5e6d4c7999805a74d3dde95cd39ffdbb20bc2636 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5e6d4c7999805a74d3dde95cd39ffdbb20bc2636/tokio/src/task/local.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/task/local.rs:14 | /// ```
///
/// [`spawn_local`]: fn@spawn_local
/// [`Runtime::block_on`]: method@crate::runtime::Runtime::block_on
/// [in-place blocking]: fn@crate::task::block_in_place
/// [`spawn_blocking`]: fn@crate::task::spawn_blocking
#[track_caller]
#[cfg(feature = "rt")]
#[cfg_attr(docsrs, doc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 5e6d4c7999805a74d3dde95cd39ffdbb20bc2636 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5e6d4c7999805a74d3dde95cd39ffdbb20bc2636/tokio/src/task/local.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/task/local.rs:15 | /// ```
///
/// [`spawn_local`]: fn@spawn_local
/// [awaiting the local set]: #awaiting-a-localset
pub async fn run_until<F>(&self, future: F) -> F::Output
where
F: Future,
{
let run_until = RunUntil {
future,
local_set: self,
};
run_until.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 5e6d4c7999805a74d3dde95cd39ffdbb20bc2636 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5e6d4c7999805a74d3dde95cd39ffdbb20bc2636/tokio/src/task/local.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/task/local.rs:16 | // Make sure we didn't hit an unhandled panic
if self.context.unhandled_panic.get() {
panic!("a spawned task panicked and the LocalSet is configured to shutdown on unhandled panic");
}
match self.next_task() {
// Run the task
//
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 5e6d4c7999805a74d3dde95cd39ffdbb20bc2636 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5e6d4c7999805a74d3dde95cd39ffdbb20bc2636/tokio/src/task/local.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/task/local.rs:17 | .shared
.queue
.lock()
.as_mut()
.and_then(|queue| queue.pop_front())
})
};
task.map(|task| unsafe {
// Safety: because the `LocalSet` itself is `!Send`, we know we are
// on the same thr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 5e6d4c7999805a74d3dde95cd39ffdbb20bc2636 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5e6d4c7999805a74d3dde95cd39ffdbb20bc2636/tokio/src/task/local.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/task/local.rs:18 | val: old,
};
f()
})
}
/// This method is like `with`, but it just calls `f` without setting the thread-local if that
/// fails.
fn with_if_possible<T>(&self, f: impl FnOnce() -> T) -> T {
let mut f = Some(f);
let res = CURRENT.try_with(|LocalData { ctx,... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 5e6d4c7999805a74d3dde95cd39ffdbb20bc2636 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5e6d4c7999805a74d3dde95cd39ffdbb20bc2636/tokio/src/task/local.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/task/local.rs:20 | ///
/// # #[tokio::main]
/// # async fn main() {
/// tokio::task::LocalSet::new()
/// .unhandled_panic(UnhandledPanic::ShutdownRuntime)
/// .run_until(async {
/// tokio::task::spawn_local(async { panic!("boom"); });
/// tokio::task::spawn_l... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 5e6d4c7999805a74d3dde95cd39ffdbb20bc2636 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5e6d4c7999805a74d3dde95cd39ffdbb20bc2636/tokio/src/task/local.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/task/local.rs:21 | // Register the waker before starting to work
self.context.shared.waker.register_by_ref(cx.waker());
if self.with(|| self.tick()) {
// If `tick` returns true, we need to notify the local future again:
// there are still tasks remaining in the run queue.
cx.waker().wa... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 5e6d4c7999805a74d3dde95cd39ffdbb20bc2636 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5e6d4c7999805a74d3dde95cd39ffdbb20bc2636/tokio/src/task/local.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/task/local.rs:22 | // need to call shutdown.
// Safety: note that this *intentionally* bypasses the unsafe
// `Shared::local_queue()` method. This is in order to avoid the
// debug assertion that we are on the thread that owns the
// `LocalSet`, because on some systems (e.g. at least some ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 5e6d4c7999805a74d3dde95cd39ffdbb20bc2636 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5e6d4c7999805a74d3dde95cd39ffdbb20bc2636/tokio/src/task/local.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/task/local.rs:23 | where
F: Future + 'static,
F::Output: 'static,
{
let id = crate::runtime::task::Id::next();
let future = crate::util::trace::task(future, "local", name, id.as_u64());
// Safety: called from the thread that owns the `LocalSet`
let (handle, notified) = {
se... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 5e6d4c7999805a74d3dde95cd39ffdbb20bc2636 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5e6d4c7999805a74d3dde95cd39ffdbb20bc2636/tokio/src/task/local.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/task/local.rs:24 | let f = me.future;
if let Poll::Ready(output) = f.poll(cx) {
return Poll::Ready(output);
}
if me.local_set.tick() {
// If `tick` returns `true`, we need to notify the local future again:
// there are still tasks remaining in the run q... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 5e6d4c7999805a74d3dde95cd39ffdbb20bc2636 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5e6d4c7999805a74d3dde95cd39ffdbb20bc2636/tokio/src/task/local.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/task/local.rs:25 | // We are *not* on the thread that owns the `LocalSet`, so we
// have to wake to the remote queue.
_ => {
// First, check whether the queue is still there (if not, the
// LocalSet is dropped). Then push to it if so, and if not,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 5e6d4c7999805a74d3dde95cd39ffdbb20bc2636 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5e6d4c7999805a74d3dde95cd39ffdbb20bc2636/tokio/src/task/local.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/task/local.rs:26 | use crate::runtime::UnhandledPanic;
match self.unhandled_panic {
UnhandledPanic::Ignore => {
// Do nothing
}
UnhandledPanic::ShutdownRuntime => {
// This hook is only called from within the runtime, so
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 5e6d4c7999805a74d3dde95cd39ffdbb20bc2636 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5e6d4c7999805a74d3dde95cd39ffdbb20bc2636/tokio/src/task/local.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/task/local.rs:27 | unsafe fn take_local_queue(&self) -> VecDeque<task::Notified<Arc<Shared>>> {
// The caller ensures it is called from the same thread that owns
// the LocalSet.
self.assert_called_from_owner_thread();
self.local_queue.with_mut(|ptr| std::mem::take(&mut (*ptr)))
}
unsafe fn task_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 5e6d4c7999805a74d3dde95cd39ffdbb20bc2636 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5e6d4c7999805a74d3dde95cd39ffdbb20bc2636/tokio/src/task/local.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/task/local.rs:28 | self.assert_called_from_owner_thread();
self.owned.close_and_shutdown_all()
}
#[track_caller]
fn assert_called_from_owner_thread(&self) {
// FreeBSD has some weirdness around thread-local destruction.
// TODO: remove this hack when thread id is cleaned up
#[cfg(not(any(targ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 5e6d4c7999805a74d3dde95cd39ffdbb20bc2636 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5e6d4c7999805a74d3dde95cd39ffdbb20bc2636/tokio/src/task/local.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/task/local.rs:29 | spawn_local(async {}).await.unwrap();
})
.await;
};
crate::runtime::Builder::new_current_thread()
.build()
.expect("rt")
.block_on(f)
}
// Tests that when a task on a `LocalSet` is woken by an io driver on the
// same threa... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 5e6d4c7999805a74d3dde95cd39ffdbb20bc2636 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5e6d4c7999805a74d3dde95cd39ffdbb20bc2636/tokio/src/task/local.rs | 1,121 | 1,175 |
tokio-rs/tokio:tokio/src/task/local.rs:30 | Poll::Ready(())
})
.await;
notify.notify_one();
let task = unsafe { local.context.shared.local_state.task_pop_front() };
// TODO(eliza): it would be nice to be able to assert that this is
// the local task.
assert!(
tas... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 5e6d4c7999805a74d3dde95cd39ffdbb20bc2636 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5e6d4c7999805a74d3dde95cd39ffdbb20bc2636/tokio/src/task/local.rs | 1,161 | 1,175 |
tokio-rs/tokio:tokio/src/task/local.rs:8 | } });
struct LocalData {
ctx: RcCell<Context>,
}
cfg_rt! {
/// Spawns a `!Send` future on the current [`LocalSet`].
///
/// The spawned future will run on the same thread that called `spawn_local`.
///
/// The provided future will start running in the background immediately
/// when `spawn... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 28d6f4d5093ba5f565e6836b81e3db79ca7a196a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/28d6f4d5093ba5f565e6836b81e3db79ca7a196a/tokio/src/task/local.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/task/local.rs:1 | //! Runs `!Send` futures on the current thread.
use crate::loom::cell::UnsafeCell;
use crate::loom::sync::{Arc, Mutex};
use crate::runtime::task::{self, JoinHandle, LocalOwnedTasks, Task};
use crate::runtime::{context, ThreadId};
use crate::sync::AtomicWaker;
use crate::util::RcCell;
use std::cell::Cell;
use std::coll... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 06f1a601bb05b1aba9f95020a7fa7572899c588f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/06f1a601bb05b1aba9f95020a7fa7572899c588f/tokio/src/task/local.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/task/local.rs:8 | } });
struct LocalData {
ctx: RcCell<Context>,
}
cfg_rt! {
/// Spawns a `!Send` future on the current [`LocalSet`].
///
/// The spawned future will run on the same thread that called `spawn_local`.
///
/// The provided future will start running in the background immediately
/// when `spawn... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 06f1a601bb05b1aba9f95020a7fa7572899c588f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/06f1a601bb05b1aba9f95020a7fa7572899c588f/tokio/src/task/local.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/task/local.rs:7 | ///
/// This field must *only* be accessed from the thread that owns the
/// `LocalSet` (i.e., `Thread::current().id() == owner`).
local_state: LocalState,
/// Remote run queue sender.
queue: Mutex<Option<VecDeque<task::Notified<Arc<Shared>>>>>,
/// Wake the `LocalSet` task.
waker: AtomicW... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | c6552c5680fa14105547cfbbc26b26d67197b64e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6552c5680fa14105547cfbbc26b26d67197b64e/tokio/src/task/local.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/task/local.rs:8 | } });
struct LocalData {
ctx: RcCell<Context>,
}
cfg_rt! {
/// Spawns a `!Send` future on the current [`LocalSet`].
///
/// The spawned future will run on the same thread that called `spawn_local`.
///
/// You do not have to `.await` the returned `JoinHandle` to make the
/// provided futur... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | c6552c5680fa14105547cfbbc26b26d67197b64e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6552c5680fa14105547cfbbc26b26d67197b64e/tokio/src/task/local.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/task/local.rs:10 | pub struct LocalEnterGuard(Option<Rc<Context>>);
impl Drop for LocalEnterGuard {
fn drop(&mut self) {
CURRENT.with(|LocalData { ctx, .. }| {
ctx.set(self.0.take());
})
}
}
impl fmt::Debug for LocalEnterGuard {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | c6552c5680fa14105547cfbbc26b26d67197b64e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6552c5680fa14105547cfbbc26b26d67197b64e/tokio/src/task/local.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/task/local.rs:14 | /// })
/// ```
///
/// [`spawn_local`]: fn@spawn_local
/// [`Runtime::block_on`]: method@crate::runtime::Runtime::block_on
/// [in-place blocking]: fn@crate::task::block_in_place
/// [`spawn_blocking`]: fn@crate::task::spawn_blocking
#[track_caller]
#[cfg(feature = "rt")]
#[cfg_attr(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | c6552c5680fa14105547cfbbc26b26d67197b64e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6552c5680fa14105547cfbbc26b26d67197b64e/tokio/src/task/local.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/task/local.rs:15 | /// }
/// ```
///
/// [`spawn_local`]: fn@spawn_local
/// [awaiting the local set]: #awaiting-a-localset
pub async fn run_until<F>(&self, future: F) -> F::Output
where
F: Future,
{
let run_until = RunUntil {
future,
local_set: self,
};
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | c6552c5680fa14105547cfbbc26b26d67197b64e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6552c5680fa14105547cfbbc26b26d67197b64e/tokio/src/task/local.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/task/local.rs:16 | for _ in 0..MAX_TASKS_PER_TICK {
// Make sure we didn't hit an unhandled panic
if self.context.unhandled_panic.get() {
panic!("a spawned task panicked and the LocalSet is configured to shutdown on unhandled panic");
}
match self.next_task() {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | c6552c5680fa14105547cfbbc26b26d67197b64e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6552c5680fa14105547cfbbc26b26d67197b64e/tokio/src/task/local.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/task/local.rs:17 | self.context
.shared
.queue
.lock()
.as_mut()
.and_then(|queue| queue.pop_front())
})
};
task.map(|task| unsafe {
// Safety: because the `LocalSet` itself is `!Send`, we know we a... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | c6552c5680fa14105547cfbbc26b26d67197b64e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6552c5680fa14105547cfbbc26b26d67197b64e/tokio/src/task/local.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/task/local.rs:18 | ctx_ref: ctx,
val: old,
};
f()
})
}
/// This method is like `with`, but it just calls `f` without setting the thread-local if that
/// fails.
fn with_if_possible<T>(&self, f: impl FnOnce() -> T) -> T {
let mut f = Some(f);
let res = CURR... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | c6552c5680fa14105547cfbbc26b26d67197b64e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6552c5680fa14105547cfbbc26b26d67197b64e/tokio/src/task/local.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/task/local.rs:20 | /// use tokio::runtime::UnhandledPanic;
///
/// # #[tokio::main]
/// # async fn main() {
/// tokio::task::LocalSet::new()
/// .unhandled_panic(UnhandledPanic::ShutdownRuntime)
/// .run_until(async {
/// tokio::task::spawn_local(async { panic!("boom... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | c6552c5680fa14105547cfbbc26b26d67197b64e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6552c5680fa14105547cfbbc26b26d67197b64e/tokio/src/task/local.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/task/local.rs:21 | fn poll(self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Self::Output> {
// Register the waker before starting to work
self.context.shared.waker.register_by_ref(cx.waker());
if self.with(|| self.tick()) {
// If `tick` returns true, we need to notify the local future ag... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | c6552c5680fa14105547cfbbc26b26d67197b64e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6552c5680fa14105547cfbbc26b26d67197b64e/tokio/src/task/local.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/task/local.rs:22 | // We already called shutdown on all tasks above, so there is no
// need to call shutdown.
// Safety: note that this *intentionally* bypasses the unsafe
// `Shared::local_queue()` method. This is in order to avoid the
// debug assertion that we are on the thread that own... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | c6552c5680fa14105547cfbbc26b26d67197b64e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6552c5680fa14105547cfbbc26b26d67197b64e/tokio/src/task/local.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/task/local.rs:23 | fn spawn<F>(&self, future: F, name: Option<&str>) -> JoinHandle<F::Output>
where
F: Future + 'static,
F::Output: 'static,
{
let id = crate::runtime::task::Id::next();
let future = crate::util::trace::task(future, "local", name, id.as_u64());
// Safety: called from the th... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | c6552c5680fa14105547cfbbc26b26d67197b64e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6552c5680fa14105547cfbbc26b26d67197b64e/tokio/src/task/local.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/task/local.rs:24 | let _no_blocking = crate::runtime::context::disallow_block_in_place();
let f = me.future;
if let Poll::Ready(output) = f.poll(cx) {
return Poll::Ready(output);
}
if me.local_set.tick() {
// If `tick` returns `true`, we need to notify the ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | c6552c5680fa14105547cfbbc26b26d67197b64e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6552c5680fa14105547cfbbc26b26d67197b64e/tokio/src/task/local.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/task/local.rs:25 | }
// We are *not* on the thread that owns the `LocalSet`, so we
// have to wake to the remote queue.
_ => {
// First, check whether the queue is still there (if not, the
// LocalSet is dropped). Then push to it if so, and if not,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | c6552c5680fa14105547cfbbc26b26d67197b64e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6552c5680fa14105547cfbbc26b26d67197b64e/tokio/src/task/local.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/task/local.rs:26 | fn unhandled_panic(&self) {
use crate::runtime::UnhandledPanic;
match self.unhandled_panic {
UnhandledPanic::Ignore => {
// Do nothing
}
UnhandledPanic::ShutdownRuntime => {
// This hook is only called from ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | c6552c5680fa14105547cfbbc26b26d67197b64e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6552c5680fa14105547cfbbc26b26d67197b64e/tokio/src/task/local.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/task/local.rs:27 | }
unsafe fn take_local_queue(&self) -> VecDeque<task::Notified<Arc<Shared>>> {
// The caller ensures it is called from the same thread that owns
// the LocalSet.
self.assert_called_from_owner_thread();
self.local_queue.with_mut(|ptr| std::mem::take(&mut (*ptr)))
}
unsafe f... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | c6552c5680fa14105547cfbbc26b26d67197b64e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6552c5680fa14105547cfbbc26b26d67197b64e/tokio/src/task/local.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/task/local.rs:28 | // the LocalSet.
self.assert_called_from_owner_thread();
self.owned.close_and_shutdown_all()
}
#[track_caller]
fn assert_called_from_owner_thread(&self) {
// FreeBSD has some weirdness around thread-local destruction.
// TODO: remove this hack when thread id is cleaned up
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | c6552c5680fa14105547cfbbc26b26d67197b64e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6552c5680fa14105547cfbbc26b26d67197b64e/tokio/src/task/local.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/task/local.rs:29 | .run_until(async {
spawn_local(async {}).await.unwrap();
})
.await;
};
crate::runtime::Builder::new_current_thread()
.build()
.expect("rt")
.block_on(f)
}
// Tests that when a task on a `LocalSet` is woken b... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | c6552c5680fa14105547cfbbc26b26d67197b64e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6552c5680fa14105547cfbbc26b26d67197b64e/tokio/src/task/local.rs | 1,121 | 1,176 |
tokio-rs/tokio:tokio/src/task/local.rs:30 | let _ = run_until.as_mut().poll(cx);
Poll::Ready(())
})
.await;
notify.notify_one();
let task = unsafe { local.context.shared.local_state.task_pop_front() };
// TODO(eliza): it would be nice to be able to assert that this is
// the... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | c6552c5680fa14105547cfbbc26b26d67197b64e | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6552c5680fa14105547cfbbc26b26d67197b64e/tokio/src/task/local.rs | 1,161 | 1,176 |
tokio-rs/tokio:tokio/src/task/local.rs:1 | //! Runs `!Send` futures on the current thread.
use crate::loom::cell::UnsafeCell;
use crate::loom::sync::{Arc, Mutex};
use crate::loom::thread::{self, ThreadId};
use crate::runtime::task::{self, JoinHandle, LocalOwnedTasks, Task};
use crate::sync::AtomicWaker;
use crate::util::RcCell;
use std::cell::Cell;
use std::co... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b7812c85ca2d051d47cec023b880cbf8cdcbc313 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7812c85ca2d051d47cec023b880cbf8cdcbc313/tokio/src/task/local.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/task/local.rs:7 | ///
/// This field must *only* be accessed from the thread that owns the
/// `LocalSet` (i.e., `Thread::current().id() == owner`).
local_state: LocalState,
/// Remote run queue sender.
queue: Mutex<Option<VecDeque<task::Notified<Arc<Shared>>>>>,
/// Wake the `LocalSet` task.
waker: AtomicW... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b7812c85ca2d051d47cec023b880cbf8cdcbc313 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7812c85ca2d051d47cec023b880cbf8cdcbc313/tokio/src/task/local.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/task/local.rs:8 | ctx: RcCell::new(),
} });
struct LocalData {
thread_id: Cell<Option<ThreadId>>,
ctx: RcCell<Context>,
}
cfg_rt! {
/// Spawns a `!Send` future on the current [`LocalSet`].
///
/// The spawned future will run on the same thread that called `spawn_local`.
///
/// You do not have to `.await` t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b7812c85ca2d051d47cec023b880cbf8cdcbc313 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7812c85ca2d051d47cec023b880cbf8cdcbc313/tokio/src/task/local.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/task/local.rs:9 | /// task::spawn_local(async move {
/// println!("{}", unsend_data);
/// // ...
/// }).await.unwrap();
/// }).await;
/// }
/// ```
///
/// [`LocalSet`]: struct@crate::task::LocalSet
/// [`tokio::spawn`]: fn@crate::task::spawn
#[track_cal... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b7812c85ca2d051d47cec023b880cbf8cdcbc313 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7812c85ca2d051d47cec023b880cbf8cdcbc313/tokio/src/task/local.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/task/local.rs:10 | /// Context guard for LocalSet
pub struct LocalEnterGuard(Option<Rc<Context>>);
impl Drop for LocalEnterGuard {
fn drop(&mut self) {
CURRENT.with(|LocalData { ctx, .. }| {
ctx.set(self.0.take());
})
}
}
impl fmt::Debug for LocalEnterGuard {
fn fmt(&self, f: &mut fmt::Formatter<... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b7812c85ca2d051d47cec023b880cbf8cdcbc313 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7812c85ca2d051d47cec023b880cbf8cdcbc313/tokio/src/task/local.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/task/local.rs:24 | let _no_blocking = crate::runtime::context::disallow_block_in_place();
let f = me.future;
if let Poll::Ready(output) = f.poll(cx) {
return Poll::Ready(output);
}
if me.local_set.tick() {
// If `tick` returns `true`, we need to notify the ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b7812c85ca2d051d47cec023b880cbf8cdcbc313 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7812c85ca2d051d47cec023b880cbf8cdcbc313/tokio/src/task/local.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/task/local.rs:27 | }
unsafe fn take_local_queue(&self) -> VecDeque<task::Notified<Arc<Shared>>> {
// The caller ensures it is called from the same thread that owns
// the LocalSet.
self.assert_called_from_owner_thread();
self.local_queue.with_mut(|ptr| std::mem::take(&mut (*ptr)))
}
unsafe f... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b7812c85ca2d051d47cec023b880cbf8cdcbc313 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7812c85ca2d051d47cec023b880cbf8cdcbc313/tokio/src/task/local.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/task/local.rs:28 | // the LocalSet.
self.assert_called_from_owner_thread();
self.owned.close_and_shutdown_all()
}
#[track_caller]
fn assert_called_from_owner_thread(&self) {
// FreeBSD has some weirdness around thread-local destruction.
// TODO: remove this hack when thread id is cleaned up
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b7812c85ca2d051d47cec023b880cbf8cdcbc313 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7812c85ca2d051d47cec023b880cbf8cdcbc313/tokio/src/task/local.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/src/task/local.rs:29 | CURRENT
.try_with(|localdata| localdata.get_or_insert_id())
.ok()
}
#[cfg(all(test, not(loom)))]
mod tests {
use super::*;
// Does a `LocalSet` running on a current-thread runtime...basically work?
//
// This duplicates a test in `tests/task_local_set.rs`, but because this is
// a ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b7812c85ca2d051d47cec023b880cbf8cdcbc313 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7812c85ca2d051d47cec023b880cbf8cdcbc313/tokio/src/task/local.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/src/task/local.rs:30 | let rt = crate::runtime::Builder::new_current_thread()
.build()
.expect("rt");
rt.block_on(async {
let local = LocalSet::new();
let notify = Arc::new(Notify::new());
let task = local.spawn_local({
let notify = notify.clone();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b7812c85ca2d051d47cec023b880cbf8cdcbc313 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7812c85ca2d051d47cec023b880cbf8cdcbc313/tokio/src/task/local.rs | 1,161 | 1,194 |
tokio-rs/tokio:tokio/src/task/local.rs:1 | //! Runs `!Send` futures on the current thread.
use crate::loom::sync::{Arc, Mutex};
use crate::loom::thread::{self, ThreadId};
use crate::runtime::task::{self, JoinHandle, LocalOwnedTasks, Task};
use crate::sync::AtomicWaker;
use crate::util::{RcCell, VecDequeCell};
use std::cell::Cell;
use std::collections::VecDeque... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/task/local.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/task/local.rs:6 | /// let spawner = LocalSpawner::new();
///
/// let (send, response) = oneshot::channel();
/// spawner.spawn(Task::AddOne(10, send));
/// let eleven = response.await.unwrap();
/// assert_eq!(eleven, 11);
/// }
/// ```
///
/// [`Send`]: trait@std::marker::Send
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/task/local.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/task/local.rs:7 | struct Shared {
/// Local run queue sender and receiver.
///
/// # Safety
///
/// This field must *only* be accessed from the thread that owns the
/// `LocalSet` (i.e., `Thread::current().id() == owner`).
local_queue: VecDequeCell<task::Notified<Arc<Shared>>>,
/// The `ThreadId` of the ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/task/local.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/task/local.rs:8 | thread_id: Cell<Option<ThreadId>>,
ctx: RcCell<Context>,
}
cfg_rt! {
/// Spawns a `!Send` future on the current [`LocalSet`].
///
/// The spawned future will run on the same thread that called `spawn_local`.
///
/// You do not have to `.await` the returned `JoinHandle` to make the
/// provi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/task/local.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/task/local.rs:9 | /// }).await;
/// }
/// ```
///
/// [`LocalSet`]: struct@crate::task::LocalSet
/// [`tokio::spawn`]: fn@crate::task::spawn
#[track_caller]
pub fn spawn_local<F>(future: F) -> JoinHandle<F::Output>
where
F: Future + 'static,
F::Output: 'static,
{
spawn_loca... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/task/local.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/task/local.rs:10 | impl Drop for LocalEnterGuard {
fn drop(&mut self) {
CURRENT.with(|LocalData { ctx, .. }| {
ctx.set(self.0.take());
})
}
}
impl fmt::Debug for LocalEnterGuard {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("LocalEnterGuard").finish()
}
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/task/local.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/task/local.rs:11 | /// [`spawn_local`]: fn@crate::task::spawn_local
pub fn enter(&self) -> LocalEnterGuard {
CURRENT.with(|LocalData { ctx, .. }| {
let old = ctx.replace(Some(self.context.clone()));
LocalEnterGuard(old)
})
}
/// Spawns a `!Send` task onto the local task set.
///
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/task/local.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/task/local.rs:14 | /// [`spawn_blocking`]: fn@crate::task::spawn_blocking
#[track_caller]
#[cfg(feature = "rt")]
#[cfg_attr(docsrs, doc(cfg(feature = "rt")))]
pub fn block_on<F>(&self, rt: &crate::runtime::Runtime, future: F) -> F::Output
where
F: Future,
{
rt.block_on(self.run_until(future))
}... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/task/local.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/task/local.rs:15 | where
F: Future,
{
let run_until = RunUntil {
future,
local_set: self,
};
run_until.await
}
pub(in crate::task) fn spawn_named<F>(
&self,
future: F,
name: Option<&str>,
) -> JoinHandle<F::Output>
where
F: Future... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/task/local.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/task/local.rs:16 | match self.next_task() {
// Run the task
//
// Safety: As spawned tasks are `!Send`, `run_unchecked` must be
// used. We are responsible for maintaining the invariant that
// `run_unchecked` is only called on threads that spawned the
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/task/local.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/task/local.rs:17 | })
};
task.map(|task| self.context.owned.assert_owner(task))
}
fn pop_local(&self) -> Option<task::Notified<Arc<Shared>>> {
unsafe {
// Safety: because the `LocalSet` itself is `!Send`, we know we are
// on the same thread if we have access to the `LocalSet`, an... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/task/local.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/task/local.rs:18 | let mut f = Some(f);
let res = CURRENT.try_with(|LocalData { ctx, .. }| {
struct Reset<'a> {
ctx_ref: &'a RcCell<Context>,
val: Option<Rc<Context>>,
}
impl<'a> Drop for Reset<'a> {
fn drop(&mut self) {
self.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/task/local.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/task/local.rs:20 | ///
/// // Do some work, but `run_until` will panic before it completes
/// # loop { tokio::task::yield_now().await; }
/// })
/// .await;
/// # }
/// ```
///
/// [`JoinHandle`]: struct@crate::task::JoinHandle
pub fn unhandled_panic(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/task/local.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/task/local.rs:21 | Poll::Ready(())
} else {
// There are still futures in the local set, but we've polled all the
// futures in the run queue. Therefore, we can just return Pending
// since the remaining futures will be woken from somewhere else.
Poll::Pending
}
}
}
imp... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/task/local.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/task/local.rs:22 | drop(task);
}
// Take the queue from the Shared object to prevent pushing
// notifications to it in the future.
let queue = self.context.shared.queue.lock().take().unwrap();
for task in queue {
drop(task);
}
assert!(se... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/task/local.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/task/local.rs:23 | type Output = T::Output;
fn poll(self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Self::Output> {
let me = self.project();
me.local_set.with(|| {
me.local_set
.context
.shared
.waker
.register_by_ref(cx.waker... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/task/local.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/task/local.rs:24 | thread_id().map(|id| id == self.owner).unwrap_or(true),
"`LocalSet`'s local run queue must not be accessed by another thread!"
);
&self.local_queue
}
/// Schedule the provided task on the scheduler.
fn schedule(&self, task: task::Notified<Arc<Self>>) {
CURRENT.with(|loca... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/task/local.rs | 921 | 980 |
tokio-rs/tokio:tokio/src/task/local.rs:25 | self.waker.wake();
}
}
}
});
}
fn ptr_eq(&self, other: &Shared) -> bool {
std::ptr::eq(self, other)
}
}
// This is safe because (and only because) we *pinky pwomise* to never touch the
// local run queue except from the thread that owns the `... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/task/local.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/src/task/local.rs:26 | // This hook is only called from within the runtime, so
// `CURRENT` should match with `&self`, i.e. there is no
// opportunity for a nested scheduler to be called.
CURRENT.with(|LocalData { ctx, .. }| match ctx.get() {
Some(cx) if Arc:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/task/local.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/src/task/local.rs:27 | // borrows violations in the `LocalSet` implementation.
#[test]
fn local_current_thread_scheduler() {
let f = async {
LocalSet::new()
.run_until(async {
spawn_local(async {}).await.unwrap();
})
.await;
};
cra... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/task/local.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/src/task/local.rs:28 | task.await.unwrap();
}));
// poll the run until future once
crate::future::poll_fn(|cx| {
let _ = run_until.as_mut().poll(cx);
Poll::Ready(())
})
.await;
notify.notify_one();
let task = unsafe { local.c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 687aa2bae5d6c70bb942238d793d9d2a41e59ac9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/687aa2bae5d6c70bb942238d793d9d2a41e59ac9/tokio/src/task/local.rs | 1,081 | 1,101 |
tokio-rs/tokio:tokio/src/task/local.rs:22 | drop(task);
}
// Take the queue from the Shared object to prevent pushing
// notifications to it in the future.
let queue = self.context.shared.queue.lock().take().unwrap();
for task in queue {
drop(task);
}
assert!(se... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | ca8e176ce98d2372c24c74839877189cbc9883dc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ca8e176ce98d2372c24c74839877189cbc9883dc/tokio/src/task/local.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/task/local.rs:23 | type Output = T::Output;
fn poll(self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Self::Output> {
let me = self.project();
me.local_set.with(|| {
me.local_set
.context
.shared
.waker
.register_by_ref(cx.waker... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | ca8e176ce98d2372c24c74839877189cbc9883dc | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ca8e176ce98d2372c24c74839877189cbc9883dc/tokio/src/task/local.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/task/local.rs:22 | drop(task);
}
// Take the queue from the Shared object to prevent pushing
// notifications to it in the future.
let queue = self.context.shared.queue.lock().take().unwrap();
for task in queue {
drop(task);
}
assert!(se... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/task/local.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/task/local.rs:23 | type Output = T::Output;
fn poll(self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Self::Output> {
let me = self.project();
me.local_set.with(|| {
me.local_set
.context
.shared
.waker
.register_by_ref(cx.waker... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/task/local.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/task/local.rs:15 | where
F: Future,
{
let run_until = RunUntil {
future,
local_set: self,
};
run_until.await
}
pub(in crate::task) fn spawn_named<F>(
&self,
future: F,
name: Option<&str>,
) -> JoinHandle<F::Output>
where
F: Future... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b1f40f4356c7f7be0e1959f992608d2058a76deb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1f40f4356c7f7be0e1959f992608d2058a76deb/tokio/src/task/local.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/task/local.rs:16 | match self.next_task() {
// Run the task
//
// Safety: As spawned tasks are `!Send`, `run_unchecked` must be
// used. We are responsible for maintaining the invariant that
// `run_unchecked` is only called on threads that spawned the
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b1f40f4356c7f7be0e1959f992608d2058a76deb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1f40f4356c7f7be0e1959f992608d2058a76deb/tokio/src/task/local.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/task/local.rs:22 | drop(task);
}
// Take the queue from the Shared object to prevent pushing
// notifications to it in the future.
let queue = self.context.shared.queue.lock().take().unwrap();
for task in queue {
drop(task);
}
assert!(se... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b1f40f4356c7f7be0e1959f992608d2058a76deb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1f40f4356c7f7be0e1959f992608d2058a76deb/tokio/src/task/local.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/task/local.rs:23 | type Output = T::Output;
fn poll(self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Self::Output> {
let me = self.project();
me.local_set.with(|| {
me.local_set
.context
.shared
.waker
.register_by_ref(cx.waker... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b1f40f4356c7f7be0e1959f992608d2058a76deb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b1f40f4356c7f7be0e1959f992608d2058a76deb/tokio/src/task/local.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/task/local.rs:22 | drop(task);
}
// Take the queue from the Shared object to prevent pushing
// notifications to it in the future.
let queue = self.context.shared.queue.lock().take().unwrap();
for task in queue {
drop(task);
}
assert!(se... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b248be2879dfc5e19d1b82561486efede74172ba | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b248be2879dfc5e19d1b82561486efede74172ba/tokio/src/task/local.rs | 841 | 900 |
tokio-rs/tokio:tokio/src/task/local.rs:23 | type Output = T::Output;
fn poll(self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Self::Output> {
let me = self.project();
me.local_set.with(|| {
me.local_set
.context
.shared
.waker
.register_by_ref(cx.waker... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b248be2879dfc5e19d1b82561486efede74172ba | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b248be2879dfc5e19d1b82561486efede74172ba/tokio/src/task/local.rs | 881 | 940 |
tokio-rs/tokio:tokio/src/task/local.rs:7 | struct Shared {
/// Local run queue sender and receiver.
///
/// # Safety
///
/// This field must *only* be accessed from the thread that owns the
/// `LocalSet` (i.e., `Thread::current().id() == owner`).
local_queue: VecDequeCell<task::Notified<Arc<Shared>>>,
/// The `ThreadId` of the ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | f8097437dde60e9478e3f38302ac28bf5bc3f3f5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f8097437dde60e9478e3f38302ac28bf5bc3f3f5/tokio/src/task/local.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/task/local.rs:8 | thread_id: Cell<Option<ThreadId>>,
ctx: RcCell<Context>,
}
cfg_rt! {
/// Spawns a `!Send` future on the local task set.
///
/// The spawned future will be run on the same thread that called `spawn_local.`
/// This may only be called from the context of a local task set.
///
/// # Panics
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | f8097437dde60e9478e3f38302ac28bf5bc3f3f5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f8097437dde60e9478e3f38302ac28bf5bc3f3f5/tokio/src/task/local.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/task/local.rs:9 | F::Output: 'static,
{
spawn_local_inner(future, None)
}
#[track_caller]
pub(super) fn spawn_local_inner<F>(future: F, name: Option<&str>) -> JoinHandle<F::Output>
where F: Future + 'static,
F::Output: 'static
{
match CURRENT.with(|LocalData { ctx, .. }| ctx.get()) {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | f8097437dde60e9478e3f38302ac28bf5bc3f3f5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f8097437dde60e9478e3f38302ac28bf5bc3f3f5/tokio/src/task/local.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/task/local.rs:10 | f.debug_struct("LocalEnterGuard").finish()
}
}
impl LocalSet {
/// Returns a new local task set.
pub fn new() -> LocalSet {
LocalSet {
tick: Cell::new(0),
context: Rc::new(Context {
owned: LocalOwnedTasks::new(),
shared: Arc::new(Shared {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | f8097437dde60e9478e3f38302ac28bf5bc3f3f5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f8097437dde60e9478e3f38302ac28bf5bc3f3f5/tokio/src/task/local.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/task/local.rs:14 | /// background until the future passed to `run_until` completes. When the future
/// passed to `run` finishes, any local futures which have not completed
/// will remain on the local set, and will be driven on subsequent calls to
/// `run_until` or when [awaiting the local set] itself.
///
/// # Exa... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | f8097437dde60e9478e3f38302ac28bf5bc3f3f5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f8097437dde60e9478e3f38302ac28bf5bc3f3f5/tokio/src/task/local.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/task/local.rs:15 | F: Future + 'static,
F::Output: 'static,
{
let handle = self.context.spawn(future, name);
// Because a task was spawned from *outside* the `LocalSet`, wake the
// `LocalSet` future to execute the new task, if it hasn't been woken.
//
// Spawning via the free fn `spaw... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | f8097437dde60e9478e3f38302ac28bf5bc3f3f5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f8097437dde60e9478e3f38302ac28bf5bc3f3f5/tokio/src/task/local.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/task/local.rs:16 | true
}
fn next_task(&self) -> Option<task::LocalNotified<Arc<Shared>>> {
let tick = self.tick.get();
self.tick.set(tick.wrapping_add(1));
let task = if tick % REMOTE_FIRST_INTERVAL == 0 {
self.context
.shared
.queue
.lock()
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | f8097437dde60e9478e3f38302ac28bf5bc3f3f5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f8097437dde60e9478e3f38302ac28bf5bc3f3f5/tokio/src/task/local.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/task/local.rs:17 | CURRENT.with(|LocalData { ctx, .. }| {
struct Reset<'a> {
ctx_ref: &'a RcCell<Context>,
val: Option<Rc<Context>>,
}
impl<'a> Drop for Reset<'a> {
fn drop(&mut self) {
self.ctx_ref.set(self.val.take());
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | f8097437dde60e9478e3f38302ac28bf5bc3f3f5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f8097437dde60e9478e3f38302ac28bf5bc3f3f5/tokio/src/task/local.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/task/local.rs:19 | /// This option is currently unstable and its implementation is
/// incomplete. The API may change or be removed in the future. See
/// tokio-rs/tokio#4516 for more details.
///
/// # Examples
///
/// The following demonstrates a `LocalSet` configured to shutdown on
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | f8097437dde60e9478e3f38302ac28bf5bc3f3f5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f8097437dde60e9478e3f38302ac28bf5bc3f3f5/tokio/src/task/local.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/task/local.rs:20 | }
}
}
impl fmt::Debug for LocalSet {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("LocalSet").finish()
}
}
impl Future for LocalSet {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Self::Output> {
// Regist... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | f8097437dde60e9478e3f38302ac28bf5bc3f3f5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f8097437dde60e9478e3f38302ac28bf5bc3f3f5/tokio/src/task/local.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/task/local.rs:21 | impl Drop for LocalSet {
fn drop(&mut self) {
self.with_if_possible(|| {
// Shut down all tasks in the LocalOwnedTasks and close it to
// prevent new tasks from ever being added.
self.context.owned.close_and_shutdown_all();
// We already called shutdown on al... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | f8097437dde60e9478e3f38302ac28bf5bc3f3f5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f8097437dde60e9478e3f38302ac28bf5bc3f3f5/tokio/src/task/local.rs | 801 | 860 |
tokio-rs/tokio:tokio/src/task/local.rs:22 | impl Context {
#[track_caller]
fn spawn<F>(&self, future: F, name: Option<&str>) -> JoinHandle<F::Output>
where
F: Future + 'static,
F::Output: 'static,
{
let id = crate::runtime::task::Id::next();
let future = crate::util::trace::task(future, "local", name, id.as_u64());... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | f8097437dde60e9478e3f38302ac28bf5bc3f3f5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f8097437dde60e9478e3f38302ac28bf5bc3f3f5/tokio/src/task/local.rs | 841 | 900 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.