mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-16 07:11:19 +08:00
56 lines
1.0 KiB
PHP
56 lines
1.0 KiB
PHP
<?php
|
|
/**
|
|
* @link https://www.yiiframework.com/
|
|
* @copyright Copyright (c) 2008 Yii Software LLC
|
|
* @license https://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 $attemptsTime = [];
|
|
public static $locked = false;
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function acquireLock($name, $timeout = 0)
|
|
{
|
|
return $this->retryAcquire($timeout, function () {
|
|
$this->attemptsTime[] = \microtime(true);
|
|
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;
|
|
}
|
|
}
|