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

Class SpscQueue

A fixed-size single-producer single-consumer queue in shared memory.

One thread produces and one thread consumes. A blocking call stops the whole OS thread, so use it only in a worker that runs one coroutine. An anonymous queue is visible to threads of this process and to a forked child. A named queue is visible to another process that attaches the same name.

Methods

Static method attachNamed

public static function attachNamed ( string $name ) : self

Attach a named queue.

Static method createNamed

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

Create a named queue.

Throws \ValueError when a size is out of range Throws SpscQueueException when the name exists or the queue cannot be created

public static function unlink ( string $name ) : void

Remove a name.

An existing mapping stays valid. On Windows the section ends when the last mapping closes; unlink does not remove the name earlier.

Method __construct

public function __construct ( int $capacity , int $maxMessageSize )

Create an anonymous queue.

Param int $capacity maximum number of queued values Param int $maxMessageSize maximum size of one serialized value in bytes

Throws \ValueError when a size is out of range Throws SpscQueueException when the queue cannot be created

Method __debugInfo

public function __debugInfo ( ) : array

Return debug information.

Method __serialize

public function __serialize ( ) : array

Serialize the queue by name or shared object id.

The serialized form does not copy queued values.

Method __unserialize

public function __unserialize ( array $data ) : void

Restore the queue from a name or shared object id.

Method close

public function close ( ) : void

Stop further pushes and wake both sides.

Method drain

public function drain ( ) : array

Pop all queued values without waiting.

Method getCapacity

public function getCapacity ( ) : int

Return the maximum number of queued values.

Method getLength

public function getLength ( ) : int

Return the number of queued values.

Method getMaxMessageSize

public function getMaxMessageSize ( ) : int

Return the maximum serialized value size in bytes.

Method getName

public function getName ( ) : ?string

Return the name, or null for an anonymous queue.

Method getParkCount

public function getParkCount ( ) : int

Return the number of times a side parked.

Method getWakeCount

public function getWakeCount ( ) : int

Return the number of wakes that reached a waiter.

Method isClosed

public function isClosed ( ) : bool

Return true after close.

Method isEmpty

public function isEmpty ( ) : bool

Return true when the queue has no values.

Method isFull

public function isFull ( ) : bool

Return true when the queue has no free slot.

Method pop

public function pop ( int $timeout ) : mixed

Pop and unserialize a value.

this method blocks the whole OS thread

Param int $timeout timeout in milliseconds, -1 waits forever

Throws SpscQueueException on timeout, a closed empty queue, or a deserialization failure

Method popMany

public function popMany ( int $max , int $timeout ) : array

Pop up to max values.

The call returns at least one value when the queue is not empty.

this method blocks the whole OS thread

Param int $max maximum number of values to return Param int $timeout timeout in milliseconds, -1 waits forever

Returns array the values in queue order

Method push

public function push ( mixed $value , int $timeout ) : self

Serialize a value and push it.

this method blocks the whole OS thread

Param mixed $value value to serialize Param int $timeout timeout in milliseconds, -1 waits forever

Throws SpscQueueException on timeout, a closed queue, or a serialization failure

Method pushMany

public function pushMany ( array $values , int $timeout ) : int

Serialize a batch and push it as one unit.

The batch enters as a whole or not at all.

this method blocks the whole OS thread

Param array $values values to serialize Param int $timeout timeout in milliseconds, -1 waits forever

Returns int number of values pushed

Throws SpscQueueException on timeout, a closed queue, or an oversized batch


Copyright 2022 the Swow contributors