1
0
mirror of https://github.com/danog/parallel.git synced 2024-11-30 04:39:01 +01:00

Synchronization methods now part of SynchronizableInterface

This commit is contained in:
coderstephen 2015-07-15 18:12:18 -05:00
parent 1ed1a45a3d
commit 1f76fcadb2
3 changed files with 35 additions and 25 deletions

View File

@ -4,7 +4,7 @@ namespace Icicle\Concurrent;
/**
* Interface for all types of execution contexts.
*/
interface ContextInterface
interface ContextInterface extends SynchronizableInterface
{
/**
* Checks if the context is running.
@ -13,29 +13,6 @@ interface ContextInterface
*/
public function isRunning();
/**
* Acquires a lock on the context.
*
* @return \Icicle\Promise\PromiseInterface
*/
public function lock();
/**
* Unlocks the context.
*
* @return \Icicle\Promise\PromiseInterface
*/
public function unlock();
/**
* Invokes a function while maintaining a lock for the calling context.
*
* @param callable $callback The function to invoke.
*
* @return \Icicle\Promise\PromiseInterface
*/
public function synchronized(callable $callback);
/**
* Starts the context execution.
*/

View File

@ -1,6 +1,8 @@
<?php
namespace Icicle\Concurrent\Forking;
use Icicle\Concurrent\SynchronizableInterface;
/**
* A synchronized object that safely shares its state across processes and
* provides methods for process synchronization.
@ -8,7 +10,7 @@ namespace Icicle\Concurrent\Forking;
* When used with forking, the object must be created prior to forking for both
* processes to access the synchronized object.
*/
abstract class Synchronized extends SharedObject
abstract class Synchronized extends SharedObject implements SynchronizableInterface
{
/**
* @var AsyncSemaphore A semaphore used for locking the object data.

View File

@ -0,0 +1,31 @@
<?php
namespace Icicle\Concurrent;
/**
* Interface for objects that can be synchronized across contexts.
*/
interface SynchronizableInterface
{
/**
* Acquires a lock on the context.
*
* @return \Icicle\Promise\PromiseInterface
*/
public function lock();
/**
* Unlocks the context.
*
* @return \Icicle\Promise\PromiseInterface
*/
public function unlock();
/**
* Invokes a function while maintaining a lock for the calling context.
*
* @param callable $callback The function to invoke.
*
* @return \Icicle\Promise\PromiseInterface
*/
public function synchronized(callable $callback);
}