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:
parent
19080f651b
commit
ff2f0682d6
41
src/Sync/ExtSyncSemaphore.php
Normal file
41
src/Sync/ExtSyncSemaphore.php
Normal 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();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user