PosixSemaphore
in package
implements
Semaphore
uses
ForbidCloning, ForbidSerialization
A non-blocking, inter-process POSIX semaphore.
Uses a POSIX message queue to store a queue of permits in a lock-free data structure. This semaphore implementation is preferred over other implementations when available, as it provides the best performance.
Not compatible with Windows.
Table of Contents
Interfaces
- Semaphore
- A counting semaphore.
Constants
- LATENCY_TIMEOUT = 0.01
- MAX_ID = 0x7fffffff
Properties
- $errorHandler : Closure
- $initializer : int
- $key : int
- $nextId : int
- $queue : SysvMessageQueue
Methods
- __destruct() : mixed
- Removes the semaphore if it still exists.
- __serialize() : never
- __unserialize() : never
- acquire() : Lock
- Acquires a lock on the semaphore. Semaphores may have one or more locks.
- create() : self
- Creates a new semaphore with a given ID and number of locks.
- getKey() : int
- getPermissions() : int
- Gets the access permissions of the semaphore.
- setPermissions() : void
- Sets the access permissions of the semaphore.
- use() : self
- __clone() : mixed
- __construct() : mixed
- getNextId() : int
- release() : void
- Releases a lock from the semaphore.
Constants
LATENCY_TIMEOUT
private
mixed
LATENCY_TIMEOUT
= 0.01
MAX_ID
private
mixed
MAX_ID
= 0x7fffffff
Properties
$errorHandler read-only
private
Closure
$errorHandler
$initializer read-only
private
int
$initializer
$key read-only
private
int
$key
$nextId
private
static int
$nextId
= 0
$queue read-only
private
SysvMessageQueue
$queue
Methods
__destruct()
Removes the semaphore if it still exists.
public
__destruct() : mixed
Tags
__serialize()
public
final __serialize() : never
Return values
never__unserialize()
public
final __unserialize(array<string|int, mixed> $data) : never
Parameters
- $data : array<string|int, mixed>
Return values
neveracquire()
Acquires a lock on the semaphore. Semaphores may have one or more locks.
public
acquire() : Lock
Return values
Lock —Returns with a lock object once a lock is obtained. May fail with a SyncException if an error occurs when attempting to obtain the lock (e.g. a shared memory segment closed).
create()
Creates a new semaphore with a given ID and number of locks.
public
static create(int $maxLocks[, int $permissions = 0600 ]) : self
Parameters
- $maxLocks : int
-
The maximum number of locks that can be acquired from the semaphore.
- $permissions : int = 0600
-
Permissions to access the semaphore. Use file permission format specified as 0xxx.
Tags
Return values
selfgetKey()
public
getKey() : int
Return values
intgetPermissions()
Gets the access permissions of the semaphore.
public
getPermissions() : int
Return values
int —A permissions mode.
setPermissions()
Sets the access permissions of the semaphore.
public
setPermissions(int $mode) : void
The current user must have access to the semaphore in order to change the permissions.
Parameters
- $mode : int
-
A permissions mode to set.
Tags
use()
public
static use(int $key) : self
Parameters
- $key : int
-
Use getKey() on the creating process and send this key to another process.
Return values
self__clone()
protected
final __clone() : mixed
__construct()
private
__construct(SysvMessageQueue $queue, int $key, int $initializer) : mixed
Parameters
- $queue : SysvMessageQueue
- $key : int
- $initializer : int
-
PID of the process that created the semaphore or 0 if the semaphore was only opened in this process.
Tags
getNextId()
private
static getNextId() : int
Return values
intrelease()
Releases a lock from the semaphore.
private
release() : void