if (count($this->args) >= 2) {
$lock = $this->getArgument(1);
- if ($this->lock->releaseLock($lock, true)) {
+ if ($this->lock->release($lock, true)) {
$this->out(sprintf('Lock \'%s\' released.', $lock));
} else {
$this->out(sprintf('Couldn\'t release Lock \'%s\'', $lock));
+++ /dev/null
-<?php
-
-/**
- * @file src/Core/Lock.php
- * @brief Functions for preventing parallel execution of functions
- */
-
-namespace Friendica\Core;
-
-use Friendica\Core\Cache\Cache;
-use Friendica\DI;
-
-/**
- * This class contain Functions for preventing parallel execution of functions
- */
-class Lock
-{
- /**
- * @brief Releases a lock if it was set by us
- *
- * @param string $key Name of the lock
- * @param bool $override Overrides the lock to get releases
- *
- * @return bool
- * @throws \Exception
- */
- public static function release($key, $override = false)
- {
- return DI::lock()->releaseLock($key, $override);
- }
-
- /**
- * @brief Releases all lock that were set by us
- * @return void
- * @throws \Exception
- */
- public static function releaseAll()
- {
- DI::lock()->releaseAll();
- }
-}
/**
* (@inheritdoc)
*/
- public function releaseLock($key, $override = false)
+ public function release($key, $override = false)
{
$cachekey = self::getLockKey($key);
$locks = $this->getLocks();
foreach ($locks as $lock) {
- if (!$this->releaseLock($lock, $override)) {
+ if (!$this->release($lock, $override)) {
$success = false;
}
}
/**
* (@inheritdoc)
*/
- public function releaseLock($key, $override = false)
+ public function release($key, $override = false)
{
if ($override) {
$where = ['name' => $key];
*
* @return boolean Was the unlock successful?
*/
- public function releaseLock($key, $override = false);
+ public function release($key, $override = false);
/**
* Releases all lock that were set by us
$return = true;
foreach ($this->acquiredLocks as $acquiredLock => $hasLock) {
- if (!$this->releaseLock($acquiredLock, $override)) {
+ if (!$this->release($acquiredLock, $override)) {
$return = false;
}
}
* @param bool $override not necessary parameter for semaphore locks since the lock lives as long as the execution
* of the using function
*/
- public function releaseLock($key, $override = false)
+ public function release($key, $override = false)
{
$success = false;
// In force mode, we release the dbupdate lock first
// Necessary in case of an stuck update
if ($override) {
- Lock::release('dbupdate', true);
+ DI::lock()->release('dbupdate', true);
}
$build = Config::get('system', 'build', null, true);
$retryBuild = Config::get('system', 'build', null, true);
if ($retryBuild !== $build) {
Logger::info('Update already done.', ['from' => $stored, 'to' => $current]);
- Lock::release('dbupdate');
+ DI::lock()->release('dbupdate');
return '';
}
$r = self::runUpdateFunction($x, 'pre_update');
if (!$r) {
Config::set('system', 'update', Update::FAILED);
- Lock::release('dbupdate');
+ DI::lock()->release('dbupdate');
return $r;
}
}
}
Logger::error('Update ERROR.', ['from' => $stored, 'to' => $current, 'retval' => $retval]);
Config::set('system', 'update', Update::FAILED);
- Lock::release('dbupdate');
+ DI::lock()->release('dbupdate');
return $retval;
} else {
Config::set('database', 'last_successful_update', $current);
$r = self::runUpdateFunction($x, 'update');
if (!$r) {
Config::set('system', 'update', Update::FAILED);
- Lock::release('dbupdate');
+ DI::lock()->release('dbupdate');
return $r;
}
}
}
Config::set('system', 'update', Update::SUCCESS);
- Lock::release('dbupdate');
+ DI::lock()->release('dbupdate');
}
}
}
L10n::t('Update %s failed. See error logs.', $x)
);
Logger::error('Update function ERROR.', ['function' => $funcname, 'retval' => $retval]);
- Lock::release('dbupdate_function');
+ DI::lock()->release('dbupdate_function');
return false;
} else {
Config::set('database', 'last_successful_update_function', $funcname);
Config::set('system', 'build', $x);
}
- Lock::release('dbupdate_function');
+ DI::lock()->release('dbupdate_function');
Logger::info('Update function finished.', ['function' => $funcname]);
return true;
}
// Trying to fetch new processes - but only once when successful
if (!$refetched && DI::lock()->acquire('worker_process', 0)) {
self::findWorkerProcesses();
- Lock::release('worker_process');
+ DI::lock()->release('worker_process');
self::$state = self::STATE_REFETCH;
$refetched = true;
} else {
// 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);
- Lock::release('worker');
+ DI::lock()->release('worker');
return;
}
// Check free memory
if (DI::process()->isMinMemoryReached()) {
Logger::log('Memory limit reached, quitting.', Logger::DEBUG);
- Lock::release('worker');
+ DI::lock()->release('worker');
return;
}
- Lock::release('worker');
+ DI::lock()->release('worker');
}
}
$found = self::findWorkerProcesses();
- Lock::release('worker_process');
+ DI::lock()->release('worker_process');
if ($found) {
$stamp = (float)microtime(true);
// If there are already enough workers running, don't fork another one
$quit = self::tooMuchWorkers();
- Lock::release('worker');
+ DI::lock()->release('worker');
if ($quit) {
return $added;
} else {
// This shouldn't happen.
Logger::log('Could not insert activity for URI ' . $item['uri'] . ' - should not happen');
- Lock::release('item_insert_activity');
+ DI::lock()->release('item_insert_activity');
return false;
}
if ($locked) {
- Lock::release('item_insert_activity');
+ DI::lock()->release('item_insert_activity');
}
return true;
}
Logger::log('Could not insert content for URI ' . $item['uri'] . ' - should not happen');
}
if ($locked) {
- Lock::release('item_insert_content');
+ DI::lock()->release('item_insert_content');
}
}
// We are having duplicated entries. Hopefully this solves it.
if (DI::lock()->acquire('ostatus_process_item_insert')) {
$ret = Item::insert($item);
- Lock::release('ostatus_process_item_insert');
+ DI::lock()->release('ostatus_process_item_insert');
Logger::log("Item with uri ".$item["uri"]." for user ".$importer["uid"].' stored. Return value: '.$ret);
} else {
$ret = Item::insert($item);
* @param null|int $pid The PID which was set
* @param null|int $times How often the method will get used
*
- *@see DatabaseLock::releaseLock()
+ *@see DatabaseLock::release()
*
*/
public function mockReleaseLock($key, $pid = null, $times = null)
$this->assertFalse($this->instance->isLocked('foo'));
$this->assertTrue($this->instance->acquire('foo', 1));
$this->assertTrue($this->instance->isLocked('foo'));
- $this->instance->releaseLock('foo');
+ $this->instance->release('foo');
$this->assertFalse($this->instance->isLocked('foo'));
}
$this->assertTrue($this->instance->acquire('bar', 1));
$this->assertTrue($this->instance->acquire('nice', 1));
- $this->assertTrue($this->instance->releaseLock('foo'));
+ $this->assertTrue($this->instance->release('foo'));
$this->assertFalse($this->instance->isLocked('foo'));
$this->assertTrue($this->instance->isLocked('bar'));
$this->assertFalse($this->instance->isLocked('test'));
$this->assertTrue($this->instance->acquire('test', 1, 10));
$this->assertTrue($this->instance->isLocked('test'));
- $this->assertTrue($this->instance->releaseLock('test'));
+ $this->assertTrue($this->instance->release('test'));
$this->assertFalse($this->instance->isLocked('test'));
}
public function testReleaseLockWithoutLock()
{
$this->assertFalse($this->instance->isLocked('wrongLock'));
- $this->assertFalse($this->instance->releaseLock('wrongLock'));
+ $this->assertFalse($this->instance->release('wrongLock'));
}
}
touch($file);
$this->assertTrue(file_exists($file));
- $this->assertFalse($this->instance->releaseLock('test', false));
+ $this->assertFalse($this->instance->release('test', false));
$this->assertTrue(file_exists($file));
}
touch($file);
$this->assertTrue(file_exists($file));
- $this->assertFalse($this->instance->releaseLock('test', true));
+ $this->assertFalse($this->instance->release('test', true));
$this->assertTrue(file_exists($file));
}
$this->assertTrue(file_exists($file));
$this->assertTrue($this->instance->acquire('test'));
$this->assertTrue($this->instance->isLocked('test'));
- $this->assertTrue($this->instance->releaseLock('test'));
+ $this->assertTrue($this->instance->release('test'));
}
}