MCPcopy Create free account
hub / github.com/NthTensor/Forte / poll

Method poll

src/scope.rs:700–846  ·  view source on GitHub ↗

Polls the future. # Safety `this` must be a pointer produced by `Arc::into_raw` on an `Arc `. This call takes ownership of exactly one strong reference count for that allocation, consuming it via `Arc::from_raw` internally. The caller must hold "ownership" of one such strong reference.

(this: NonNull<()>, worker: &Worker)

Source from the content-addressed store, hash-verified

698
699impl<'scope, Fut> SpawnScoped<'scope, FutureMarker> for Fut
700where
701 Fut: Future<Output = ()> + 'scope,
702{
703 #[inline]
704 unsafe fn spawn_scoped<'env, S: for<'w> Scheduler<'w>>(
705 self,
706 scope: &'scope Scope<'scope, 'env>,
707 scheduler: S,
708 ) {
709 let job = ScopeFutureJob::new(scope, scheduler, self);
710 Worker::with_current(|worker| job.schedule(worker));
711 }
712}
713
714// The following is a small async executor built specifically to execute futures
715// spawned onto scopes. It is one of the more complex (and unsafe) areas of
716// Forte's code. Please take care when making changes.
717
718/// This value is used for the state of future-jobs that are not currently being
719/// polled or queued onto the thread pool. They may switch to the WOKEN state at
720/// any time, after which they are queued.
721const READY: u32 = 0;
722
723/// This value is used for the state of future-jobs that have already been
724/// woken. Jobs in this state may be in one of the three following categories:
725///
726/// * A pending job that has been (or is about to be) pushed to the queue
727/// so that it can be polled.
728///
729/// * A pending job that is currently being polled (or has just finished) and
730/// which was *not* queued after it was woken, because it was woken while
731/// running.
732///
733/// * A job that was woken after it completed or panicked. These jobs will stay
734/// in the WOKEN state forever, and will never be queued or polled again.
735///
736/// When a WOKEN future-job is executed by a worker, it switches into the LOCKED
737/// state. When a job finished executing in the WOKEN state (indicating it was
738/// woken while executing), and has not been completed or panicked, it is
739/// queued, and remains in the WOKEN state.
740///
741/// Future-jobs should never move directly from WOKEN to READY.
742const WOKEN: u32 = 1;
743
744/// This value is used for the state of future-jobs that have not been woken and
745/// are either executing, completed, or have been canceled due to a panic. They
746/// may switch to the WOKEN state at any time, but are not queued to the pool
747/// when this happens (they are instead queued when the future is done being
748/// polled, assuming it has not panicked or been completed).
749///
750/// When a job finished executing and has not been WOKEN, it switches back to
751/// the READY state.
752const LOCKED: u32 = 2;
753
754/// This is a job that polls a future each time it is executed. The 'scope and
755/// 'env lifetimes are the same as the ones from scope (see [`Scope`] for a
756/// detailed explanation).
757///

Callers 1

block_onMethod · 0.80

Calls 5

halt_unwindingFunction · 0.85
getMethod · 0.80
store_panicMethod · 0.80
scheduleMethod · 0.45
wake_by_refMethod · 0.45

Tested by

no test coverage detected