class SwooleTableState

Coordinates multi-step Swoole table row mutations across workers.

Swoole Table does not currently provide full-row compare-and-swap, set-if-absent, or delete-if-current primitives, so cache operations that need atomic read-check-write behavior use striped shared Atomics around tiny critical sections.

Constants

protected STRIPE_COUNT

protected SPINS_BEFORE_BACKOFF

protected LOCK_ACQUIRE_TIMEOUT_NANOSECONDS

Properties

protected Atomic> $rowLocks

Striped locks for row lifecycle operations.

Methods

__construct(SwooleTable $table, int $hashSeed = 0)

Create a new Swoole table state instance.

table()

Get the Swoole table.

int
hashSeed()

Get the hash seed.

mixed
withRowLock(string $key, callable $callback)

Run the callback while holding the row lock for the given table key.

mixed
withAllRowLocks(callable $callback)

Run the callback while holding every row-lock stripe.

Atomic
lockFor(string $key)

Get the striped lock for a table key.

void
acquire(Atomic $lock)

Acquire a striped lock.

void
release(Atomic $lock)

Release a striped lock.

Details

at line 40
__construct(SwooleTable $table, int $hashSeed = 0)

Create a new Swoole table state instance.

Parameters

SwooleTable $table
int $hashSeed

at line 55
SwooleTable table()

Get the Swoole table.

Return Value

SwooleTable

at line 63
int hashSeed()

Get the hash seed.

Return Value

int

at line 75
mixed withRowLock(string $key, callable $callback)

Run the callback while holding the row lock for the given table key.

Parameters

string $key
callable $callback

Return Value

mixed

at line 94
mixed withAllRowLocks(callable $callback)

Run the callback while holding every row-lock stripe.

Parameters

callable $callback

Return Value

mixed

at line 115
protected Atomic lockFor(string $key)

Get the striped lock for a table key.

Parameters

string $key

Return Value

Atomic

at line 123
protected void acquire(Atomic $lock)

Acquire a striped lock.

Parameters

Atomic $lock

Return Value

void

at line 147
protected void release(Atomic $lock)

Release a striped lock.

Parameters

Atomic $lock

Return Value

void