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:14 | fn local_threadpool_blocking_in_place() {
thread_local! {
static ON_RT_THREAD: Cell<bool> = Cell::new(false);
}
ON_RT_THREAD.with(|cell| cell.set(true));
let mut rt = runtime::Builder::new()
.threaded_scheduler()
.enable_all()
.build()
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 41d15ea212525f4be310d65c29c626488af546e1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/41d15ea212525f4be310d65c29c626488af546e1/tokio/src/task/local.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/task/local.rs:15 | task::spawn_blocking(|| {
assert!(
!ON_RT_THREAD.with(|cell| cell.get()),
"blocking must not run on the local task set's thread"
);
})
.await
.unwrap();
assert!(ON_RT_T... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 41d15ea212525f4be310d65c29c626488af546e1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/41d15ea212525f4be310d65c29c626488af546e1/tokio/src/task/local.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/task/local.rs:16 | }
#[test]
fn nested_spawn_is_local() {
thread_local! {
static ON_RT_THREAD: Cell<bool> = Cell::new(false);
}
ON_RT_THREAD.with(|cell| cell.set(true));
let mut rt = runtime::Builder::new()
.threaded_scheduler()
.build()
.unwrap();... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 41d15ea212525f4be310d65c29c626488af546e1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/41d15ea212525f4be310d65c29c626488af546e1/tokio/src/task/local.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/task/local.rs:17 | thread_local! {
static ON_RT_THREAD: Cell<bool> = Cell::new(false);
}
ON_RT_THREAD.with(|cell| cell.set(true));
let mut rt = runtime::Builder::new()
.threaded_scheduler()
.build()
.unwrap();
let local = LocalSet::new();
local.bloc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 41d15ea212525f4be310d65c29c626488af546e1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/41d15ea212525f4be310d65c29c626488af546e1/tokio/src/task/local.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/task/local.rs:18 | #[test]
fn drop_cancels_tasks() {
// This test reproduces issue #1842
let mut rt = runtime::Builder::new()
.enable_time()
.basic_scheduler()
.build()
.unwrap();
let (started_tx, started_rx) = oneshot::channel();
let local = LocalSet::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 41d15ea212525f4be310d65c29c626488af546e1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/41d15ea212525f4be310d65c29c626488af546e1/tokio/src/task/local.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/task/local.rs:19 | let local = LocalSet::new();
local.spawn_local(async move { while let Some(_) = rx.recv().await {} });
local.block_on(&mut rt, async {
crate::time::delay_for(Duration::from_millis(1)).await;
});
drop(tx);
// This enters an infinite loop if th... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 41d15ea212525f4be310d65c29c626488af546e1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/41d15ea212525f4be310d65c29c626488af546e1/tokio/src/task/local.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/task/local.rs:20 | thread.join().expect("test thread should not panic!")
}
#[test]
fn local_tasks_are_polled_after_tick() {
// Reproduces issues #1899 and #1900
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
static RX1: AtomicUsize = AtomicUsize::new(0);
static RX2: AtomicUsize = Ato... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 41d15ea212525f4be310d65c29c626488af546e1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/41d15ea212525f4be310d65c29c626488af546e1/tokio/src/task/local.rs | 761 | 820 |
tokio-rs/tokio:tokio/src/task/local.rs:21 | tx.send(()).unwrap();
}
time::delay_for(Duration::from_millis(300)).await;
let rx1 = RX1.load(SeqCst);
let rx2 = RX2.load(SeqCst);
println!("EXPECT = {}; RX1 = {}; RX2 = {}", EXPECTED, rx1, rx2);
assert_eq!(EXPECTED, rx1);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 41d15ea212525f4be310d65c29c626488af546e1 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/41d15ea212525f4be310d65c29c626488af546e1/tokio/src/task/local.rs | 801 | 824 |
tokio-rs/tokio:tokio/src/task/local.rs:9 | // === impl Scheduler ===
impl Schedule for Scheduler {
fn bind(&self, task: &Task<Self>) {
assert!(self.is_current());
unsafe {
self.queues.add_task(task);
}
}
fn release(&self, task: Task<Self>) {
// This will be called when dropping the local runtime.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b7ecd350365c2695b2cc6f513ef8a5ec7e320916 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7ecd350365c2695b2cc6f513ef8a5ec7e320916/tokio/src/task/local.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/task/local.rs:11 | let tick = self.tick.get().wrapping_add(1);
self.tick.set(tick);
let task = match unsafe {
// safety: we must be on the local thread to call this. The assertion
// the top of this method ensures that `tick` is only called locally.
self.queues.next... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b7ecd350365c2695b2cc6f513ef8a5ec7e320916 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7ecd350365c2695b2cc6f513ef8a5ec7e320916/tokio/src/task/local.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/task/local.rs:12 | self.queues.drain_pending_drop();
}
}
}
}
#[cfg(all(test, not(loom)))]
mod tests {
use super::*;
use crate::{
runtime,
sync::{mpsc, oneshot},
task, time,
};
use std::time::Duration;
#[test]
fn local_current_thread() {
let mut rt = runtime... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b7ecd350365c2695b2cc6f513ef8a5ec7e320916 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7ecd350365c2695b2cc6f513ef8a5ec7e320916/tokio/src/task/local.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/task/local.rs:13 | });
}
#[test]
fn local_threadpool_timer() {
// This test ensures that runtime services like the timer are properly
// set for the local task set.
thread_local! {
static ON_RT_THREAD: Cell<bool> = Cell::new(false);
}
ON_RT_THREAD.with(|cell| cell.set(true... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b7ecd350365c2695b2cc6f513ef8a5ec7e320916 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7ecd350365c2695b2cc6f513ef8a5ec7e320916/tokio/src/task/local.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/task/local.rs:14 | let mut rt = runtime::Builder::new()
.threaded_scheduler()
.enable_all()
.build()
.unwrap();
LocalSet::new().block_on(&mut rt, async {
assert!(ON_RT_THREAD.with(|cell| cell.get()));
let join = spawn_local(async move {
assert... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b7ecd350365c2695b2cc6f513ef8a5ec7e320916 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7ecd350365c2695b2cc6f513ef8a5ec7e320916/tokio/src/task/local.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/task/local.rs:15 | .unwrap();
assert!(ON_RT_THREAD.with(|cell| cell.get()));
});
join.await.unwrap();
});
}
#[test]
fn all_spawns_are_local() {
use futures::future;
thread_local! {
static ON_RT_THREAD: Cell<bool> = Cell::new(false);
}
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b7ecd350365c2695b2cc6f513ef8a5ec7e320916 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7ecd350365c2695b2cc6f513ef8a5ec7e320916/tokio/src/task/local.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/task/local.rs:16 | ON_RT_THREAD.with(|cell| cell.set(true));
let mut rt = runtime::Builder::new()
.threaded_scheduler()
.build()
.unwrap();
LocalSet::new().block_on(&mut rt, async {
assert!(ON_RT_THREAD.with(|cell| cell.get()));
spawn_local(async {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b7ecd350365c2695b2cc6f513ef8a5ec7e320916 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7ecd350365c2695b2cc6f513ef8a5ec7e320916/tokio/src/task/local.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/task/local.rs:17 | .threaded_scheduler()
.build()
.unwrap();
let local = LocalSet::new();
local.block_on(&mut rt, async move {
let (tx, rx) = crate::sync::oneshot::channel();
let join = spawn_local(async move {
println!("hello world running...");
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b7ecd350365c2695b2cc6f513ef8a5ec7e320916 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7ecd350365c2695b2cc6f513ef8a5ec7e320916/tokio/src/task/local.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/task/local.rs:18 | .unwrap();
let (started_tx, started_rx) = oneshot::channel();
let local = LocalSet::new();
local.spawn_local(async move {
started_tx.send(()).unwrap();
loop {
time::delay_for(Duration::from_secs(3600)).await;
}
});
local.bloc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b7ecd350365c2695b2cc6f513ef8a5ec7e320916 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7ecd350365c2695b2cc6f513ef8a5ec7e320916/tokio/src/task/local.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/task/local.rs:19 | drop(tx);
// This enters an infinite loop if the remote notified tasks are not
// properly cancelled.
drop(local);
// Send a message on the channel so that the test thread can
// determine if we have entered an infinite loop:
done_tx.send(()).unw... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b7ecd350365c2695b2cc6f513ef8a5ec7e320916 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7ecd350365c2695b2cc6f513ef8a5ec7e320916/tokio/src/task/local.rs | 721 | 780 |
tokio-rs/tokio:tokio/src/task/local.rs:20 | use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
static RX1: AtomicUsize = AtomicUsize::new(0);
static RX2: AtomicUsize = AtomicUsize::new(0);
static EXPECTED: usize = 500;
let (tx, mut rx) = mpsc::unbounded_channel();
let mut rt = runtime::Builder::new()
.b... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b7ecd350365c2695b2cc6f513ef8a5ec7e320916 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7ecd350365c2695b2cc6f513ef8a5ec7e320916/tokio/src/task/local.rs | 761 | 817 |
tokio-rs/tokio:tokio/src/task/local.rs:21 | assert_eq!(EXPECTED, rx1);
assert_eq!(EXPECTED, rx2);
});
while let Some(oneshot) = rx.recv().await {
RX1.fetch_add(1, SeqCst);
task::spawn_local(async move {
oneshot.await.unwrap();
RX2.fetch_add(1, SeqCst... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | b7ecd350365c2695b2cc6f513ef8a5ec7e320916 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b7ecd350365c2695b2cc6f513ef8a5ec7e320916/tokio/src/task/local.rs | 801 | 817 |
tokio-rs/tokio:tokio/src/task/local.rs:8 | /// [`spawn_blocking`]: ../blocking/fn.spawn_blocking.html
pub fn block_on<F>(&self, rt: &mut crate::runtime::Runtime, future: F) -> F::Output
where
F: Future,
{
let scheduler = self.scheduler.clone();
self.scheduler
.with(move || rt.block_on(LocalFuture { scheduler, futu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 0e729aa341028c121b9c39fe552ed4309bae6b6a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0e729aa341028c121b9c39fe552ed4309bae6b6a/tokio/src/task/local.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/task/local.rs:9 | unsafe {
self.queues.add_task(task);
}
}
fn release(&self, task: Task<Self>) {
// This will be called when dropping the local runtime.
self.queues.release_remote(task);
}
fn release_local(&self, task: &Task<Self>) {
debug_assert!(self.is_current());
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 0e729aa341028c121b9c39fe552ed4309bae6b6a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0e729aa341028c121b9c39fe552ed4309bae6b6a/tokio/src/task/local.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/task/local.rs:10 | fn with<F>(&self, f: impl FnOnce() -> F) -> F {
struct Entered<'a> {
current: &'a Cell<Option<NonNull<Scheduler>>>,
}
impl<'a> Drop for Entered<'a> {
fn drop(&mut self) {
self.current.set(None);
}
}
CURRENT_TASK_SET.with(|curr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 0e729aa341028c121b9c39fe552ed4309bae6b6a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0e729aa341028c121b9c39fe552ed4309bae6b6a/tokio/src/task/local.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/task/local.rs:11 | } {
Some(task) => task,
None => return,
};
if let Some(task) = task.run(&mut || Some(self.into())) {
unsafe {
// safety: we must be on the local thread to call this. The
// the top of this method ensures tha... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 0e729aa341028c121b9c39fe552ed4309bae6b6a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0e729aa341028c121b9c39fe552ed4309bae6b6a/tokio/src/task/local.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/task/local.rs:12 | #[test]
fn local_current_thread() {
let mut rt = runtime::Builder::new().basic_scheduler().build().unwrap();
LocalSet::new().block_on(&mut rt, async {
spawn_local(async {}).await.unwrap();
});
}
#[test]
fn local_threadpool() {
thread_local! {
stat... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 0e729aa341028c121b9c39fe552ed4309bae6b6a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0e729aa341028c121b9c39fe552ed4309bae6b6a/tokio/src/task/local.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/task/local.rs:13 | .enable_all()
.build()
.unwrap();
LocalSet::new().block_on(&mut rt, async {
assert!(ON_RT_THREAD.with(|cell| cell.get()));
let join = spawn_local(async move {
assert!(ON_RT_THREAD.with(|cell| cell.get()));
crate::time::delay_for(Dur... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 0e729aa341028c121b9c39fe552ed4309bae6b6a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0e729aa341028c121b9c39fe552ed4309bae6b6a/tokio/src/task/local.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/task/local.rs:14 | #[test]
fn local_threadpool_blocking_run() {
thread_local! {
static ON_RT_THREAD: Cell<bool> = Cell::new(false);
}
ON_RT_THREAD.with(|cell| cell.set(true));
let mut rt = runtime::Builder::new()
.threaded_scheduler()
.enable_all()
.bui... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 0e729aa341028c121b9c39fe552ed4309bae6b6a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0e729aa341028c121b9c39fe552ed4309bae6b6a/tokio/src/task/local.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/task/local.rs:15 | let mut rt = runtime::Builder::new()
.threaded_scheduler()
.build()
.unwrap();
LocalSet::new().block_on(&mut rt, async {
assert!(ON_RT_THREAD.with(|cell| cell.get()));
let handles = (0..128)
.map(|_| {
spawn_local(as... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 0e729aa341028c121b9c39fe552ed4309bae6b6a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0e729aa341028c121b9c39fe552ed4309bae6b6a/tokio/src/task/local.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/task/local.rs:16 | spawn_local(async {
assert!(ON_RT_THREAD.with(|cell| cell.get()));
})
.await
.unwrap();
})
.await
.unwrap();
})
.await
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 0e729aa341028c121b9c39fe552ed4309bae6b6a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0e729aa341028c121b9c39fe552ed4309bae6b6a/tokio/src/task/local.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/task/local.rs:17 | "hello world"
});
let join2 = task::spawn(async move {
assert!(
!ON_RT_THREAD.with(|cell| cell.get()),
"spawned task should be on a worker"
);
tx.send(()).expect("task shouldn't have ended yet");
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 0e729aa341028c121b9c39fe552ed4309bae6b6a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0e729aa341028c121b9c39fe552ed4309bae6b6a/tokio/src/task/local.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/task/local.rs:18 | started_rx.await.unwrap();
});
drop(local);
drop(rt);
}
#[test]
fn drop_cancels_remote_tasks() {
// This test reproduces issue #1885.
use std::sync::mpsc::RecvTimeoutError;
let (done_tx, done_rx) = std::sync::mpsc::channel();
let thread = std::thread... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 0e729aa341028c121b9c39fe552ed4309bae6b6a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0e729aa341028c121b9c39fe552ed4309bae6b6a/tokio/src/task/local.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/task/local.rs:19 | // thread. When the test thread finishes, it will send a message on a
// channel to this thread. We'll wait for that message with a fairly
// generous timeout, and if we don't recieve it, we assume the test
// thread has hung.
//
// Note that it should definitely complete in unde... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 0e729aa341028c121b9c39fe552ed4309bae6b6a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0e729aa341028c121b9c39fe552ed4309bae6b6a/tokio/src/task/local.rs | 721 | 744 |
tokio-rs/tokio:tokio/src/task/local.rs:3 | pub struct LocalSet {
scheduler: Rc<Scheduler>,
}
}
struct Scheduler {
/// List of all active tasks spawned onto this executor.
///
/// # Safety
///
/// Must only be accessed from the primary thread
tasks: UnsafeCell<task::OwnedList<Scheduler>>,
/// Local run local_queue.
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 07451f8b94a8b867696ddc1c6b546774fe1e06e4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/07451f8b94a8b867696ddc1c6b546774fe1e06e4/tokio/src/task/local.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/task/local.rs:4 | #[pin]
future: F,
}
}
thread_local! {
static CURRENT_TASK_SET: Cell<Option<NonNull<Scheduler>>> = Cell::new(None);
}
cfg_rt_util! {
/// 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 ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 07451f8b94a8b867696ddc1c6b546774fe1e06e4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/07451f8b94a8b867696ddc1c6b546774fe1e06e4/tokio/src/task/local.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/task/local.rs:5 | pub fn spawn_local<F>(future: F) -> JoinHandle<F::Output>
where
F: Future + 'static,
F::Output: 'static,
{
CURRENT_TASK_SET.with(|current| {
let current = current
.get()
.expect("`spawn_local` called from outside of a local::LocalSet!");
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 07451f8b94a8b867696ddc1c6b546774fe1e06e4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/07451f8b94a8b867696ddc1c6b546774fe1e06e4/tokio/src/task/local.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/task/local.rs:8 | /// ```
/// This, however, will not panic:
/// ```
/// use tokio::runtime::Runtime;
/// use tokio::task;
///
/// let mut rt = Runtime::new().unwrap();
/// let local = task::LocalSet::new();
/// local.block_on(&mut rt, async {
/// let join = task::spawn_local(async {
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 07451f8b94a8b867696ddc1c6b546774fe1e06e4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/07451f8b94a8b867696ddc1c6b546774fe1e06e4/tokio/src/task/local.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/task/local.rs:9 | type Output = F::Output;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.project();
let scheduler = this.scheduler;
let mut future = this.future;
scheduler.waker.register_by_ref(cx.waker());
if let Poll::Ready(output) = future.as_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 07451f8b94a8b867696ddc1c6b546774fe1e06e4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/07451f8b94a8b867696ddc1c6b546774fe1e06e4/tokio/src/task/local.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/task/local.rs:10 | if self.is_current() {
unsafe {
self.schedule_local(task);
}
} else {
self.remote_queue.lock().unwrap().push_back(task);
self.waker.wake();
}
}
}
impl Scheduler {
fn new() -> Self {
Self {
tasks: UnsafeCell::ne... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 07451f8b94a8b867696ddc1c6b546774fe1e06e4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/07451f8b94a8b867696ddc1c6b546774fe1e06e4/tokio/src/task/local.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/task/local.rs:11 | })
}
unsafe fn schedule_local(&self, task: Task<Self>) {
(*self.local_queue.get()).push_back(task);
}
fn is_current(&self) -> bool {
CURRENT_TASK_SET
.try_with(|current| {
current
.get()
.iter()
.an... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 07451f8b94a8b867696ddc1c6b546774fe1e06e4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/07451f8b94a8b867696ddc1c6b546774fe1e06e4/tokio/src/task/local.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/task/local.rs:12 | Err(_) => panic!("mutex poisoned"),
Ok(lock) => lock,
};
lock.pop_front()
}
fn tick(&self) {
assert!(self.is_current());
for _ in 0..MAX_TASKS_PER_TICK {
let tick = self.tick.get().wrapping_add(1);
self.tick.set(tick);
let task = m... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 07451f8b94a8b867696ddc1c6b546774fe1e06e4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/07451f8b94a8b867696ddc1c6b546774fe1e06e4/tokio/src/task/local.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/task/local.rs:13 | impl Drop for Scheduler {
fn drop(&mut self) {
// Drain all local tasks
while let Some(task) = self.next_local_task() {
task.shutdown();
}
// Release owned tasks
unsafe {
(*self.tasks.get()).shutdown();
}
self.drain_pending_drop();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 07451f8b94a8b867696ddc1c6b546774fe1e06e4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/07451f8b94a8b867696ddc1c6b546774fe1e06e4/tokio/src/task/local.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/task/local.rs:14 | static ON_RT_THREAD: Cell<bool> = Cell::new(false);
}
ON_RT_THREAD.with(|cell| cell.set(true));
let mut rt = runtime::Runtime::new().unwrap();
LocalSet::new().block_on(&mut rt, async {
assert!(ON_RT_THREAD.with(|cell| cell.get()));
spawn_local(async {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 07451f8b94a8b867696ddc1c6b546774fe1e06e4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/07451f8b94a8b867696ddc1c6b546774fe1e06e4/tokio/src/task/local.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/task/local.rs:15 | });
}
#[test]
// This will panic, since the thread that calls `block_on` cannot use
// in-place blocking inside of `block_on`.
#[should_panic]
fn local_threadpool_blocking_in_place() {
thread_local! {
static ON_RT_THREAD: Cell<bool> = Cell::new(false);
}
ON_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 07451f8b94a8b867696ddc1c6b546774fe1e06e4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/07451f8b94a8b867696ddc1c6b546774fe1e06e4/tokio/src/task/local.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/task/local.rs:16 | .enable_all()
.build()
.unwrap();
LocalSet::new().block_on(&mut rt, async {
assert!(ON_RT_THREAD.with(|cell| cell.get()));
let join = spawn_local(async move {
assert!(ON_RT_THREAD.with(|cell| cell.get()));
task::spawn_blocking(|| {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 07451f8b94a8b867696ddc1c6b546774fe1e06e4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/07451f8b94a8b867696ddc1c6b546774fe1e06e4/tokio/src/task/local.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/task/local.rs:17 | })
})
.collect::<Vec<_>>();
for joined in future::join_all(handles).await {
joined.unwrap();
}
})
}
#[test]
fn nested_spawn_is_local() {
thread_local! {
static ON_RT_THREAD: Cell<bool> = Cell::new(false);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 07451f8b94a8b867696ddc1c6b546774fe1e06e4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/07451f8b94a8b867696ddc1c6b546774fe1e06e4/tokio/src/task/local.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/task/local.rs:18 | })
.await
.unwrap();
})
}
#[test]
fn join_local_future_elsewhere() {
thread_local! {
static ON_RT_THREAD: Cell<bool> = Cell::new(false);
}
ON_RT_THREAD.with(|cell| cell.set(true));
let mut rt = runtime::Builder::new()
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 07451f8b94a8b867696ddc1c6b546774fe1e06e4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/07451f8b94a8b867696ddc1c6b546774fe1e06e4/tokio/src/task/local.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/task/local.rs:19 | join.await.expect("task should complete successfully");
println!("hello world task joined");
});
join2.await.unwrap()
});
}
#[test]
fn drop_cancels_tasks() {
// This test reproduces issue #1842
use crate::sync::oneshot;
use std::time::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 07451f8b94a8b867696ddc1c6b546774fe1e06e4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/07451f8b94a8b867696ddc1c6b546774fe1e06e4/tokio/src/task/local.rs | 721 | 756 |
tokio-rs/tokio:tokio/src/task/local.rs:8 | /// ```
/// This, however, will not panic:
/// ```
/// use tokio::runtime::Runtime;
/// use tokio::task;
///
/// let mut rt = Runtime::new().unwrap();
/// let local = task::LocalSet::new();
/// local.block_on(&mut rt, async {
/// let join = task::spawn_local(async {
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 8b60c5386a60be4dacffe71823350040e8ba90fd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8b60c5386a60be4dacffe71823350040e8ba90fd/tokio/src/task/local.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/task/local.rs:9 | impl<F: Future> Future for LocalFuture<F> {
type Output = F::Output;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.project();
let scheduler = this.scheduler;
let mut future = this.future;
scheduler.waker.register_by_ref(cx.waker());
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 8b60c5386a60be4dacffe71823350040e8ba90fd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8b60c5386a60be4dacffe71823350040e8ba90fd/tokio/src/task/local.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/task/local.rs:10 | fn schedule(&self, task: Task<Self>) {
if self.is_current() {
unsafe {
self.schedule_local(task);
}
} else {
self.remote_queue.lock().unwrap().push_back(task);
self.waker.wake();
}
}
}
impl Scheduler {
fn new() -> Self {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 8b60c5386a60be4dacffe71823350040e8ba90fd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8b60c5386a60be4dacffe71823350040e8ba90fd/tokio/src/task/local.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/task/local.rs:11 | f()
})
}
unsafe fn schedule_local(&self, task: Task<Self>) {
(*self.local_queue.get()).push_back(task);
}
fn is_current(&self) -> bool {
CURRENT_TASK_SET
.try_with(|current| {
current
.get()
.iter()
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 8b60c5386a60be4dacffe71823350040e8ba90fd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8b60c5386a60be4dacffe71823350040e8ba90fd/tokio/src/task/local.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/task/local.rs:12 | Err(_) if std::thread::panicking() => return None,
Err(_) => panic!("mutex poisoned"),
Ok(lock) => lock,
};
lock.pop_front()
}
fn tick(&self) {
assert!(self.is_current());
for _ in 0..MAX_TASKS_PER_TICK {
let tick = self.tick.get().wrapping_ad... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 8b60c5386a60be4dacffe71823350040e8ba90fd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8b60c5386a60be4dacffe71823350040e8ba90fd/tokio/src/task/local.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/task/local.rs:13 | }
impl Drop for Scheduler {
fn drop(&mut self) {
// Drain all local tasks
while let Some(task) = self.next_local_task() {
task.shutdown();
}
// Release owned tasks
unsafe {
(*self.tasks.get()).shutdown();
}
self.drain_pending_drop();... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 8b60c5386a60be4dacffe71823350040e8ba90fd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8b60c5386a60be4dacffe71823350040e8ba90fd/tokio/src/task/local.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/task/local.rs:14 | thread_local! {
static ON_RT_THREAD: Cell<bool> = Cell::new(false);
}
ON_RT_THREAD.with(|cell| cell.set(true));
let mut rt = runtime::Runtime::new().unwrap();
LocalSet::new().block_on(&mut rt, async {
assert!(ON_RT_THREAD.with(|cell| cell.get()));
sp... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 8b60c5386a60be4dacffe71823350040e8ba90fd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8b60c5386a60be4dacffe71823350040e8ba90fd/tokio/src/task/local.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/task/local.rs:15 | join.await.unwrap();
});
}
#[test]
// This will panic, since the thread that calls `block_on` cannot use
// in-place blocking inside of `block_on`.
#[should_panic]
fn local_threadpool_blocking_in_place() {
thread_local! {
static ON_RT_THREAD: Cell<bool> = Cell::new(f... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 8b60c5386a60be4dacffe71823350040e8ba90fd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8b60c5386a60be4dacffe71823350040e8ba90fd/tokio/src/task/local.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/task/local.rs:16 | .threaded_scheduler()
.enable_all()
.build()
.unwrap();
LocalSet::new().block_on(&mut rt, async {
assert!(ON_RT_THREAD.with(|cell| cell.get()));
let join = spawn_local(async move {
assert!(ON_RT_THREAD.with(|cell| cell.get()));
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 8b60c5386a60be4dacffe71823350040e8ba90fd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8b60c5386a60be4dacffe71823350040e8ba90fd/tokio/src/task/local.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/task/local.rs:17 | assert!(ON_RT_THREAD.with(|cell| cell.get()));
})
})
.collect::<Vec<_>>();
for joined in future::join_all(handles).await {
joined.unwrap();
}
})
}
#[test]
fn nested_spawn_is_local() {
thread_local! {... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 8b60c5386a60be4dacffe71823350040e8ba90fd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8b60c5386a60be4dacffe71823350040e8ba90fd/tokio/src/task/local.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/task/local.rs:18 | .unwrap();
})
.await
.unwrap();
})
}
#[test]
fn join_local_future_elsewhere() {
thread_local! {
static ON_RT_THREAD: Cell<bool> = Cell::new(false);
}
ON_RT_THREAD.with(|cell| cell.set(true));
let mut rt = runtime::Buil... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 8b60c5386a60be4dacffe71823350040e8ba90fd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8b60c5386a60be4dacffe71823350040e8ba90fd/tokio/src/task/local.rs | 681 | 740 |
tokio-rs/tokio:tokio/src/task/local.rs:3 | scheduler: Rc<Scheduler>,
}
}
struct Scheduler {
/// List of all active tasks spawned onto this executor.
///
/// # Safety
///
/// Must only be accessed from the primary thread
tasks: UnsafeCell<task::OwnedList<Scheduler>>,
/// Local run local_queue.
///
/// Tasks notified from ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 524e66314faacd9803792ce2a9dc13befd2ceeeb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/524e66314faacd9803792ce2a9dc13befd2ceeeb/tokio/src/task/local.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/task/local.rs:4 | future: F,
}
}
thread_local! {
static CURRENT_TASK_SET: Cell<Option<NonNull<Scheduler>>> = Cell::new(None);
}
cfg_rt_util! {
/// 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 ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 524e66314faacd9803792ce2a9dc13befd2ceeeb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/524e66314faacd9803792ce2a9dc13befd2ceeeb/tokio/src/task/local.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/task/local.rs:5 | where
F: Future + 'static,
F::Output: 'static,
{
CURRENT_TASK_SET.with(|current| {
let current = current
.get()
.expect("`spawn_local` called from outside of a local::LocalSet!");
unsafe {
let (task, handle) = task::join... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 524e66314faacd9803792ce2a9dc13befd2ceeeb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/524e66314faacd9803792ce2a9dc13befd2ceeeb/tokio/src/task/local.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/task/local.rs:8 | /// This, however, will not panic:
/// ```
/// use tokio::runtime::Runtime;
/// use tokio::task;
///
/// let mut rt = Runtime::new().unwrap();
/// let local = task::LocalSet::new();
/// local.block_on(&mut rt, async {
/// let join = task::spawn_local(async {
/// let block... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 524e66314faacd9803792ce2a9dc13befd2ceeeb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/524e66314faacd9803792ce2a9dc13befd2ceeeb/tokio/src/task/local.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/task/local.rs:9 | type Output = F::Output;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.project();
let scheduler = this.scheduler;
let mut future = this.future;
scheduler.waker.register_by_ref(cx.waker());
if let Poll::Ready(output) = future.as_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/src/task/local.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/task/local.rs:10 | unsafe {
self.schedule_local(task);
}
} else {
self.remote_queue.lock().unwrap().push_back(task);
self.waker.wake();
}
}
}
impl Scheduler {
fn new() -> Self {
Self {
tasks: UnsafeCell::new(task::OwnedList::new()),
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/src/task/local.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/task/local.rs:11 | }
unsafe fn schedule_local(&self, task: Task<Self>) {
(*self.local_queue.get()).push_back(task);
}
fn is_current(&self) -> bool {
CURRENT_TASK_SET
.try_with(|current| {
current
.get()
.iter()
.any(|curr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/src/task/local.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/task/local.rs:12 | Ok(lock) => lock,
};
lock.pop_front()
}
fn tick(&self) {
assert!(self.is_current());
for _ in 0..MAX_TASKS_PER_TICK {
let tick = self.tick.get().wrapping_add(1);
self.tick.set(tick);
let task = match self.next_task(tick) {
Some... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/src/task/local.rs | 441 | 500 |
tokio-rs/tokio:tokio/src/task/local.rs:13 | impl Drop for Scheduler {
fn drop(&mut self) {
// Drain all local tasks
while let Some(task) = self.next_local_task() {
task.shutdown();
}
// Release owned tasks
unsafe {
(*self.tasks.get()).shutdown();
}
self.drain_pending_drop();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/src/task/local.rs | 481 | 540 |
tokio-rs/tokio:tokio/src/task/local.rs:14 | }
ON_RT_THREAD.with(|cell| cell.set(true));
let mut rt = runtime::Runtime::new().unwrap();
LocalSet::new().block_on(&mut rt, async {
assert!(ON_RT_THREAD.with(|cell| cell.get()));
spawn_local(async {
assert!(ON_RT_THREAD.with(|cell| cell.get()));
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/src/task/local.rs | 521 | 580 |
tokio-rs/tokio:tokio/src/task/local.rs:15 | }
#[test]
// This will panic, since the thread that calls `block_on` cannot use
// in-place blocking inside of `block_on`.
#[should_panic]
fn local_threadpool_blocking_in_place() {
thread_local! {
static ON_RT_THREAD: Cell<bool> = Cell::new(false);
}
ON_RT_THREA... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/src/task/local.rs | 561 | 620 |
tokio-rs/tokio:tokio/src/task/local.rs:16 | .build()
.unwrap();
LocalSet::new().block_on(&mut rt, async {
assert!(ON_RT_THREAD.with(|cell| cell.get()));
let join = spawn_local(async move {
assert!(ON_RT_THREAD.with(|cell| cell.get()));
task::spawn_blocking(|| {
assert... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/src/task/local.rs | 601 | 660 |
tokio-rs/tokio:tokio/src/task/local.rs:17 | })
.collect::<Vec<_>>();
for joined in future::join_all(handles).await {
joined.unwrap();
}
})
}
#[test]
fn nested_spawn_is_local() {
thread_local! {
static ON_RT_THREAD: Cell<bool> = Cell::new(false);
}
ON... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/src/task/local.rs | 641 | 700 |
tokio-rs/tokio:tokio/src/task/local.rs:18 | .await
.unwrap();
})
}
#[test]
fn join_local_future_elsewhere() {
thread_local! {
static ON_RT_THREAD: Cell<bool> = Cell::new(false);
}
ON_RT_THREAD.with(|cell| cell.set(true));
let mut rt = runtime::Builder::new()
.threaded_sched... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/local.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/src/task/local.rs | 681 | 727 |
tokio-rs/tokio:tokio/src/task/mod.rs:6 | //! println!("spawned task done!")
//! });
//!
//! // Yield, allowing the newly-spawned task to execute first.
//! task::yield_now().await;
//! println!("main task done!");
//! }
//! # .await;
//! # }
//! ```
//!
//! [`task::spawn_blocking`]: crate::task::spawn_blocking
//! [`task::block_in_plac... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | bb6c3839ef0491310f40e4570b465bcc6b09ae95 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/bb6c3839ef0491310f40e4570b465bcc6b09ae95/tokio/src/task/mod.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/task/mod.rs:7 | mod list;
pub(crate) use self::list::OwnedList;
pub(crate) mod queue;
mod raw;
use self::raw::RawTask;
mod spawn;
pub use spawn::spawn;
mod stack;
pub(crate) use self::stack::TransferStack;
mod state;
use self::state::{Snapshot, State};
mod waker;
mod yield_now;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | bb6c3839ef0491310f40e4570b465bcc6b09ae95 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/bb6c3839ef0491310f40e4570b465bcc6b09ae95/tokio/src/task/mod.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/task/mod.rs:8 | /// An owned handle to the task, tracked by ref count
pub(crate) struct Task<S: 'static> {
raw: RawTask,
_p: PhantomData<S>,
}
unsafe impl<S: ScheduleSendOnly + 'static> Send for Task<S> {}
/// Task result sent back
pub(crate) type Result<T> = std::result::Result<T, JoinError>;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | bb6c3839ef0491310f40e4570b465bcc6b09ae95 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/bb6c3839ef0491310f40e4570b465bcc6b09ae95/tokio/src/task/mod.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/task/mod.rs:9 | S: ScheduleSendOnly,
{
let raw = RawTask::new_joinable::<_, S>(task);
let task = Task {
raw,
_p: PhantomData,
};
let join = JoinHandle::new(raw);
(task, join)
}
cfg_rt_util! {
/// Create a new `!Send` task with an associated join ha... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | bb6c3839ef0491310f40e4570b465bcc6b09ae95 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/bb6c3839ef0491310f40e4570b465bcc6b09ae95/tokio/src/task/mod.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/task/mod.rs:10 | }
pub(crate) fn header(&self) -> &Header {
self.raw.header()
}
pub(crate) fn into_raw(self) -> NonNull<Header> {
let raw = self.raw.into_raw();
mem::forget(self);
raw
}
}
impl<S: Schedule> Task<S> {
/// Returns `self` whe... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | bb6c3839ef0491310f40e4570b465bcc6b09ae95 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/bb6c3839ef0491310f40e4570b465bcc6b09ae95/tokio/src/task/mod.rs | 361 | 411 |
tokio-rs/tokio:tokio/src/task/mod.rs:11 | fn drop(&mut self) {
self.raw.drop_task();
}
}
impl<S> fmt::Debug for Task<S> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Task").finish()
}
}
} | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | bb6c3839ef0491310f40e4570b465bcc6b09ae95 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/bb6c3839ef0491310f40e4570b465bcc6b09ae95/tokio/src/task/mod.rs | 401 | 411 |
tokio-rs/tokio:tokio/src/task/mod.rs:6 | //! # .await;
//! # }
//! ```
//!
//! [`task::spawn_blocking`]: crate::task::spawn_blocking
//! [`task::block_in_place`]: crate::task::block_in_place
//! [rt-threaded]: ../runtime/index.html#threaded-scheduler
//! [`task::yield_now`]: crate::task::yield_now()
//! [`thread::yield_now`]: std::thread::yield_now
cfg_blocki... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | 619d730d610bbfd0a13285178d6bf3d89a29d6a3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/619d730d610bbfd0a13285178d6bf3d89a29d6a3/tokio/src/task/mod.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/task/mod.rs:7 | mod spawn;
pub use spawn::spawn;
mod stack;
pub(crate) use self::stack::TransferStack;
mod state;
use self::state::{Snapshot, State};
mod waker;
mod yield_now;
pub use yield_now::yield_now;
}
cfg_rt_util! {
mod local;
pub use local::{spawn_local, LocalSet};
mod task_loc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | 619d730d610bbfd0a13285178d6bf3d89a29d6a3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/619d730d610bbfd0a13285178d6bf3d89a29d6a3/tokio/src/task/mod.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/task/mod.rs:8 | unsafe impl<S: ScheduleSendOnly + 'static> Send for Task<S> {}
/// Task result sent back
pub(crate) type Result<T> = std::result::Result<T, JoinError>;
pub(crate) trait Schedule: Sized + 'static {
/// Bind a task to the executor.
///
/// Guaranteed to be called from the thread that... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | 619d730d610bbfd0a13285178d6bf3d89a29d6a3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/619d730d610bbfd0a13285178d6bf3d89a29d6a3/tokio/src/task/mod.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/task/mod.rs:9 | };
let join = JoinHandle::new(raw);
(task, join)
}
cfg_rt_util! {
/// Create a new `!Send` task with an associated join handle
pub(crate) fn joinable_local<T, S>(task: T) -> (Task<S>, JoinHandle<T::Output>)
where
T: Future + 'static,
S: Schedule... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | 619d730d610bbfd0a13285178d6bf3d89a29d6a3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/619d730d610bbfd0a13285178d6bf3d89a29d6a3/tokio/src/task/mod.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/task/mod.rs:10 | let raw = self.raw.into_raw();
mem::forget(self);
raw
}
}
impl<S: Schedule> Task<S> {
/// Returns `self` when the task needs to be immediately re-scheduled
pub(crate) fn run<F>(self, mut executor: F) -> Option<Self>
where
F: FnMut() -> Option<... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | 619d730d610bbfd0a13285178d6bf3d89a29d6a3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/619d730d610bbfd0a13285178d6bf3d89a29d6a3/tokio/src/task/mod.rs | 361 | 404 |
tokio-rs/tokio:tokio/src/task/mod.rs:6 | //! # .await;
//! # }
//! ```
//!
//! [`task::spawn_blocking`]: crate::task::spawn_blocking
//! [`task::block_in_place`]: crate::task::block_in_place
//! [rt-threaded]: ../runtime/index.html#threaded-scheduler
//! [`task::yield_now`]: crate::task::yield_now()
//! [`thread::yield_now`]: std::thread::yield_now
cfg_blocki... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | 0e729aa341028c121b9c39fe552ed4309bae6b6a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0e729aa341028c121b9c39fe552ed4309bae6b6a/tokio/src/task/mod.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/task/mod.rs:7 | mod spawn;
pub use spawn::spawn;
mod stack;
pub(crate) use self::stack::TransferStack;
mod state;
use self::state::{Snapshot, State};
mod waker;
mod yield_now;
pub use yield_now::yield_now;
}
cfg_rt_util! {
mod local;
pub use local::{spawn_local, LocalSet};
}
cfg_rt_core! {... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | 0e729aa341028c121b9c39fe552ed4309bae6b6a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0e729aa341028c121b9c39fe552ed4309bae6b6a/tokio/src/task/mod.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/task/mod.rs:8 | pub(crate) type Result<T> = std::result::Result<T, JoinError>;
pub(crate) trait Schedule: Sized + 'static {
/// Bind a task to the executor.
///
/// Guaranteed to be called from the thread that called `poll` on the task.
fn bind(&self, task: &Task<Self>);
/// The task has c... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | 0e729aa341028c121b9c39fe552ed4309bae6b6a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0e729aa341028c121b9c39fe552ed4309bae6b6a/tokio/src/task/mod.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/task/mod.rs:9 | (task, join)
}
cfg_rt_util! {
/// Create a new `!Send` task with an associated join handle
pub(crate) fn joinable_local<T, S>(task: T) -> (Task<S>, JoinHandle<T::Output>)
where
T: Future + 'static,
S: Schedule,
{
let raw = RawTask::new_joinabl... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | 0e729aa341028c121b9c39fe552ed4309bae6b6a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0e729aa341028c121b9c39fe552ed4309bae6b6a/tokio/src/task/mod.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/task/mod.rs:10 | }
}
impl<S: Schedule> Task<S> {
/// Returns `self` when the task needs to be immediately re-scheduled
pub(crate) fn run<F>(self, mut executor: F) -> Option<Self>
where
F: FnMut() -> Option<NonNull<S>>,
{
if unsafe {
self.raw
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | 0e729aa341028c121b9c39fe552ed4309bae6b6a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0e729aa341028c121b9c39fe552ed4309bae6b6a/tokio/src/task/mod.rs | 361 | 401 |
tokio-rs/tokio:tokio/src/task/mod.rs:6 | //! # .await;
//! # }
//! ```
//!
//! [`task::spawn_blocking`]: crate::task::spawn_blocking
//! [`task::block_in_place`]: crate::task::block_in_place
//! [rt-threaded]: ../runtime/index.html#threaded-scheduler
//! [`task::yield_now`]: crate::task::yield_now()
//! [`thread::yield_now`]: std::thread::yield_now
cfg_blocki... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | 6efe07c3fba8ef103dd2a03328e8b667371803b3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6efe07c3fba8ef103dd2a03328e8b667371803b3/tokio/src/task/mod.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/task/mod.rs:7 | pub use spawn::spawn;
mod stack;
pub(crate) use self::stack::TransferStack;
mod state;
use self::state::{Snapshot, State};
mod waker;
mod yield_now;
pub use yield_now::yield_now;
}
cfg_rt_util! {
mod local;
pub use local::{spawn_local, LocalSet};
}
cfg_rt_core! {
/// Unit t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | 6efe07c3fba8ef103dd2a03328e8b667371803b3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6efe07c3fba8ef103dd2a03328e8b667371803b3/tokio/src/task/mod.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/task/mod.rs:8 | pub(crate) trait Schedule: Sized + 'static {
/// Bind a task to the executor.
///
/// Guaranteed to be called from the thread that called `poll` on the task.
fn bind(&self, task: &Task<Self>);
/// The task has completed work and is ready to be released. The scheduler
///... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | 6efe07c3fba8ef103dd2a03328e8b667371803b3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6efe07c3fba8ef103dd2a03328e8b667371803b3/tokio/src/task/mod.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/task/mod.rs:9 | }
cfg_rt_util! {
/// Create a new `!Send` task with an associated join handle
pub(crate) fn joinable_local<T, S>(task: T) -> (Task<S>, JoinHandle<T::Output>)
where
T: Future + 'static,
S: Schedule,
{
let raw = RawTask::new_joinable_local::<_, S>(t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | 6efe07c3fba8ef103dd2a03328e8b667371803b3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6efe07c3fba8ef103dd2a03328e8b667371803b3/tokio/src/task/mod.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/task/mod.rs:10 | impl<S: Schedule> Task<S> {
/// Returns `self` when the task needs to be immediately re-scheduled
pub(crate) fn run<F>(self, mut executor: F) -> Option<Self>
where
F: FnMut() -> Option<NonNull<S>>,
{
if unsafe {
self.raw
.poll(&... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | 6efe07c3fba8ef103dd2a03328e8b667371803b3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6efe07c3fba8ef103dd2a03328e8b667371803b3/tokio/src/task/mod.rs | 361 | 399 |
tokio-rs/tokio:tokio/src/task/mod.rs:6 | //! # .await;
//! # }
//! ```
//!
//! [`task::spawn_blocking`]: crate::task::spawn_blocking
//! [`task::block_in_place`]: crate::task::block_in_place
//! [rt-threaded]: ../runtime/index.html#threaded-scheduler
//! [`task::yield_now`]: crate::task::yield_now()
//! [`thread::yield_now`]: std::thread::yield_now
cfg_blocki... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/src/task/mod.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/task/mod.rs:7 | pub(crate) use self::list::OwnedList;
mod raw;
use self::raw::RawTask;
cfg_rt_core! {
mod spawn;
pub use spawn::spawn;
}
mod stack;
pub(crate) use self::stack::TransferStack;
mod state;
use self::state::{Snapshot, State};
mod waker;
mod yield_now;
pub use yield_now::yield_now;
/// Unit tests
#[cfg(test)]... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/src/task/mod.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/task/mod.rs:8 | pub(crate) trait Schedule: Sized + 'static {
/// Bind a task to the executor.
///
/// Guaranteed to be called from the thread that called `poll` on the task.
fn bind(&self, task: &Task<Self>);
/// The task has completed work and is ready to be released. The scheduler
/// is free to drop it when... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/src/task/mod.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/task/mod.rs:9 | (task, join)
}
cfg_rt_util! {
/// Create a new `!Send` task with an associated join handle
pub(crate) fn joinable_local<T, S>(task: T) -> (Task<S>, JoinHandle<T::Output>)
where
T: Future + 'static,
S: Schedule,
{
let raw = RawTask::new_joinable_local::<_, S>(task);
let ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/src/task/mod.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/task/mod.rs:10 | }
impl<S: Schedule> Task<S> {
/// Returns `self` when the task needs to be immediately re-scheduled
pub(crate) fn run<F>(self, mut executor: F) -> Option<Self>
where
F: FnMut() -> Option<NonNull<S>>,
{
if unsafe {
self.raw
.poll(&mut || executor().map(|ptr| p... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/src/task/mod.rs | 361 | 399 |
tokio-rs/tokio:tokio/src/task/mod.rs:6 | //! # .await;
//! # }
//! ```
//!
//! [`task::spawn_blocking`]: crate::task::spawn_blocking
//! [`task::block_in_place`]: crate::task::block_in_place
//! [rt-threaded]: ../runtime/index.html#threaded-scheduler
//! [`task::yield_now`]: crate::task::yield_now()
//! [`thread::yield_now`]: std::thread::yield_now
cfg_blocki... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/task/mod.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/task/mod.rs:7 | cfg_rt_core! {
mod spawn;
pub use spawn::spawn;
}
mod stack;
pub(crate) use self::stack::TransferStack;
mod state;
use self::state::{Snapshot, State};
mod waker;
mod yield_now;
pub use yield_now::yield_now;
/// Unit tests
#[cfg(test)]
mod tests;
use std::future::Future;
use std::marker::PhantomData;
use s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/task/mod.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/src/task/mod.rs | 241 | 300 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.