pub struct Task { /* private fields */ }Implementations§
Source§impl Task
impl Task
pub fn global_id(&self) -> u32
pub fn leaf_idx(&self) -> u16
pub fn signal_idx(&self) -> u8
pub fn signal_bit(&self) -> u8
pub fn stats(&self) -> TaskStats
pub fn set_cpu_time_tracking(&self, enabled: bool)
pub fn slot(&self) -> Option<NonNull<TaskSlot>>
pub fn clear_slot(&self)
pub fn state(&self) -> &AtomicU8
Sourcepub fn schedule(&self)
pub fn schedule(&self)
Attempts to schedule this queue for execution (IDLE -> SCHEDULED transition).
Called by producers after enqueuing items to notify the executor. Uses atomic operations to ensure only one successful schedule per work batch.
§Algorithm
- Fast check: If already SCHEDULED, return false immediately (idempotent)
- Atomic set:
fetch_or(SCHEDULED)to set the SCHEDULED flag - State check: If previous state was IDLE (neither SCHEDULED nor EXECUTING):
- Set bit in signal word via
signal.set(bit_index) - If signal transitioned from empty, update summary via
waker.mark_active() - Return true (successful schedule)
- Set bit in signal word via
- Otherwise: Return false (already scheduled or executing)
§Returns
true: Successfully transitioned from IDLE to SCHEDULED (work will be processed)false: Already scheduled/executing, or concurrent schedule won (idempotent)
§Concurrent Behavior
- Multiple producers: Only the first
schedule()succeeds (returns true) - During EXECUTING: Sets SCHEDULED flag, which
finish()will detect and reschedule
§Memory Ordering
- Initial load:
Acquire(see latest state) fetch_or:Release(publish enqueued items to executor)
§Performance
- Already scheduled: ~2-3 ns (fast path, single atomic load)
- Successful schedule: ~10-20 ns (fetch_or + signal update + potential summary update)
§Example
ⓘ
// Producer 1
queue.try_push(item)?;
if gate.schedule() {
println!("Successfully scheduled"); // First producer
}
// Producer 2 (concurrent)
queue.try_push(another_item)?;
if !gate.schedule() {
println!("Already scheduled"); // Idempotent, no action needed
}pub fn is_yielded(&self) -> bool
pub unsafe fn waker_yield(&self) -> Waker
pub unsafe fn poll_future(&self, cx: &mut Context<'_>) -> Option<Poll<()>>
pub fn attach_future(&self, future_ptr: *mut ()) -> Result<(), *mut ()>
pub fn take_future(&self) -> Option<*mut ()>
pub unsafe fn reset( &mut self, global_id: u32, leaf_idx: u16, signal_idx: u8, signal_bit: u8, signal_ptr: *const TaskSignal, slot_ptr: *mut TaskSlot, )
Sourcepub fn has_pinned_generator(&self) -> bool
pub fn has_pinned_generator(&self) -> bool
Check if this task has a pinned generator
Sourcepub unsafe fn get_pinned_generator<'a>(
&self,
) -> Option<&'a mut Box<dyn Iterator<Item = usize> + 'static>>
pub unsafe fn get_pinned_generator<'a>( &self, ) -> Option<&'a mut Box<dyn Iterator<Item = usize> + 'static>>
Get the pinned generator for this task (if any) Safety: Only call from the worker thread that owns this task
Sourcepub unsafe fn pin_generator(
&self,
generator_box: Box<dyn Iterator<Item = usize> + 'static>,
mode: GeneratorRunMode,
)
pub unsafe fn pin_generator( &self, generator_box: Box<dyn Iterator<Item = usize> + 'static>, mode: GeneratorRunMode, )
Pin a generator to this task Safety: Only call from the worker thread that owns this task
Sourcepub fn generator_run_mode(&self) -> GeneratorRunMode
pub fn generator_run_mode(&self) -> GeneratorRunMode
Get the generator run mode
Sourcepub unsafe fn set_generator_run_mode(&self, mode: GeneratorRunMode)
pub unsafe fn set_generator_run_mode(&self, mode: GeneratorRunMode)
Set the generator run mode Safety: Only call from the worker thread that owns this task
Trait Implementations§
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more