PHP Class yii\mutex\Mutex
This is achieved by using a "lock" mechanism. Each possibly concurrent thread cooperates by acquiring
a lock before accessing the corresponding data.
Usage example:
if ($mutex->acquire($mutexName)) {
business logic execution
} else {
execution is blocked!
}
This is a base class, which should be extended in order to implement the actual lock mechanism.
Exibir arquivo
Open project: yiisoft/yii2
Class Usage Examples
Public Properties
Property |
Type |
Description |
|
$autoRelease |
|
whether all locks acquired in this process (i.e. local locks) must be released automatically
before finishing script execution. Defaults to true. Setting this property to true means that all locks
acquired in this process must be released (regardless of errors or exceptions). |
|
Public Methods
Method |
Description |
|
acquire ( string $name, integer $timeout ) : boolean |
Acquires a lock by name. |
|
init ( ) |
Initializes the Mutex component. |
|
release ( string $name ) : boolean |
Releases acquired lock. This method will return false in case the lock was not found. |
|
Protected Methods
Method |
Description |
|
acquireLock ( string $name, integer $timeout ) : boolean |
This method should be extended by a concrete Mutex implementations. Acquires lock by name. |
|
releaseLock ( string $name ) : boolean |
This method should be extended by a concrete Mutex implementations. Releases lock by given name. |
|
Method Details
public acquire ( string $name, integer $timeout ) : boolean |
$name |
string |
of the lock to be acquired. Must be unique. |
$timeout |
integer |
time to wait for lock to be released. Defaults to zero meaning that method will return
false immediately in case lock was already acquired. |
return |
boolean |
lock acquiring result. |
acquireLock()
abstract protected method
This method should be extended by a concrete Mutex implementations. Acquires lock by name.
Initializes the Mutex component.
Releases acquired lock. This method will return false in case the lock was not found.
public release ( string $name ) : boolean |
$name |
string |
of the lock to be released. This lock must already exist. |
return |
boolean |
lock release result: false in case named lock was not found.. |
releaseLock()
abstract protected method
This method should be extended by a concrete Mutex implementations. Releases lock by given name.
Property Details
$autoRelease public_oe property
whether all locks acquired in this process (i.e. local locks) must be released automatically
before finishing script execution. Defaults to true. Setting this property to true means that all locks
acquired in this process must be released (regardless of errors or exceptions).