pub struct Futex { /* private fields */ }
Expand description

A primitive for creating userspace synchronization tools.

SYNOPSIS

A futex is a Fast Userspace muTEX. It is a low level synchronization primitive which is a building block for higher level APIs such as pthread_mutex_t and pthread_cond_t. Futexes are designed to not enter the kernel or allocate kernel resources in the uncontested case.

Implementations

Create a new Futex.

The parameter value is the reference to an userspace AtomicI32. This reference is the information used in kernel to track what futex given threads are waiting on. The kernel does not currently modify the value of *value. It is up to userspace code to correctly atomically modify this value across threads in order to build mutexes and so on.

Wait on a futex.

This atomically verifies that value_ptr still contains the value current_value and sleeps until the futex is made available by a call to wake.

See wait_with_owner for advanced usage and more details.

Wake some number of threads waiting on a futex.

It wakes at most wake_count of the waiters that are waiting on this futex. Return the number of waiters that were woken up.

Ownership

The owner of the futex is set to nothing, regardless of the wake count.

Get the owner of the futex.

Wait on a futex.

This atomically verifies that value_ptr still contains the value current_value and sleeps until the futex is made available by a call to wake.

SPURIOUS WAKEUPS

This implementation currently does not generate spurious wakeups.

Ownership

A successful call results in the owner of the futex being set to the thread referenced by the new_owner, or to nothing if it is None.

Errors
  • INVALID_ARGS: One of the following is true
    • new_owner is currently a member of the waiters for this.
    • new_owner has not been started yet.
  • BAD_STATE: current_value does not match the value at value_ptr.
  • TIMED_OUT: The thread was not woken before deadline passed.

Wake exactly one thread from the futex wait queue.

If there is at least one thread to wake, the owner of the futex will be set to the thread which was woken. Otherwise, the futex will have no owner.

Ownership

If there is at least one thread to wake, the owner of the futex will be set to the thread which was woken. Otherwise, the futex will have no owner.

Requeuing is a generalization of waking.

First, verifies that the value in current_value matches the value of the futex, and if not reports ZxError::BAD_STATE. After waking wake_count threads, requeue_count threads are moved from the original futex’s wait queue to the wait queue corresponding to another requeue_futex.

This requeueing behavior may be used to avoid thundering herds on wake.

Ownership

The owner of this futex is set to nothing, regardless of the wake count. The owner of the requeue_futex is set to the thread new_requeue_owner.

Trait Implementations

Formats the value using the given formatter. Read more

Get object’s KoID.

Get the name of the type of the kernel object.

Get object’s name.

Set object’s name.

Get the signal status.

Assert signal.

Deassert signal.

Change signal status: first clear then set indicated bits. Read more

Add callback for signal status changes. Read more

Attempt to find a child of the object with given KoID. Read more

Attempt to get the object’s peer. Read more

If the object is related to another (such as the other end of a channel, or the parent of a job), returns the KoID of that object, otherwise returns zero. Read more

Get object’s allowed signals.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Casts the value.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Casts the value.

Casts the value.

Casts the value.

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s. Read more

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Casts the value.

Casts the value.

Casts the value.

Casts the value.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Casts the value.

Casts the value.

Casts the value.

Casts the value.