mirror of
https://github.com/danog/parallel.git
synced 2024-11-27 04:44:56 +01:00
Use a common interface for mutexes
This commit is contained in:
parent
a0d0b3646e
commit
eded7b86a4
22
src/Sync/MutexInterface.php
Normal file
22
src/Sync/MutexInterface.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
namespace Icicle\Concurrent\Sync;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple mutex that provides synchronous, atomic locking and unlocking across
|
||||||
|
* contexts.
|
||||||
|
*
|
||||||
|
* Objects that implement this interface should guarantee that all operations
|
||||||
|
* are atomic.
|
||||||
|
*/
|
||||||
|
interface MutexInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Locks the mutex.
|
||||||
|
*/
|
||||||
|
public function lock();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unlocks the mutex.
|
||||||
|
*/
|
||||||
|
public function unlock();
|
||||||
|
}
|
@ -1,14 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Icicle\Concurrent\Threading;
|
namespace Icicle\Concurrent\Threading;
|
||||||
|
|
||||||
|
use Icicle\Concurrent\Sync\MutexInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A thread-safe mutex.
|
* A thread-safe mutex using the pthreads locking mechanism.
|
||||||
*
|
|
||||||
* Operations are guaranteed to be atomic.
|
|
||||||
*
|
*
|
||||||
* Compatible with POSIX systems and Microsoft Windows.
|
* Compatible with POSIX systems and Microsoft Windows.
|
||||||
*/
|
*/
|
||||||
class Mutex extends \Threaded
|
class Mutex extends \Threaded implements MutexInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var long A unique handle ID on a system mutex.
|
* @var long A unique handle ID on a system mutex.
|
||||||
@ -26,7 +26,7 @@ class Mutex extends \Threaded
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Locks the mutex.
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function lock()
|
public function lock()
|
||||||
{
|
{
|
||||||
@ -34,7 +34,7 @@ class Mutex extends \Threaded
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unlocks the mutex.
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function unlock()
|
public function unlock()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user