1
0
mirror of https://github.com/danog/parallel.git synced 2024-12-04 02:27:55 +01:00
parallel/lib/Sync/Semaphore.php

41 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace Icicle\Concurrent\Sync;
/**
* A non-blocking counting semaphore.
*
* Objects that implement this interface should guarantee that all operations
2015-08-31 19:26:11 +02:00
* are atomic. Implementations do not have to guarantee that acquiring a lock
* is first-come, first serve.
*/
2015-12-05 06:50:32 +01:00
interface Semaphore extends \Countable
{
/**
* Gets the number of currently available locks.
*
* @return int The number of available locks.
*/
2016-01-25 05:59:14 +01:00
public function count(): int;
/**
* Gets the total number of locks on the semaphore (not the number of available locks).
*
* @return int The total number of locks.
*/
2016-01-25 05:59:14 +01:00
public function getSize(): int;
/**
* @coroutine
*
* Acquires a lock from the semaphore asynchronously.
*
2015-10-17 06:32:01 +02:00
* If there are one or more locks available, this function resolves immediately with a lock and the lock count is
* decreased. If no locks are available, the semaphore waits asynchronously for a lock to become available.
*
* @return \Generator Resolves with a lock object when the acquire is successful.
*
* @resolve \Icicle\Concurrent\Sync\Lock
*/
2016-01-25 05:59:14 +01:00
public function acquire(): \Generator;
}