This is automatic generated document for things in Swow\Futex class

Class Futex

A 32-bit futex in shared memory.

wait() blocks the whole OS thread, not only the current coroutine. Use it only in a worker thread that runs one coroutine. An anonymous futex is visible to threads of this process and to a forked child. A named futex is visible to another process that attaches the same name. setValue() publishes the value with release order. getValue() reads it with acquire order. add(), compareExchange(), and exchange() are atomic. Store a value before wake().

Methods

Static method attachNamed

public static function attachNamed ( string $name ) : self

Attach a named futex.

Static method createNamed

public static function createNamed ( string $name , int $value ) : self

Create a named futex.

public static function unlink ( string $name ) : void

Remove a name. An existing mapping stays valid.

Method __construct

public function __construct ( int $value )

Create an anonymous futex.

Param int $value initial signed 32-bit value

Throws \ValueError when the value does not fit Throws \Swow\SyncException when the futex cannot be created

Method __debugInfo

public function __debugInfo ( ) : array

Return debug information.

Method __serialize

public function __serialize ( ) : array

Serialize the futex by name or shared object id.

Method __unserialize

public function __unserialize ( array $data ) : void

Restore the futex from a name or shared object id.

Method add

public function add ( int $delta ) : int

Add a signed value to the futex word.

The addition is atomic and wraps on overflow.

Param int $delta signed 32-bit value to add

Returns int the value before the addition

Method compareExchange

public function compareExchange ( int $expected , int $new ) : bool

Compare and exchange the futex word.

The write happens only when the current value equals expected.

Param int $expected signed 32-bit value to compare Param int $new signed 32-bit value to store

Returns bool true when the value was stored

Method exchange

public function exchange ( int $new ) : int

Exchange the futex word.

Param int $new signed 32-bit value to store

Returns int the value before the exchange

Method getSharedId

public function getSharedId ( ) : int

Return the shared object id.

Method getValue

public function getValue ( ) : int

Return the current value with acquire order.

Method setValue

public function setValue ( int $value ) : void

Store a value with release order.

Method wait

public function wait ( int $expected , int $timeout ) : bool

Wait while the value equals expected.

this method blocks the whole OS thread

Param int $expected signed 32-bit value to compare Param int $timeout timeout in milliseconds, -1 waits forever

Returns bool false when the value changed or the timeout expired

Throws \Swow\SyncException when the wait cannot be performed

Method wake

public function wake ( int $count ) : bool

Wake waiters. This method does not block.

A negative count wakes all waiters. A count of zero wakes none.


Copyright 2022 the Swow contributors

This site uses Just the Docs, a documentation theme for Jekyll.