3 namespace Friendica\Core\Lock;
5 use Friendica\Core\Cache\Cache;
10 * @package Friendica\Core\Lock
12 * Basic class for Locking with common functions (local acquired locks, releaseAll, ..)
14 abstract class Lock implements ILock
16 const TYPE_DATABASE = Cache::TYPE_DATABASE;
17 const TYPE_SEMAPHORE = 'semaphore';
20 * @var array The local acquired locks
22 protected $acquiredLocks = [];
25 * Check if we've locally acquired a lock
27 * @param string key The Name of the lock
29 * @return bool Returns true if the lock is set
31 protected function hasAcquiredLock($key)
33 return isset($this->acquireLock[$key]) && $this->acquiredLocks[$key] === true;
37 * Mark a locally acquired lock
39 * @param string $key The Name of the lock
41 protected function markAcquire($key)
43 $this->acquiredLocks[$key] = true;
47 * Mark a release of a locally acquired lock
49 * @param string $key The Name of the lock
51 protected function markRelease($key)
53 unset($this->acquiredLocks[$key]);
59 public function releaseAll($override = false)
63 foreach ($this->acquiredLocks as $acquiredLock => $hasLock) {
64 if (!$this->releaseLock($acquiredLock, $override)) {