1
0
mirror of https://github.com/danog/parallel.git synced 2025-01-22 05:51:14 +01:00

Add semaphore from sync extension

This commit is contained in:
coderstephen 2015-08-01 21:56:18 -05:00
parent 19080f651b
commit ff2f0682d6

View File

@ -0,0 +1,41 @@
<?php
namespace Icicle\Concurrent\Sync;
use Icicle\Concurrent\Exception\SemaphoreException;
/**
* A wrapper for a semaphore based on the "sync" extension.
*/
class ExtSyncSemaphore implements SemaphoreInterface
{
/**
* @var \SyncSemaphore A semaphore instance.
*/
private $semaphore;
/**
* Creates a new semaphore object.
*
* @param int $maxLocks The maximum number of processes that can lock the semaphore.
*/
public function __construct($maxLocks = 1)
{
$this->semaphore = new \SyncSemaphore(null, $maxLocks);
}
/**
* {@inheritdoc}
*/
public function lock()
{
$this->semaphore->lock(-1);
}
/**
* {@inheritdoc}
*/
public function unlock()
{
$this->semaphore->unlock();
}
}