mirror of
https://github.com/friendica/friendica
synced 2025-04-29 13:04:23 +02:00
code standards / simplifications
This commit is contained in:
parent
19209f6826
commit
906bb25972
18 changed files with 70 additions and 121 deletions
|
@ -8,7 +8,7 @@ use Friendica\BaseObject;
|
|||
*
|
||||
* @package Friendica\Core\Lock
|
||||
*
|
||||
* @brief Basic class for Locking with common functions (local acquired locks, releaseAll, ..)
|
||||
* Basic class for Locking with common functions (local acquired locks, releaseAll, ..)
|
||||
*/
|
||||
abstract class AbstractLockDriver extends BaseObject implements ILockDriver
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ abstract class AbstractLockDriver extends BaseObject implements ILockDriver
|
|||
protected $acquiredLocks = [];
|
||||
|
||||
/**
|
||||
* @brief Check if we've locally acquired a lock
|
||||
* Check if we've locally acquired a lock
|
||||
*
|
||||
* @param string key The Name of the lock
|
||||
* @return bool Returns true if the lock is set
|
||||
|
@ -28,7 +28,7 @@ abstract class AbstractLockDriver extends BaseObject implements ILockDriver
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Mark a locally acquired lock
|
||||
* Mark a locally acquired lock
|
||||
*
|
||||
* @param string $key The Name of the lock
|
||||
*/
|
||||
|
@ -37,7 +37,7 @@ abstract class AbstractLockDriver extends BaseObject implements ILockDriver
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Mark a release of a locally acquired lock
|
||||
* Mark a release of a locally acquired lock
|
||||
*
|
||||
* @param string $key The Name of the lock
|
||||
*/
|
||||
|
@ -46,13 +46,13 @@ abstract class AbstractLockDriver extends BaseObject implements ILockDriver
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Releases all lock that were set by us
|
||||
* Releases all lock that were set by us
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function releaseAll() {
|
||||
foreach ($this->acquiredLocks as $acquiredLock => $hasLock) {
|
||||
$this->releaseLock($acquiredLock);
|
||||
$this->release($acquiredLock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,15 +22,9 @@ class CacheLockDriver extends AbstractLockDriver
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief Sets a lock for a given name
|
||||
*
|
||||
* @param string $key The Name of the lock
|
||||
* @param integer $timeout Seconds until we give up
|
||||
*
|
||||
* @return boolean Was the lock successful?
|
||||
* (@inheritdoc)
|
||||
*/
|
||||
public function acquireLock($key, $timeout = 120)
|
||||
public function acquire($key, $timeout = 120)
|
||||
{
|
||||
$got_lock = false;
|
||||
$start = time();
|
||||
|
@ -64,11 +58,9 @@ class CacheLockDriver extends AbstractLockDriver
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Removes a lock if it was set by us
|
||||
*
|
||||
* @param string $key Name of the lock
|
||||
* (@inheritdoc)
|
||||
*/
|
||||
public function releaseLock($key)
|
||||
public function release($key)
|
||||
{
|
||||
$cachekey = self::getCacheKey($key);
|
||||
|
||||
|
@ -77,10 +69,7 @@ class CacheLockDriver extends AbstractLockDriver
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Checks, if a key is currently locked to a process
|
||||
*
|
||||
* @param string $key The name of the lock
|
||||
* @return bool
|
||||
* (@inheritdoc)
|
||||
*/
|
||||
public function isLocked($key)
|
||||
{
|
||||
|
|
|
@ -14,7 +14,7 @@ class DatabaseLockDriver extends AbstractLockDriver
|
|||
/**
|
||||
* (@inheritdoc)
|
||||
*/
|
||||
public function acquireLock($key, $timeout = 120)
|
||||
public function acquire($key, $timeout = 120)
|
||||
{
|
||||
$got_lock = false;
|
||||
$start = time();
|
||||
|
@ -55,7 +55,7 @@ class DatabaseLockDriver extends AbstractLockDriver
|
|||
/**
|
||||
* (@inheritdoc)
|
||||
*/
|
||||
public function releaseLock($key)
|
||||
public function release($key)
|
||||
{
|
||||
dba::delete('locks', ['name' => $key, 'pid' => getmypid()]);
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Friendica\Core\Lock;
|
|||
interface ILockDriver
|
||||
{
|
||||
/**
|
||||
* @brief Checks, if a key is currently locked to a or my process
|
||||
* Checks, if a key is currently locked to a or my process
|
||||
*
|
||||
* @param string $key The name of the lock
|
||||
* @return bool
|
||||
|
@ -19,26 +19,26 @@ interface ILockDriver
|
|||
|
||||
/**
|
||||
*
|
||||
* @brief Acquires a lock for a given name
|
||||
* Acquires a lock for a given name
|
||||
*
|
||||
* @param string $key The Name of the lock
|
||||
* @param integer $timeout Seconds until we give up
|
||||
*
|
||||
* @return boolean Was the lock successful?
|
||||
*/
|
||||
public function acquireLock($key, $timeout = 120);
|
||||
public function acquire($key, $timeout = 120);
|
||||
|
||||
/**
|
||||
* @brief Releases a lock if it was set by us
|
||||
* Releases a lock if it was set by us
|
||||
*
|
||||
* @param string $key The Name of the lock
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function releaseLock($key);
|
||||
public function release($key);
|
||||
|
||||
/**
|
||||
* @brief Releases all lock that were set by us
|
||||
* Releases all lock that were set by us
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
|
|
@ -14,11 +14,7 @@ class SemaphoreLockDriver extends AbstractLockDriver
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Creates a semaphore key
|
||||
*
|
||||
* @param string $key Name of the lock
|
||||
*
|
||||
* @return integer the semaphore key
|
||||
* (@inheritdoc)
|
||||
*/
|
||||
private static function semaphoreKey($key)
|
||||
{
|
||||
|
@ -35,14 +31,9 @@ class SemaphoreLockDriver extends AbstractLockDriver
|
|||
|
||||
/**
|
||||
*
|
||||
* @brief Sets a lock for a given name
|
||||
*
|
||||
* @param string $key The Name of the lock
|
||||
* @param integer $timeout Seconds until we give up
|
||||
*
|
||||
* @return boolean Was the lock successful?
|
||||
* (@inheritdoc)
|
||||
*/
|
||||
public function acquireLock($key, $timeout = 120)
|
||||
public function acquire($key, $timeout = 120)
|
||||
{
|
||||
self::$semaphore[$key] = sem_get(self::semaphoreKey($key));
|
||||
if (self::$semaphore[$key]) {
|
||||
|
@ -56,13 +47,9 @@ class SemaphoreLockDriver extends AbstractLockDriver
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Removes a lock if it was set by us
|
||||
*
|
||||
* @param string $key Name of the lock
|
||||
*
|
||||
* @return mixed
|
||||
* (@inheritdoc)
|
||||
*/
|
||||
public function releaseLock($key)
|
||||
public function release($key)
|
||||
{
|
||||
if (empty(self::$semaphore[$key])) {
|
||||
return false;
|
||||
|
@ -75,10 +62,7 @@ class SemaphoreLockDriver extends AbstractLockDriver
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Checks, if a key is currently locked to a process
|
||||
*
|
||||
* @param string $key The name of the lock
|
||||
* @return bool
|
||||
* (@inheritdoc)
|
||||
*/
|
||||
public function isLocked($key)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue