Yii2 framework backup
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

55 lines
1.0 KiB

<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yiiunit\framework\mutex\mocks;
use yii\mutex\Mutex;
use yii\mutex\RetryAcquireTrait;
/**
* Class DumbMutex.
*
* @author Robert Korulczyk <robert@korulczyk.pl>
*/
class DumbMutex extends Mutex
{
use RetryAcquireTrait;
public $attemptsCounter = 0;
public static $locked = false;
/**
* {@inheritdoc}
*/
protected function acquireLock($name, $timeout = 0)
{
return $this->retryAcquire($timeout, function () {
$this->attemptsCounter++;
if (!static::$locked) {
static::$locked = true;
return true;
}
return false;
});
}
/**
* {@inheritdoc}
*/
protected function releaseLock($name)
{
if (static::$locked) {
static::$locked = false;
return true;
}
return false;
}
}