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:
Spinlock
: a synchronous [mutual exclusion] spinlock, which implements theblocking::RawMutex
andblocking::ScopedRawMutex
traits.RwSpinlock
: a synchronous [reader-writer] spinlock, which implements theblocking::RawRwLock
trait.InitOnce
: a cell storing aMaybeUninit
value which must be manually initialized prior to use.Lazy
: anInitOnce
cell coupled with an initializer function. TheLazy
cell ensures the initializer is called to initialize the value the first time it is accessed.
Modules
- Cells storing a value which must be initialized prior to use.