3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Core;
24 use Friendica\Core\Lock\ILock;
27 * Basic class for Locking with common functions (local acquired locks, releaseAll, ..)
29 abstract class BaseLock implements ILock
32 * @var array The local acquired locks
34 protected $acquiredLocks = [];
37 * Check if we've locally acquired a lock
39 * @param string key The Name of the lock
41 * @return bool Returns true if the lock is set
43 protected function hasAcquiredLock($key)
45 return isset($this->acquireLock[$key]) && $this->acquiredLocks[$key] === true;
49 * Mark a locally acquired lock
51 * @param string $key The Name of the lock
53 protected function markAcquire($key)
55 $this->acquiredLocks[$key] = true;
59 * Mark a release of a locally acquired lock
61 * @param string $key The Name of the lock
63 protected function markRelease($key)
65 unset($this->acquiredLocks[$key]);
71 public function releaseAll($override = false)
75 foreach ($this->acquiredLocks as $acquiredLock => $hasLock) {
76 if (!$this->release($acquiredLock, $override)) {