Module maitake::sync::spin

source ·
Expand description

Synchronous spinning-based synchronization primitives.

The synchronization primitives in maitake-sync are asynchronous. They are designed to be used with core::task and core::future, and when it is necessary to wait for another task to complete some work for the current task to proceed, maitake’s synchronization primitives wait by yielding to the asynchronous task scheduler to allow another task to proceed.

This module, on the other hand, provides synchronous (or blocking) synchronization primitives. Rather than yielding to the runtime, these synchronization primitives will block the current CPU core (or thread, if running in an environment with threads) until they are woken by other cores. This is performed by spinning: issuing yield or pause instructions in a loop until some value changes. These synchronization primitives are, in some cases, necessary to implement the async synchronization primitives that form maitake-sync’s core APIs. They are also exposed publicly so they can be used in other projects, when a spinlock-based synchronization primitive is needed.

This module provides the following APIs:

Modules

  • Cells storing a value which must be initialized prior to use.

Structs

  • A cell which may be initialized a single time after it is created.
  • A cell which will be lazily initialized by the provided function the first time it is accessed.
  • A spinlock-based RawRwLock implementation.
  • A spinlock-based RawMutex implementation.