Expand description
Synchronization primitives over shared memory.
This module provides an alternative implementation for the ngx_atomic_t
type,
ngx_atomic_*
/ngx_rwlock_*
family of functions and related usage patterns from nginx.
<ngx_atomic.h>
contains a wide variety of implementation variants for different platforms and
build configurations. It’s not feasible to properly expose all of these to the Rust code, and we
are not going to. The implementation here uses similar logic on the foundation of the
core::sync::atomic types and is intentionally not interoperable with the nginx atomics.
Thus, it’s only suitable for use for new shared memory structures instead of, for example,
interacting with the upstream zones.
One potential pitfall here is that atomics in Rust are specified in terms of threads, and we use the types in this module for interprocess synchronization. This should not be an issue though, as Rust refers to the C/C++11 memory model for atomics, and there’s a following note in [atomics.lockfree]:
[Note: Operations that are lock-free should also be address-free. That is, atomic operations on the same memory location via two different addresses will communicate atomically. The implementation should not depend on any per-process state. This restriction enables communication via memory that is mapped into a process more than once and by memory that is shared between two processes. — end note]
In practice, this recommendation is applied in all the implementations that matter to us.
Structs§
- RawSpinlock
- Raw lock type.
Type Aliases§
- RwLock
- Reader-writer lock over an atomic variable, based on the nginx rwlock implementation.
- RwLock
Read Guard - RAII structure used to release the shared read access of a lock when dropped.
- RwLock
Write Guard - RAII structure used to release the exclusive write access of a lock when dropped.