id stringlengths 22 133 | text stringlengths 40 40.2k | arch stringclasses 1
value | syntax stringclasses 1
value | kind stringclasses 4
values | repo stringclasses 27
values | path stringlengths 5 116 | license stringclasses 6
values | commit stringlengths 40 40 | source_host stringclasses 1
value | category stringclasses 16
values | source_url stringlengths 85 196 | line_start int64 1 4.28k | line_end int64 4 4.31k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:9 | // The waker must be stored in the task struct.
let res = if snapshot.has_join_waker() {
// There already is a waker stored in the struct. If it matches
// the provided waker, then there is no further work to do.
// Otherwise, the waker must be swapped.
let will_w... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/runtime/task/harness.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:10 | true
}
fn set_join_waker(
header: &Header,
trailer: &Trailer,
waker: Waker,
snapshot: Snapshot,
) -> Result<Snapshot, Snapshot> {
assert!(snapshot.is_join_interested());
assert!(!snapshot.has_join_waker());
// Safety: Only the `JoinHandle` may set the `waker` field. When
// `JOIN_INTER... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/runtime/task/harness.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:11 | let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
stage.drop_future_or_output();
}));
if let Err(err) = res {
// Dropping the future panicked, complete the join
// handle with the panic to avoid dropping the panic
// on the ground.
JoinError::panic(err)
} el... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/runtime/task/harness.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:12 | res
}));
match res {
Ok(Poll::Pending) => match header.state.transition_to_idle() {
Ok(snapshot) => {
if snapshot.is_notified() {
PollFuture::Notified
} else {
PollFuture::None
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 8198ef38814c45f9dc02fcbf826225b5cf32a6bb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8198ef38814c45f9dc02fcbf826225b5cf32a6bb/tokio/src/runtime/task/harness.rs | 441 | 461 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:5 | self.header().id.as_ref()
}
/// Forcibly shutdown the task
///
/// Attempt to transition to `Running` in order to forcibly shutdown the
/// task. If the task is currently running or in a state of completion, then
/// there is nothing further to do. When the task completes running, it will
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | ced7992f6555d884cac452d177b094eb44a58a29 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ced7992f6555d884cac452d177b094eb44a58a29/tokio/src/runtime/task/harness.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:6 | if is_join_interested {
// Store the output. The future has already been dropped
//
// Safety: Mutual exclusion is obtained by having transitioned the task
// state -> Running
let stage = &self.core().stage;
stage.store_outp... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | ced7992f6555d884cac452d177b094eb44a58a29 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ced7992f6555d884cac452d177b094eb44a58a29/tokio/src/runtime/task/harness.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:3 | };
// The transition to `Running` done above ensures that a lock on the
// future has been obtained. This also ensures the `*mut T` pointer
// contains the future (as opposed to the output) and is initialized.
let waker_ref = waker_ref::<T, S>(self.header());
let cx = Context::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 0cefa85bfa8a0d03b7a50eceff798ffa64f0bef9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0cefa85bfa8a0d03b7a50eceff798ffa64f0bef9/tokio/src/runtime/task/harness.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:4 | // by a Waker on any arbitrary thread.
self.core().stage.drop_future_or_output();
}
// Drop the `JoinHandle` reference, possibly deallocating the task
self.drop_reference();
}
// ===== waker behavior =====
pub(super) fn wake_by_val(self) {
self.wake_by_ref();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 0cefa85bfa8a0d03b7a50eceff798ffa64f0bef9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0cefa85bfa8a0d03b7a50eceff798ffa64f0bef9/tokio/src/runtime/task/harness.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:5 | // The task is concurrently running. No further work needed.
return;
}
// By transitioning the lifecycle to `Running`, we have permission to
// drop the future.
let err = cancel_task(&self.core().stage);
self.complete(Err(err), true)
}
/// Remotely abort the... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 0cefa85bfa8a0d03b7a50eceff798ffa64f0bef9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0cefa85bfa8a0d03b7a50eceff798ffa64f0bef9/tokio/src/runtime/task/harness.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:6 | if self
.scheduler_view()
.transition_to_terminal(is_join_interested)
{
self.dealloc()
}
}
fn to_task(&self) -> Task<S> {
self.scheduler_view().to_task()
}
}
enum TransitionToRunning {
Ok(Snapshot),
DropReference,
}
struct SchedulerView<... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 0cefa85bfa8a0d03b7a50eceff798ffa64f0bef9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0cefa85bfa8a0d03b7a50eceff798ffa64f0bef9/tokio/src/runtime/task/harness.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:7 | false
};
mem::forget(me);
// This might deallocate
let snapshot = self
.header
.state
.transition_to_terminal(!is_join_interested, ref_dec);
snapshot.ref_count() == 0
}
fn transition_to_running(&self) -> TransitionToRunning {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 0cefa85bfa8a0d03b7a50eceff798ffa64f0bef9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0cefa85bfa8a0d03b7a50eceff798ffa64f0bef9/tokio/src/runtime/task/harness.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:8 | // the task's sate.
let snapshot = header.state.transition_to_complete();
if !snapshot.is_join_interested() {
// The `JoinHandle` is not interested in the output of this task. It
// is our responsibility to drop the output.
stage.drop_future_or_output();
} else if snapshot.has_join_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 0cefa85bfa8a0d03b7a50eceff798ffa64f0bef9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0cefa85bfa8a0d03b7a50eceff798ffa64f0bef9/tokio/src/runtime/task/harness.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:9 | //
// This requires two atomic operations, unsetting the bit and
// then resetting it. If the task transitions to complete
// concurrently to either one of those operations, then setting
// the join waker fails and we proceed to reading the task
// output.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 0cefa85bfa8a0d03b7a50eceff798ffa64f0bef9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0cefa85bfa8a0d03b7a50eceff798ffa64f0bef9/tokio/src/runtime/task/harness.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:10 | let res = header.state.set_join_waker();
// If the state could not be updated, then clear the join waker
if res.is_err() {
unsafe {
trailer.set_waker(None);
}
}
res
}
enum PollFuture<T> {
Complete(Result<T, JoinError>, bool),
DropReference,
Notified,
None,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 0cefa85bfa8a0d03b7a50eceff798ffa64f0bef9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0cefa85bfa8a0d03b7a50eceff798ffa64f0bef9/tokio/src/runtime/task/harness.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:11 | ) -> PollFuture<T::Output> {
if snapshot.is_cancelled() {
PollFuture::Complete(Err(cancel_task(core)), snapshot.is_join_interested())
} else {
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
struct Guard<'a, T: Future> {
core: &'a CoreStage<T>,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 0cefa85bfa8a0d03b7a50eceff798ffa64f0bef9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0cefa85bfa8a0d03b7a50eceff798ffa64f0bef9/tokio/src/runtime/task/harness.rs | 401 | 442 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:1 | use crate::future::Future;
use crate::runtime::task::core::{Cell, Core, CoreStage, Header, Scheduler, Trailer};
use crate::runtime::task::state::Snapshot;
use crate::runtime::task::waker::waker_ref;
use crate::runtime::task::{JoinError, Notified, Schedule, Task};
use std::mem;
use std::panic;
use std::ptr::NonNull;
us... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 2087f3e0ebb08d633d59c5f964b3901e68b3c038 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2087f3e0ebb08d633d59c5f964b3901e68b3c038/tokio/src/runtime/task/harness.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:2 | SchedulerView {
header: self.header(),
scheduler: &self.core().scheduler,
}
}
}
impl<T, S> Harness<T, S>
where
T: Future,
S: Schedule,
{
/// Polls the inner future.
///
/// All necessary state checks and transitions are performed.
///
/// Panics raised wh... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 2087f3e0ebb08d633d59c5f964b3901e68b3c038 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2087f3e0ebb08d633d59c5f964b3901e68b3c038/tokio/src/runtime/task/harness.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:3 | };
// The transition to `Running` done above ensures that a lock on the
// future has been obtained. This also ensures the `*mut T` pointer
// contains the future (as opposed to the output) and is initialized.
let waker_ref = waker_ref::<T, S>(self.header());
let cx = Context::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 2087f3e0ebb08d633d59c5f964b3901e68b3c038 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2087f3e0ebb08d633d59c5f964b3901e68b3c038/tokio/src/runtime/task/harness.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:4 | // task structure until the task is deallocated, it may be dropped
// by a Waker on any arbitrary thread.
self.core().stage.drop_future_or_output();
}
// Drop the `JoinHandle` reference, possibly deallocating the task
self.drop_reference();
}
// ===== waker beha... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 2087f3e0ebb08d633d59c5f964b3901e68b3c038 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2087f3e0ebb08d633d59c5f964b3901e68b3c038/tokio/src/runtime/task/harness.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:5 | if !self.header().state.transition_to_shutdown() {
// The task is concurrently running. No further work needed.
return;
}
// By transitioning the lifecycle to `Running`, we have permission to
// drop the future.
let err = cancel_task(&self.core().stage);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 2087f3e0ebb08d633d59c5f964b3901e68b3c038 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2087f3e0ebb08d633d59c5f964b3901e68b3c038/tokio/src/runtime/task/harness.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:6 | if self
.scheduler_view()
.transition_to_terminal(is_join_interested)
{
self.dealloc()
}
}
fn to_task(&self) -> Task<S> {
self.scheduler_view().to_task()
}
}
enum TransitionToRunning {
Ok(Snapshot),
DropReference,
}
struct SchedulerView<... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 2087f3e0ebb08d633d59c5f964b3901e68b3c038 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2087f3e0ebb08d633d59c5f964b3901e68b3c038/tokio/src/runtime/task/harness.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:7 | false
}
} else {
false
};
// This might deallocate
let snapshot = self
.header
.state
.transition_to_terminal(!is_join_interested, ref_dec);
snapshot.ref_count() == 0
}
fn transition_to_running(&self) -> Trans... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 2087f3e0ebb08d633d59c5f964b3901e68b3c038 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2087f3e0ebb08d633d59c5f964b3901e68b3c038/tokio/src/runtime/task/harness.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:8 | T: Future,
{
// Transition the task's lifecycle to `Complete` and get a snapshot of
// the task's sate.
let snapshot = header.state.transition_to_complete();
if !snapshot.is_join_interested() {
// The `JoinHandle` is not interested in the output of this task. It
// is our responsibility... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 2087f3e0ebb08d633d59c5f964b3901e68b3c038 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2087f3e0ebb08d633d59c5f964b3901e68b3c038/tokio/src/runtime/task/harness.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:9 | // Unset the `JOIN_WAKER` to gain mutable access to the `waker`
// field then update the field with the new join worker.
//
// This requires two atomic operations, unsetting the bit and
// then resetting it. If the task transitions to complete
// concurrently ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 2087f3e0ebb08d633d59c5f964b3901e68b3c038 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2087f3e0ebb08d633d59c5f964b3901e68b3c038/tokio/src/runtime/task/harness.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:10 | }
// Update the `JoinWaker` state accordingly
let res = header.state.set_join_waker();
// If the state could not be updated, then clear the join waker
if res.is_err() {
unsafe {
trailer.set_waker(None);
}
}
res
}
enum PollFuture<T> {
Complete(Result<T, JoinErr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 2087f3e0ebb08d633d59c5f964b3901e68b3c038 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2087f3e0ebb08d633d59c5f964b3901e68b3c038/tokio/src/runtime/task/harness.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:11 | core: &CoreStage<T>,
snapshot: Snapshot,
cx: Context<'_>,
) -> PollFuture<T::Output> {
if snapshot.is_cancelled() {
PollFuture::Complete(Err(cancel_task(core)), snapshot.is_join_interested())
} else {
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
struct Guard<'a,... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 2087f3e0ebb08d633d59c5f964b3901e68b3c038 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2087f3e0ebb08d633d59c5f964b3901e68b3c038/tokio/src/runtime/task/harness.rs | 401 | 445 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:6 | if self
.scheduler_view()
.transition_to_terminal(is_join_interested)
{
self.dealloc()
}
}
fn to_task(&self) -> Task<S> {
self.scheduler_view().to_task()
}
}
enum TransitionToRunning {
Ok(Snapshot),
DropReference,
}
struct SchedulerView<... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 7c4183a45d3548840104df87d9c8b81c1b19c006 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7c4183a45d3548840104df87d9c8b81c1b19c006/tokio/src/runtime/task/harness.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:7 | false
}
} else {
false
};
// This might deallocate
let snapshot = self
.header
.state
.transition_to_terminal(!is_join_interested, ref_dec);
snapshot.ref_count() == 0
}
fn transition_to_running(&self) -> Trans... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 7c4183a45d3548840104df87d9c8b81c1b19c006 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7c4183a45d3548840104df87d9c8b81c1b19c006/tokio/src/runtime/task/harness.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:8 | // The scheduler maintains ownership of the task and responds to
// `wake` calls.
//
// The task reference count has been incremented.
//
// Safety: Since we have unique access to the task so that we can
// safely call `bind_scheduler`.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 7c4183a45d3548840104df87d9c8b81c1b19c006 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7c4183a45d3548840104df87d9c8b81c1b19c006/tokio/src/runtime/task/harness.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:9 | if !snapshot.is_complete() {
// The waker must be stored in the task struct.
let res = if snapshot.has_join_waker() {
// There already is a waker stored in the struct. If it matches
// the provided waker, then there is no further work to do.
// Otherwise, the waker mu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 7c4183a45d3548840104df87d9c8b81c1b19c006 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7c4183a45d3548840104df87d9c8b81c1b19c006/tokio/src/runtime/task/harness.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:10 | }
true
}
fn set_join_waker(
header: &Header,
trailer: &Trailer,
waker: Waker,
snapshot: Snapshot,
) -> Result<Snapshot, Snapshot> {
assert!(snapshot.is_join_interested());
assert!(!snapshot.has_join_waker());
// Safety: Only the `JoinHandle` may set the `waker` field. When
// `JOIN... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 7c4183a45d3548840104df87d9c8b81c1b19c006 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7c4183a45d3548840104df87d9c8b81c1b19c006/tokio/src/runtime/task/harness.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:11 | // Drop the future from a panic guard.
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
stage.drop_future_or_output();
}));
if let Err(err) = res {
// Dropping the future panicked, complete the join
// handle with the panic to avoid dropping the panic
// on the gro... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 7c4183a45d3548840104df87d9c8b81c1b19c006 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7c4183a45d3548840104df87d9c8b81c1b19c006/tokio/src/runtime/task/harness.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:12 | mem::forget(guard);
res
}));
match res {
Ok(Poll::Pending) => match header.state.transition_to_idle() {
Ok(snapshot) => {
if snapshot.is_notified() {
PollFuture::Notified
} else {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 7c4183a45d3548840104df87d9c8b81c1b19c006 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7c4183a45d3548840104df87d9c8b81c1b19c006/tokio/src/runtime/task/harness.rs | 441 | 462 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:1 | use crate::runtime::task::core::{Cell, Core, CoreStage, Header, Scheduler, Trailer};
use crate::runtime::task::state::Snapshot;
use crate::runtime::task::waker::waker_ref;
use crate::runtime::task::{JoinError, Notified, Schedule, Task};
use std::future::Future;
use std::mem;
use std::panic;
use std::ptr::NonNull;
use ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | e3851089207f6617dfcc0c7a73013eb819a0bfe0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3851089207f6617dfcc0c7a73013eb819a0bfe0/tokio/src/runtime/task/harness.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:4 | // task structure until the task is deallocated, it may be dropped
// by a Waker on any arbitrary thread.
self.core().stage.drop_future_or_output();
}
// Drop the `JoinHandle` reference, possibly deallocating the task
self.drop_reference();
}
// ===== waker beha... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | e3851089207f6617dfcc0c7a73013eb819a0bfe0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3851089207f6617dfcc0c7a73013eb819a0bfe0/tokio/src/runtime/task/harness.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:5 | // By transitioning the lifcycle to `Running`, we have permission to
// drop the future.
let err = cancel_task(&self.core().stage);
self.complete(Err(err), true)
}
/// Remotely abort the task
///
/// This is similar to `shutdown` except that it asks the runtime to perform
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | e3851089207f6617dfcc0c7a73013eb819a0bfe0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3851089207f6617dfcc0c7a73013eb819a0bfe0/tokio/src/runtime/task/harness.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:6 | self.dealloc()
}
}
fn to_task(&self) -> Task<S> {
self.scheduler_view().to_task()
}
}
enum TransitionToRunning {
Ok(Snapshot),
DropReference,
}
struct SchedulerView<'a, S> {
header: &'a Header,
scheduler: &'a Scheduler<S>,
}
impl<'a, S> SchedulerView<'a, S>
where
S: S... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | e3851089207f6617dfcc0c7a73013eb819a0bfe0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3851089207f6617dfcc0c7a73013eb819a0bfe0/tokio/src/runtime/task/harness.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:7 | // This might deallocate
let snapshot = self
.header
.state
.transition_to_terminal(!is_join_interested, ref_dec);
snapshot.ref_count() == 0
}
fn transition_to_running(&self) -> TransitionToRunning {
// If this is the first time the task is polled, t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | e3851089207f6617dfcc0c7a73013eb819a0bfe0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3851089207f6617dfcc0c7a73013eb819a0bfe0/tokio/src/runtime/task/harness.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:8 | // Safety: Since we have unique access to the task so that we can
// safely call `bind_scheduler`.
self.scheduler.bind_scheduler(self.to_task());
}
TransitionToRunning::Ok(snapshot)
}
}
/// Transitions the task's lifecycle to `Complete`. Notifies the
/// `JoinHandle` if it s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | e3851089207f6617dfcc0c7a73013eb819a0bfe0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3851089207f6617dfcc0c7a73013eb819a0bfe0/tokio/src/runtime/task/harness.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:9 | // Otherwise, the waker must be swapped.
let will_wake = unsafe {
// Safety: when `JOIN_INTEREST` is set, only `JOIN_HANDLE`
// may mutate the `waker` field.
trailer.will_wake(waker)
};
if will_wake {
// The task is not... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | e3851089207f6617dfcc0c7a73013eb819a0bfe0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3851089207f6617dfcc0c7a73013eb819a0bfe0/tokio/src/runtime/task/harness.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:10 | header: &Header,
trailer: &Trailer,
waker: Waker,
snapshot: Snapshot,
) -> Result<Snapshot, Snapshot> {
assert!(snapshot.is_join_interested());
assert!(!snapshot.has_join_waker());
// Safety: Only the `JoinHandle` may set the `waker` field. When
// `JOIN_INTEREST` is **not** set, nothing el... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | e3851089207f6617dfcc0c7a73013eb819a0bfe0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3851089207f6617dfcc0c7a73013eb819a0bfe0/tokio/src/runtime/task/harness.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:11 | if let Err(err) = res {
// Dropping the future panicked, complete the join
// handle with the panic to avoid dropping the panic
// on the ground.
JoinError::panic(err)
} else {
JoinError::cancelled()
}
}
fn poll_future<T: Future>(
header: &Header,
core: &CoreStag... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | e3851089207f6617dfcc0c7a73013eb819a0bfe0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3851089207f6617dfcc0c7a73013eb819a0bfe0/tokio/src/runtime/task/harness.rs | 401 | 457 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:12 | Ok(Poll::Pending) => match header.state.transition_to_idle() {
Ok(snapshot) => {
if snapshot.is_notified() {
PollFuture::Notified
} else {
PollFuture::None
}
}
Err(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | e3851089207f6617dfcc0c7a73013eb819a0bfe0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e3851089207f6617dfcc0c7a73013eb819a0bfe0/tokio/src/runtime/task/harness.rs | 441 | 457 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:4 | // task structure until the task is deallocated, it may be dropped
// by a Waker on any arbitrary thread.
self.core().stage.drop_future_or_output();
}
// Drop the `JoinHandle` reference, possibly deallocating the task
self.drop_reference();
}
// ===== waker beha... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/task/harness.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:5 | if !self.header().state.transition_to_shutdown() {
// The task is concurrently running. No further work needed.
return;
}
// By transitioning the lifecycle to `Running`, we have permission to
// drop the future.
let err = cancel_task(&self.core().stage);
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/task/harness.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:6 | }
}
enum TransitionToRunning {
Ok(Snapshot),
DropReference,
}
struct SchedulerView<'a, S> {
header: &'a Header,
scheduler: &'a Scheduler<S>,
}
impl<'a, S> SchedulerView<'a, S>
where
S: Schedule,
{
fn to_task(&self) -> Task<S> {
// SAFETY The header is from the same struct containing t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/task/harness.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:7 | snapshot.ref_count() == 0
}
fn transition_to_running(&self) -> TransitionToRunning {
// If this is the first time the task is polled, the task will be bound
// to the scheduler, in which case the task ref count must be
// incremented.
let is_not_bound = !self.scheduler.is_bound(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/task/harness.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:8 | }
/// Transitions the task's lifecycle to `Complete`. Notifies the
/// `JoinHandle` if it still has interest in the completion.
fn transition_to_complete<T>(header: &Header, stage: &CoreStage<T>, trailer: &Trailer)
where
T: Future,
{
// Transition the task's lifecycle to `Complete` and get a snapshot of
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/task/harness.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:10 | assert!(!snapshot.has_join_waker());
// Safety: Only the `JoinHandle` may set the `waker` field. When
// `JOIN_INTEREST` is **not** set, nothing else will touch the field.
unsafe {
trailer.set_waker(Some(waker));
}
// Update the `JoinWaker` state accordingly
let res = header.state.set_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/task/harness.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:11 | JoinError::cancelled()
}
}
fn poll_future<T: Future>(
header: &Header,
core: &CoreStage<T>,
snapshot: Snapshot,
cx: Context<'_>,
) -> PollFuture<T::Output> {
if snapshot.is_cancelled() {
PollFuture::Complete(Err(JoinError::cancelled()), snapshot.is_join_interested())
} else {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/task/harness.rs | 401 | 451 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:12 | }
}
Err(_) => PollFuture::Complete(Err(cancel_task(core)), true),
},
Ok(Poll::Ready(ok)) => PollFuture::Complete(Ok(ok), snapshot.is_join_interested()),
Err(err) => {
PollFuture::Complete(Err(JoinError::panic(err)), snapshot.is_join_int... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 08ed41f339e345286f26bdbc6c67bf9f2975ed07 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/08ed41f339e345286f26bdbc6c67bf9f2975ed07/tokio/src/runtime/task/harness.rs | 441 | 451 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:4 | // task structure until the task is deallocated, it may be dropped
// by a Waker on any arbitrary thread.
self.core().stage.drop_future_or_output();
}
// Drop the `JoinHandle` reference, possibly deallocating the task
self.drop_reference();
}
// ===== waker beha... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | e7d74b3119178b9b86f7b547774b6b121de2239a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e7d74b3119178b9b86f7b547774b6b121de2239a/tokio/src/runtime/task/harness.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:5 | if !self.header().state.transition_to_shutdown() {
// The task is concurrently running. No further work needed.
return;
}
// By transitioning the lifcycle to `Running`, we have permission to
// drop the future.
let err = cancel_task(&self.core().stage);
s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | e7d74b3119178b9b86f7b547774b6b121de2239a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e7d74b3119178b9b86f7b547774b6b121de2239a/tokio/src/runtime/task/harness.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:4 | // task structure until the task is deallocated, it may be dropped
// by a Waker on any arbitrary thread.
self.core().stage.drop_future_or_output();
}
// Drop the `JoinHandle` reference, possibly deallocating the task
self.drop_reference();
}
// ===== waker beha... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 6f988728bb1b9156b78153461c8632e44cb21a21 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6f988728bb1b9156b78153461c8632e44cb21a21/tokio/src/runtime/task/harness.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:5 | // By transitioning the lifcycle to `Running`, we have permission to
// drop the future.
let err = cancel_task(&self.core().stage);
self.complete(Err(err), true)
}
// ====== internal ======
fn complete(self, output: super::Result<T::Output>, is_join_interested: bool) {
if i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 6f988728bb1b9156b78153461c8632e44cb21a21 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6f988728bb1b9156b78153461c8632e44cb21a21/tokio/src/runtime/task/harness.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:6 | DropReference,
}
struct SchedulerView<'a, S> {
header: &'a Header,
scheduler: &'a Scheduler<S>,
}
impl<'a, S> SchedulerView<'a, S>
where
S: Schedule,
{
fn to_task(&self) -> Task<S> {
// SAFETY The header is from the same struct containing the scheduler `S` so the cast is safe
unsafe {... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 6f988728bb1b9156b78153461c8632e44cb21a21 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6f988728bb1b9156b78153461c8632e44cb21a21/tokio/src/runtime/task/harness.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:7 | // If this is the first time the task is polled, the task will be bound
// to the scheduler, in which case the task ref count must be
// incremented.
let is_not_bound = !self.scheduler.is_bound();
// Transition the task to the running state.
//
// A failure to transition... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 6f988728bb1b9156b78153461c8632e44cb21a21 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6f988728bb1b9156b78153461c8632e44cb21a21/tokio/src/runtime/task/harness.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:8 | where
T: Future,
{
// Transition the task's lifecycle to `Complete` and get a snapshot of
// the task's sate.
let snapshot = header.state.transition_to_complete();
if !snapshot.is_join_interested() {
// The `JoinHandle` is not interested in the output of this task. It
// is our resp... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 6f988728bb1b9156b78153461c8632e44cb21a21 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6f988728bb1b9156b78153461c8632e44cb21a21/tokio/src/runtime/task/harness.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:9 | }
// Unset the `JOIN_WAKER` to gain mutable access to the `waker`
// field then update the field with the new join worker.
//
// This requires two atomic operations, unsetting the bit and
// then resetting it. If the task transitions to complete
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 6f988728bb1b9156b78153461c8632e44cb21a21 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6f988728bb1b9156b78153461c8632e44cb21a21/tokio/src/runtime/task/harness.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:10 | trailer.set_waker(Some(waker));
}
// Update the `JoinWaker` state accordingly
let res = header.state.set_join_waker();
// If the state could not be updated, then clear the join waker
if res.is_err() {
unsafe {
trailer.set_waker(None);
}
}
res
}
enum PollFuture... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 6f988728bb1b9156b78153461c8632e44cb21a21 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6f988728bb1b9156b78153461c8632e44cb21a21/tokio/src/runtime/task/harness.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:11 | header: &Header,
core: &CoreStage<T>,
snapshot: Snapshot,
cx: Context<'_>,
) -> PollFuture<T::Output> {
if snapshot.is_cancelled() {
PollFuture::Complete(Err(JoinError::cancelled()), snapshot.is_join_interested())
} else {
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 6f988728bb1b9156b78153461c8632e44cb21a21 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6f988728bb1b9156b78153461c8632e44cb21a21/tokio/src/runtime/task/harness.rs | 401 | 446 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:10 | trailer.set_waker(Some(waker));
}
// Update the `JoinWaker` state accordingly
let res = header.state.set_join_waker();
// If the state could not be updated, then clear the join waker
if res.is_err() {
unsafe {
trailer.set_waker(None);
}
}
res
}
enum PollFuture... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 204603b7de62e9c33b153a09c432c5d627830fb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/204603b7de62e9c33b153a09c432c5d627830fb8/tokio/src/runtime/task/harness.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:11 | header: &Header,
core: &CoreStage<T>,
snapshot: Snapshot,
cx: Context<'_>,
) -> PollFuture<T::Output> {
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
struct Guard<'a, T: Future> {
core: &'a CoreStage<T>,
}
impl<T: Future> Drop for Guard<'_, T> {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 204603b7de62e9c33b153a09c432c5d627830fb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/204603b7de62e9c33b153a09c432c5d627830fb8/tokio/src/runtime/task/harness.rs | 401 | 446 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:1 | use crate::runtime::task::core::{Cell, Core, Header, Trailer};
use crate::runtime::task::state::Snapshot;
use crate::runtime::task::{JoinError, Notified, Schedule, Task};
use std::future::Future;
use std::mem;
use std::panic;
use std::ptr::NonNull;
use std::task::{Poll, Waker};
/// Typed raw task handle
pub(super) st... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 13de30c53eb90a5453f1cecf47b188e254a293ac | github | async-runtime | https://github.com/tokio-rs/tokio/blob/13de30c53eb90a5453f1cecf47b188e254a293ac/tokio/src/runtime/task/harness.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:2 | where
T: Future,
S: Schedule,
{
/// Polls the inner future.
///
/// All necessary state checks and transitions are performed.
///
/// Panics raised while polling the future are handled.
pub(super) fn poll(self) {
// If this is the first time the task is polled, the task will be b... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 13de30c53eb90a5453f1cecf47b188e254a293ac | github | async-runtime | https://github.com/tokio-rs/tokio/blob/13de30c53eb90a5453f1cecf47b188e254a293ac/tokio/src/runtime/task/harness.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:3 | // safely call `bind_scheduler`.
self.core().bind_scheduler(self.to_task());
}
// The transition to `Running` done above ensures that a lock on the
// future has been obtained. This also ensures the `*mut T` pointer
// contains the future (as opposed to the output) and is in... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 13de30c53eb90a5453f1cecf47b188e254a293ac | github | async-runtime | https://github.com/tokio-rs/tokio/blob/13de30c53eb90a5453f1cecf47b188e254a293ac/tokio/src/runtime/task/harness.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:4 | match self.header().state.transition_to_idle() {
Ok(snapshot) => {
if snapshot.is_notified() {
// Signal yield
self.core().yield_now(Notified(self.to_task()));
// The ref-count was incremented... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 13de30c53eb90a5453f1cecf47b188e254a293ac | github | async-runtime | https://github.com/tokio-rs/tokio/blob/13de30c53eb90a5453f1cecf47b188e254a293ac/tokio/src/runtime/task/harness.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:5 | if !snapshot.is_complete() {
// The waker must be stored in the task struct.
let res = if snapshot.has_join_waker() {
// There already is a waker stored in the struct. If it matches
// the provided waker, then there is no further work to do.
// Oth... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 13de30c53eb90a5453f1cecf47b188e254a293ac | github | async-runtime | https://github.com/tokio-rs/tokio/blob/13de30c53eb90a5453f1cecf47b188e254a293ac/tokio/src/runtime/task/harness.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:6 | assert!(snapshot.is_complete());
}
}
}
*dst = Poll::Ready(self.core().take_output());
}
fn set_join_waker(&self, waker: Waker, snapshot: Snapshot) -> Result<Snapshot, Snapshot> {
assert!(snapshot.is_join_interested());
assert!(!snapshot.has_join_wake... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 13de30c53eb90a5453f1cecf47b188e254a293ac | github | async-runtime | https://github.com/tokio-rs/tokio/blob/13de30c53eb90a5453f1cecf47b188e254a293ac/tokio/src/runtime/task/harness.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:7 | // the task output may not be `Send` and as such must remain with
// the scheduler or `JoinHandle`. i.e. if the output remains in the
// task structure until the task is deallocated, it may be dropped
// by a Waker on any arbitrary thread.
self.core().drop_future_or_outpu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 13de30c53eb90a5453f1cecf47b188e254a293ac | github | async-runtime | https://github.com/tokio-rs/tokio/blob/13de30c53eb90a5453f1cecf47b188e254a293ac/tokio/src/runtime/task/harness.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:8 | }
// By transitioning the lifcycle to `Running`, we have permission to
// drop the future.
self.cancel_task();
}
// ====== internal ======
fn cancel_task(self) {
// Drop the future from a panic guard.
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 13de30c53eb90a5453f1cecf47b188e254a293ac | github | async-runtime | https://github.com/tokio-rs/tokio/blob/13de30c53eb90a5453f1cecf47b188e254a293ac/tokio/src/runtime/task/harness.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:9 | let ref_dec = if self.core().is_bound() {
if let Some(task) = self.core().release(self.to_task()) {
mem::forget(task);
true
} else {
false
}
} else {
false
};
// This might deallocate
let sna... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 13de30c53eb90a5453f1cecf47b188e254a293ac | github | async-runtime | https://github.com/tokio-rs/tokio/blob/13de30c53eb90a5453f1cecf47b188e254a293ac/tokio/src/runtime/task/harness.rs | 321 | 371 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:10 | fn wake_join(&self) {
self.trailer().waker.with(|ptr| match unsafe { &*ptr } {
Some(waker) => waker.wake_by_ref(),
None => panic!("waker missing"),
});
}
fn to_task(&self) -> Task<S> {
unsafe { Task::from_raw(self.header().into()) }
}
} | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 13de30c53eb90a5453f1cecf47b188e254a293ac | github | async-runtime | https://github.com/tokio-rs/tokio/blob/13de30c53eb90a5453f1cecf47b188e254a293ac/tokio/src/runtime/task/harness.rs | 361 | 371 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:3 | // safely call `bind_scheduler`.
self.core().bind_scheduler(self.to_task());
}
// The transition to `Running` done above ensures that a lock on the
// future has been obtained. This also ensures the `*mut T` pointer
// contains the future (as opposed to the output) and is in... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 2c53bebe56d584f1d6b710e9b39df6452d655a26 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2c53bebe56d584f1d6b710e9b39df6452d655a26/tokio/src/runtime/task/harness.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:4 | match self.header().state.transition_to_idle() {
Ok(snapshot) => {
if snapshot.is_notified() {
// Signal yield
self.core().yield_now(Notified(self.to_task()));
// The ref-count was incremented... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 2c53bebe56d584f1d6b710e9b39df6452d655a26 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2c53bebe56d584f1d6b710e9b39df6452d655a26/tokio/src/runtime/task/harness.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:7 | // the task output may not be `Send` and as such must remain with
// the scheduler or `JoinHandle`. i.e. if the output remains in the
// task structure until the task is deallocated, it may be dropped
// by a Waker on any arbitrary thread.
self.core().drop_future_or_outpu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 2c53bebe56d584f1d6b710e9b39df6452d655a26 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2c53bebe56d584f1d6b710e9b39df6452d655a26/tokio/src/runtime/task/harness.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:8 | }
// By transitioning the lifcycle to `Running`, we have permission to
// drop the future.
self.cancel_task();
}
// ====== internal ======
fn cancel_task(self) {
// Drop the future from a panic guard.
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 2c53bebe56d584f1d6b710e9b39df6452d655a26 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2c53bebe56d584f1d6b710e9b39df6452d655a26/tokio/src/runtime/task/harness.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:2 | where
T: Future,
S: Schedule,
{
/// Polls the inner future.
///
/// All necessary state checks and transitions are performed.
///
/// Panics raised while polling the future are handled.
pub(super) fn poll(self) {
// If this is the first time the task is polled, the task will be b... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 70ed3c7f0436079d798306820918d026819cb73d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70ed3c7f0436079d798306820918d026819cb73d/tokio/src/runtime/task/harness.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:3 | // safely call `bind_scheduler`.
self.core().bind_scheduler(self.to_task());
}
// The transition to `Running` done above ensures that a lock on the
// future has been obtained. This also ensures the `*mut T` pointer
// contains the future (as opposed to the output) and is in... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 70ed3c7f0436079d798306820918d026819cb73d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70ed3c7f0436079d798306820918d026819cb73d/tokio/src/runtime/task/harness.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:4 | match res {
Ok(Poll::Ready(out)) => {
self.complete(out, snapshot.is_join_interested());
}
Ok(Poll::Pending) => {
match self.header().state.transition_to_idle() {
Ok(snapshot) => {
if snapshot.is_notified() {... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 70ed3c7f0436079d798306820918d026819cb73d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70ed3c7f0436079d798306820918d026819cb73d/tokio/src/runtime/task/harness.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:5 | /// Read the task output into `dst`.
pub(super) fn try_read_output(self, dst: &mut Poll<super::Result<T::Output>>, waker: &Waker) {
// Load a snapshot of the current task state
let snapshot = self.header().state.load();
debug_assert!(snapshot.is_join_interested());
if !snapshot.is_... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 70ed3c7f0436079d798306820918d026819cb73d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70ed3c7f0436079d798306820918d026819cb73d/tokio/src/runtime/task/harness.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:6 | self.set_join_waker(waker.clone(), snapshot)
};
match res {
Ok(_) => return,
Err(snapshot) => {
assert!(snapshot.is_complete());
}
}
}
*dst = Poll::Ready(self.core().take_output());
}
fn se... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 70ed3c7f0436079d798306820918d026819cb73d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70ed3c7f0436079d798306820918d026819cb73d/tokio/src/runtime/task/harness.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:7 | pub(super) fn drop_join_handle_slow(self) {
// Try to unset `JOIN_INTEREST`. This must be done as a first step in
// case the task concurrently completed.
if self.header().state.unset_join_interested().is_err() {
// It is our responsibility to drop the output. This is critical as
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 70ed3c7f0436079d798306820918d026819cb73d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70ed3c7f0436079d798306820918d026819cb73d/tokio/src/runtime/task/harness.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:8 | /// there is nothing further to do. When the task completes running, it will
/// notice the `CANCELLED` bit and finalize the task.
pub(super) fn shutdown(self) {
if !self.header().state.transition_to_shutdown() {
// The task is concurrently running. No further work needed.
return... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 70ed3c7f0436079d798306820918d026819cb73d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70ed3c7f0436079d798306820918d026819cb73d/tokio/src/runtime/task/harness.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:9 | self.transition_to_complete();
}
// The task has completed execution and will no longer be scheduled.
//
// Attempts to batch a ref-dec with the state transition below.
let ref_dec = if self.core().is_bound() {
if let Some(task) = self.core().release(self.to_task()) ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 70ed3c7f0436079d798306820918d026819cb73d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70ed3c7f0436079d798306820918d026819cb73d/tokio/src/runtime/task/harness.rs | 321 | 377 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:10 | // Notify the join handle. The previous transition obtains the
// lock on the waker cell.
self.wake_join();
}
}
fn wake_join(&self) {
self.trailer().waker.with(|ptr| match unsafe { &*ptr } {
Some(waker) => waker.wake_by_ref(),
None => panic!("wake... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 70ed3c7f0436079d798306820918d026819cb73d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/70ed3c7f0436079d798306820918d026819cb73d/tokio/src/runtime/task/harness.rs | 361 | 377 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:1 | use crate::runtime::task::core::{Cell, Core, Header, Trailer};
use crate::runtime::task::state::Snapshot;
use crate::runtime::task::{JoinError, Notified, Schedule, Task};
use std::future::Future;
use std::mem;
use std::panic;
use std::ptr::NonNull;
use std::task::{Poll, Waker};
/// Typed raw task handle
pub(super) st... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 1cb1e291c10adf6b4e530cb1475b95ba10fa615f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/runtime/task/harness.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:2 | where
T: Future,
S: Schedule,
{
/// Polls the inner future.
///
/// All necessary state checks and transitions are performed.
///
/// Panics raised while polling the future are handled.
pub(super) fn poll(self) {
// If this is the first time the task is polled, the task will be b... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 1cb1e291c10adf6b4e530cb1475b95ba10fa615f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/runtime/task/harness.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:3 | // future has been obtained. This also ensures the `*mut T` pointer
// contains the future (as opposed to the output) and is initialized.
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
struct Guard<'a, T: Future, S: Schedule> {
core: &'a Core<T, S>,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 1cb1e291c10adf6b4e530cb1475b95ba10fa615f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/runtime/task/harness.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:4 | Ok(Poll::Pending) => {
match self.header().state.transition_to_idle() {
Ok(snapshot) => {
if snapshot.is_notified() {
// Signal yield
self.core().yield_now(Notified(self.to_task()));
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 1cb1e291c10adf6b4e530cb1475b95ba10fa615f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/runtime/task/harness.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:5 | debug_assert!(snapshot.is_join_interested());
if !snapshot.is_complete() {
// The waker must be stored in the task struct.
let res = if snapshot.has_join_waker() {
// There already is a waker stored in the struct. If it matches
// the provided waker, then... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 1cb1e291c10adf6b4e530cb1475b95ba10fa615f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/runtime/task/harness.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:6 | Err(snapshot) => {
assert!(snapshot.is_complete());
}
}
}
*dst = Poll::Ready(self.core().take_output());
}
fn set_join_waker(&self, waker: Waker, snapshot: Snapshot) -> Result<Snapshot, Snapshot> {
assert!(snapshot.is_join_interested());
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 1cb1e291c10adf6b4e530cb1475b95ba10fa615f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/runtime/task/harness.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:7 | // It is our responsibility to drop the output. This is critical as
// the task output may not be `Send` and as such must remain with
// the scheduler or `JoinHandle`. i.e. if the output remains in the
// task structure until the task is deallocated, it may be dropped
// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 1cb1e291c10adf6b4e530cb1475b95ba10fa615f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/runtime/task/harness.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:8 | return;
}
// By transitioning the lifcycle to `Running`, we have permission to
// drop the future.
self.cancel_task();
}
// ====== internal ======
fn cancel_task(self) {
// Drop the future from a panic guard.
let res = panic::catch_unwind(panic::AssertUnwin... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 1cb1e291c10adf6b4e530cb1475b95ba10fa615f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/runtime/task/harness.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:9 | // Attempts to batch a ref-dec with the state transition below.
let ref_dec = if self.core().is_bound() {
if let Some(task) = self.core().release(self.to_task()) {
mem::forget(task);
true
} else {
false
}
} else {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | 1cb1e291c10adf6b4e530cb1475b95ba10fa615f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/1cb1e291c10adf6b4e530cb1475b95ba10fa615f/tokio/src/runtime/task/harness.rs | 321 | 372 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:3 | // future has been obtained. This also ensures the `*mut T` pointer
// contains the future (as opposed to the output) and is initialized.
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
struct Guard<'a, T: Future, S: Schedule> {
core: &'a Core<T, S>,
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | a78b1c65ccfb9692ca5d3ed8ddde934f40091d83 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a78b1c65ccfb9692ca5d3ed8ddde934f40091d83/tokio/src/runtime/task/harness.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:4 | Ok(Poll::Pending) => {
match self.header().state.transition_to_idle() {
Ok(snapshot) => {
if snapshot.is_notified() {
// Signal yield
self.core().yield_now(Notified(self.to_task()));
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | a78b1c65ccfb9692ca5d3ed8ddde934f40091d83 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a78b1c65ccfb9692ca5d3ed8ddde934f40091d83/tokio/src/runtime/task/harness.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:5 | // The waker must be stored in the task struct.
let res = if snapshot.has_join_waker() {
// There already is a waker stored in the struct. If it matches
// the provided waker, then there is no further work to do.
// Otherwise, the waker must be swapped.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | a78b1c65ccfb9692ca5d3ed8ddde934f40091d83 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a78b1c65ccfb9692ca5d3ed8ddde934f40091d83/tokio/src/runtime/task/harness.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:6 | }
}
*dst = Poll::Ready(self.core().take_output());
}
fn set_join_waker(&self, waker: Waker, snapshot: Snapshot) -> Result<Snapshot, Snapshot> {
assert!(snapshot.is_join_interested());
assert!(!snapshot.has_join_waker());
// Safety: Only the `JoinHandle` may set the `wa... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | a78b1c65ccfb9692ca5d3ed8ddde934f40091d83 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a78b1c65ccfb9692ca5d3ed8ddde934f40091d83/tokio/src/runtime/task/harness.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/runtime/task/harness.rs:7 | // task structure until the task is deallocated, it may be dropped
// by a Waker on any arbitrary thread.
self.core().drop_future_or_output();
}
// Drop the `JoinHandle` reference, possibly deallocating the task
self.drop_reference();
}
// ===== waker behavior =... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/runtime/task/harness.rs | MIT | a78b1c65ccfb9692ca5d3ed8ddde934f40091d83 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a78b1c65ccfb9692ca5d3ed8ddde934f40091d83/tokio/src/runtime/task/harness.rs | 241 | 300 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.