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:
parent
1ed1a45a3d
commit
1f76fcadb2
@ -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.
|
||||
*/
|
||||
|
@ -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.
|
||||
|
31
src/SynchronizableInterface.php
Normal file
31
src/SynchronizableInterface.php
Normal 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user