1
0
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:
coderstephen 2015-08-01 20:15:03 -05:00
parent a0d0b3646e
commit eded7b86a4
2 changed files with 28 additions and 6 deletions

View 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();
}

View File

@ -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()
{ {