Struct lean_sys::lean_task

source ·
#[repr(C)]
pub struct lean_task { pub m_header: lean_object, pub m_value: u64, pub m_imp: *mut lean_task_imp, }
Expand description

Object of type Task _. The lifetime of a lean_task object can be represented as a state machine with atomic state transitions.

In the following, condition describes a predicate uniquely identifying a state.

creation:

  • Task.spawn ==> Queued
  • Task.map/bind ==> Waiting
  • Task.pure ==> Finished
  • Promise.new ==> Promised

states:

  • Queued
    • condition: in task_manager::m_queues && m_imp != nullptr && !m_imp->m_deleted
    • invariant: m_value == nullptr
    • transition: RC becomes 0 ==> Deactivated (deactivate_task lock)
    • transition: dequeued by worker thread ==> Running (spawn_worker lock)
  • Waiting
    • condition: reachable from task via m_head_dep->m_next_dep->... && !m_imp->m_deleted
    • invariant: m_imp != nullptr && m_value == nullptr
    • invariant: task dependency is Queued/Waiting/Running
      • It cannot become Deactivated because this task should be holding an owned reference to it
    • transition: RC becomes 0 ==> Deactivated (deactivate_task lock)
    • transition: task dependency Finished ==> Queued (handle_finished under spawn_worker lock)
  • Promised
    • condition: obtained as result from promise
    • invariant: m_imp != nullptr && m_value == nullptr
    • transition: promise resolved ==> Finished (resolve_core under spawn_worker lock)
    • transition: RC becomes 0 ==> Deactivated (deactivate_task lock)
  • Running
    • condition: m_imp != nullptr && m_imp->m_closure == nullptr
      • The worker takes ownership of the closure when running it
    • invariant: m_value == nullptr
    • transition: RC becomes 0 ==> Deactivated (deactivate_task lock)
    • transition: finished execution ==> Finished (spawn_worker lock)
  • Deactivated
    • condition: m_imp != nullptr && m_imp->m_deleted
    • invariant: RC == 0
    • invariant: m_imp->m_closure == nullptr && m_imp->m_head_dep == nullptr (both freed by deactivate_task_core)
      • Note that all dependent tasks must have already been Deactivated by the converse of the second Waiting invariant
    • invariant: m_value == nullptr
    • transition: dequeued by worker thread ==> freed
    • transition: finished execution ==> freed
    • transition: task dependency Finished ==> freed
    • We must keep the task object alive until one of these transitions because in either case, we have live (internal, unowned) references to the task up to that point
    • transition: task dependency Deactivated ==> freed
  • Finished
    • condition: m_value != nullptr
    • invariant: m_imp == nullptr
    • transition: RC becomes 0 ==> freed (deactivate_task lock)

Fields§

§m_header: lean_object§m_value: u64§m_imp: *mut lean_task_imp

Trait Implementations§

source§

impl Clone for lean_task

source§

fn clone(&self) -> lean_task

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for lean_task

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Copy for lean_task

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.