3 namespace Friendica\Core\Lock;
8 * @package Friendica\Core\Lock
10 * Basic class for Locking with common functions (local acquired locks, releaseAll, ..)
12 abstract class Lock implements ILock
15 * @var array The local acquired locks
17 protected $acquiredLocks = [];
20 * Check if we've locally acquired a lock
22 * @param string key The Name of the lock
24 * @return bool Returns true if the lock is set
26 protected function hasAcquiredLock($key)
28 return isset($this->acquireLock[$key]) && $this->acquiredLocks[$key] === true;
32 * Mark a locally acquired lock
34 * @param string $key The Name of the lock
36 protected function markAcquire($key)
38 $this->acquiredLocks[$key] = true;
42 * Mark a release of a locally acquired lock
44 * @param string $key The Name of the lock
46 protected function markRelease($key)
48 unset($this->acquiredLocks[$key]);
52 * Releases all lock that were set by us
54 * @return boolean Was the unlock of all locks successful?
56 public function releaseAll()
60 foreach ($this->acquiredLocks as $acquiredLock => $hasLock) {
61 if (!$this->releaseLock($acquiredLock)) {