3 namespace Friendica\Core\Lock;
4 use Friendica\BaseObject;
7 * Class AbstractLockDriver
9 * @package Friendica\Core\Lock
11 * Basic class for Locking with common functions (local acquired locks, releaseAll, ..)
13 abstract class AbstractLockDriver extends BaseObject implements ILockDriver
16 * @var array The local acquired locks
18 protected $acquiredLocks = [];
21 * Check if we've locally acquired a lock
23 * @param string key The Name of the lock
24 * @return bool Returns true if the lock is set
26 protected function hasAcquiredLock($key) {
27 return isset($this->acquireLock[$key]) && $this->acquiredLocks[$key] === true;
31 * Mark a locally acquired lock
33 * @param string $key The Name of the lock
35 protected function markAcquire($key) {
36 $this->acquiredLocks[$key] = true;
40 * Mark a release of a locally acquired lock
42 * @param string $key The Name of the lock
44 protected function markRelease($key) {
45 unset($this->acquiredLocks[$key]);
49 * Releases all lock that were set by us
53 public function releaseAll() {
54 foreach ($this->acquiredLocks as $acquiredLock => $hasLock) {
55 $this->releaseLock($acquiredLock);