PHP Class Icicle\Concurrent\Threading\Internal\Semaphore

Inheritance: extends Threaded
Mostrar archivo Open project: icicleio/concurrent Class Usage Examples

Public Methods

Method Description
__construct ( integer $locks ) Creates a new semaphore with a given number of locks.
acquire ( ) : Generator Uses a double locking mechanism to acquire a lock without blocking. A synchronous mutex is used to make sure that the semaphore is queried one at a time to preserve the integrity of the semaphore itself. Then a lock count is used to check if a lock is available without blocking.
count ( ) : integer Gets the number of currently available locks.

Protected Methods

Method Description
release ( ) Releases a lock from the semaphore.

Method Details

__construct() public method

Creates a new semaphore with a given number of locks.
public __construct ( integer $locks )
$locks integer The maximum number of locks that can be acquired from the semaphore.

acquire() public method

If a lock is not available, we add the request to a queue and set a timer to check again in the future.
public acquire ( ) : Generator
return Generator

count() public method

Gets the number of currently available locks.
public count ( ) : integer
return integer The number of available locks.

release() protected method

Releases a lock from the semaphore.
protected release ( )