Replace Lock::acquire() with DI::lock()->acquire()
This commit is contained in:
parent
e56c8dcc3c
commit
634e657d23
13 changed files with 38 additions and 52 deletions
|
@ -15,21 +15,6 @@ use Friendica\DI;
|
|||
*/
|
||||
class Lock
|
||||
{
|
||||
/**
|
||||
* @brief Acquires a lock for a given name
|
||||
*
|
||||
* @param string $key Name of the lock
|
||||
* @param integer $timeout Seconds until we give up
|
||||
* @param integer $ttl The Lock lifespan, must be one of the Cache constants
|
||||
*
|
||||
* @return boolean Was the lock successful?
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function acquire($key, $timeout = 120, $ttl = Cache::FIVE_MINUTES)
|
||||
{
|
||||
return DI::lock()->acquireLock($key, $timeout, $ttl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Releases a lock if it was set by us
|
||||
*
|
||||
|
|
|
@ -30,7 +30,7 @@ class CacheLock extends Lock
|
|||
/**
|
||||
* (@inheritdoc)
|
||||
*/
|
||||
public function acquireLock($key, $timeout = 120, $ttl = Cache\Cache::FIVE_MINUTES)
|
||||
public function acquire($key, $timeout = 120, $ttl = Cache\Cache::FIVE_MINUTES)
|
||||
{
|
||||
$got_lock = false;
|
||||
$start = time();
|
||||
|
|
|
@ -35,7 +35,7 @@ class DatabaseLock extends Lock
|
|||
/**
|
||||
* (@inheritdoc)
|
||||
*/
|
||||
public function acquireLock($key, $timeout = 120, $ttl = Cache::FIVE_MINUTES)
|
||||
public function acquire($key, $timeout = 120, $ttl = Cache::FIVE_MINUTES)
|
||||
{
|
||||
$got_lock = false;
|
||||
$start = time();
|
||||
|
|
|
@ -30,7 +30,7 @@ interface ILock
|
|||
*
|
||||
* @return boolean Was the lock successful?
|
||||
*/
|
||||
public function acquireLock($key, $timeout = 120, $ttl = Cache\Cache::FIVE_MINUTES);
|
||||
public function acquire($key, $timeout = 120, $ttl = Cache\Cache::FIVE_MINUTES);
|
||||
|
||||
/**
|
||||
* Releases a lock if it was set by us
|
||||
|
|
|
@ -36,7 +36,7 @@ class SemaphoreLock extends Lock
|
|||
/**
|
||||
* (@inheritdoc)
|
||||
*/
|
||||
public function acquireLock($key, $timeout = 120, $ttl = Cache\Cache::FIVE_MINUTES)
|
||||
public function acquire($key, $timeout = 120, $ttl = Cache\Cache::FIVE_MINUTES)
|
||||
{
|
||||
self::$semaphore[$key] = sem_get(self::semaphoreKey($key));
|
||||
if (!empty(self::$semaphore[$key])) {
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Friendica\Core;
|
|||
use Friendica\App;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Database\DBStructure;
|
||||
use Friendica\DI;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
class Update
|
||||
|
@ -95,7 +96,7 @@ class Update
|
|||
|
||||
// Compare the current structure with the defined structure
|
||||
// If the Lock is acquired, never release it automatically to avoid double updates
|
||||
if (Lock::acquire('dbupdate', 120, Cache::INFINITE)) {
|
||||
if (DI::lock()->acquire('dbupdate', 120, Cache::INFINITE)) {
|
||||
|
||||
// Checks if the build changed during Lock acquiring (so no double update occurs)
|
||||
$retryBuild = Config::get('system', 'build', null, true);
|
||||
|
@ -181,7 +182,7 @@ class Update
|
|||
// If the update fails or times-out completely you may need to
|
||||
// delete the config entry to try again.
|
||||
|
||||
if (Lock::acquire('dbupdate_function', 120,Cache::INFINITE)) {
|
||||
if (DI::lock()->acquire('dbupdate_function', 120,Cache::INFINITE)) {
|
||||
|
||||
// call the specific update
|
||||
$retval = $funcname();
|
||||
|
|
|
@ -115,7 +115,7 @@ class Worker
|
|||
}
|
||||
|
||||
// Trying to fetch new processes - but only once when successful
|
||||
if (!$refetched && Lock::acquire('worker_process', 0)) {
|
||||
if (!$refetched && DI::lock()->acquire('worker_process', 0)) {
|
||||
self::findWorkerProcesses();
|
||||
Lock::release('worker_process');
|
||||
self::$state = self::STATE_REFETCH;
|
||||
|
@ -129,7 +129,7 @@ class Worker
|
|||
if (!self::getWaitingJobForPID()) {
|
||||
self::$state = self::STATE_LONG_LOOP;
|
||||
|
||||
if (Lock::acquire('worker', 0)) {
|
||||
if (DI::lock()->acquire('worker', 0)) {
|
||||
// Count active workers and compare them with a maximum value that depends on the load
|
||||
if (self::tooMuchWorkers()) {
|
||||
Logger::log('Active worker limit reached, quitting.', Logger::DEBUG);
|
||||
|
@ -933,7 +933,7 @@ class Worker
|
|||
}
|
||||
|
||||
$stamp = (float)microtime(true);
|
||||
if (!Lock::acquire('worker_process')) {
|
||||
if (!DI::lock()->acquire('worker_process')) {
|
||||
return false;
|
||||
}
|
||||
self::$lock_duration += (microtime(true) - $stamp);
|
||||
|
@ -1172,7 +1172,7 @@ class Worker
|
|||
}
|
||||
|
||||
// If there is a lock then we don't have to check for too much worker
|
||||
if (!Lock::acquire('worker', 0)) {
|
||||
if (!DI::lock()->acquire('worker', 0)) {
|
||||
return $added;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue