StripedLock
class StripedLock
Coordinate short key-scoped critical sections across Swoole workers.
The locks must be constructed before the server forks so every worker inherits references to the same shared atomics. Every multi-stripe path acquires stripes in ascending index order and releases them in reverse so selected-stripe and all-stripe callers cannot deadlock each other.
Constants
| protected STRIPE_COUNT |
|
| protected SPINS_BEFORE_BACKOFF |
|
| protected ACQUIRE_TIMEOUT_NANOSECONDS |
|
Properties
| protected Atomic> | $locks |
Methods
Create a new striped lock.
Run the callback while holding the stripe for the given key.
Run the callback while holding the stripes for the given keys.
Run the callback while holding every stripe.
Run the callback while holding the selected stripes in their supplied order.
Get the stripe for a key.
Get the stripe index for a key.
Acquire a stripe.
Release a stripe.
Details
at line 36
__construct()
Create a new striped lock.
at line 51
mixed
withLock(string $key, callable $callback)
Run the callback while holding the stripe for the given key.
at line 71
mixed
withLocks(array $keys, callable $callback)
Run the callback while holding the stripes for the given keys.
at line 98
mixed
withAllLocks(callable $callback)
Run the callback while holding every stripe.
at line 111
protected mixed
withSelectedLocks(array $locks, callable $callback)
Run the callback while holding the selected stripes in their supplied order.
at line 132
protected Atomic
lockFor(string $key)
Get the stripe for a key.
at line 140
protected int
lockIndexFor(string $key)
Get the stripe index for a key.
at line 148
protected void
acquire(Atomic $lock)
Acquire a stripe.
at line 172
protected void
release(Atomic $lock)
Release a stripe.