1
0
Fork 0

Merge pull request #8131 from nupplaphil/task/cleanup_lock

CleanUp Lock namespace
This commit is contained in:
Hypolite Petovan 2020-01-18 14:13:14 -05:00 committed by GitHub
commit 8536b313a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 21 deletions

View file

@ -1,21 +1,14 @@
<?php
namespace Friendica\Core\Lock;
namespace Friendica\Core;
use Friendica\Core\Cache\Type;
use Friendica\Core\Lock\ILock;
/**
* Class AbstractLock
*
* @package Friendica\Core\Lock
*
* Basic class for Locking with common functions (local acquired locks, releaseAll, ..)
*/
abstract class Lock implements ILock
abstract class BaseLock implements ILock
{
const TYPE_DATABASE = Type::DATABASE;
const TYPE_SEMAPHORE = 'semaphore';
/**
* @var array The local acquired locks
*/

View file

@ -2,10 +2,11 @@
namespace Friendica\Core\Lock;
use Friendica\Core\Cache;
use Friendica\Core\BaseLock;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\IMemoryCache;
class CacheLock extends Lock
class CacheLock extends BaseLock
{
/**
* @var string The static prefix of all locks inside the cache
@ -30,7 +31,7 @@ class CacheLock extends Lock
/**
* (@inheritdoc)
*/
public function acquire($key, $timeout = 120, $ttl = Cache\Duration::FIVE_MINUTES)
public function acquire($key, $timeout = 120, $ttl = Duration::FIVE_MINUTES)
{
$got_lock = false;
$start = time();

View file

@ -2,6 +2,7 @@
namespace Friendica\Core\Lock;
use Friendica\Core\BaseLock;
use Friendica\Core\Cache\Duration;
use Friendica\Database\Database;
use Friendica\Util\DateTimeFormat;
@ -9,7 +10,7 @@ use Friendica\Util\DateTimeFormat;
/**
* Locking driver that stores the locks in the database
*/
class DatabaseLock extends Lock
class DatabaseLock extends BaseLock
{
/**
* The current ID of the process
@ -131,7 +132,7 @@ class DatabaseLock extends Lock
*/
public function getName()
{
return self::TYPE_DATABASE;
return Type::DATABASE;
}
/**

View file

@ -2,7 +2,7 @@
namespace Friendica\Core\Lock;
use Friendica\Core\Cache;
use Friendica\Core\Cache\Duration;
/**
* Lock Interface
@ -30,7 +30,7 @@ interface ILock
*
* @return boolean Was the lock successful?
*/
public function acquire($key, $timeout = 120, $ttl = Cache\Duration::FIVE_MINUTES);
public function acquire($key, $timeout = 120, $ttl = Duration::FIVE_MINUTES);
/**
* Releases a lock if it was set by us

View file

@ -2,9 +2,10 @@
namespace Friendica\Core\Lock;
use Friendica\Core\Cache;
use Friendica\Core\BaseLock;
use Friendica\Core\Cache\Duration;
class SemaphoreLock extends Lock
class SemaphoreLock extends BaseLock
{
private static $semaphore = [];
@ -36,7 +37,7 @@ class SemaphoreLock extends Lock
/**
* (@inheritdoc)
*/
public function acquire($key, $timeout = 120, $ttl = Cache\Duration::FIVE_MINUTES)
public function acquire($key, $timeout = 120, $ttl = Duration::FIVE_MINUTES)
{
self::$semaphore[$key] = sem_get(self::semaphoreKey($key));
if (!empty(self::$semaphore[$key])) {
@ -85,7 +86,7 @@ class SemaphoreLock extends Lock
*/
public function getName()
{
return self::TYPE_SEMAPHORE;
return Type::SEMAPHORE;
}
/**

16
src/Core/Lock/Type.php Normal file
View file

@ -0,0 +1,16 @@
<?php
namespace Friendica\Core\Lock;
use Friendica\Core\Cache\Type as CacheType;
/**
* Enumeration for lock types
*
* There's no "Cache" lock type, because the type depends on the concrete, used cache
*/
abstract class Type
{
const DATABASE = CacheType::DATABASE;
const SEMAPHORE = 'semaphore';
}