|
@@ 71-84 (lines=14) @@
|
| 68 |
|
* @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
| 69 |
|
* @throws \OCP\Lock\LockedException |
| 70 |
|
*/ |
| 71 |
|
public function acquireLock($path, $type) { |
| 72 |
|
if ($type === self::LOCK_SHARED) { |
| 73 |
|
if (!$this->memcache->inc($path)) { |
| 74 |
|
throw new LockedException($path, null, $this->getExistingLockForException($path)); |
| 75 |
|
} |
| 76 |
|
} else { |
| 77 |
|
$this->memcache->add($path, 0); |
| 78 |
|
if (!$this->memcache->cas($path, 0, 'exclusive')) { |
| 79 |
|
throw new LockedException($path, null, $this->getExistingLockForException($path)); |
| 80 |
|
} |
| 81 |
|
} |
| 82 |
|
$this->setTTL($path); |
| 83 |
|
$this->markAcquire($path, $type); |
| 84 |
|
} |
| 85 |
|
|
| 86 |
|
/** |
| 87 |
|
* @param string $path |
|
@@ 120-133 (lines=14) @@
|
| 117 |
|
* @param int $targetType self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
| 118 |
|
* @throws \OCP\Lock\LockedException |
| 119 |
|
*/ |
| 120 |
|
public function changeLock($path, $targetType) { |
| 121 |
|
if ($targetType === self::LOCK_SHARED) { |
| 122 |
|
if (!$this->memcache->cas($path, 'exclusive', 1)) { |
| 123 |
|
throw new LockedException($path, null, $this->getExistingLockForException($path)); |
| 124 |
|
} |
| 125 |
|
} else if ($targetType === self::LOCK_EXCLUSIVE) { |
| 126 |
|
// we can only change a shared lock to an exclusive if there's only a single owner of the shared lock |
| 127 |
|
if (!$this->memcache->cas($path, 1, 'exclusive')) { |
| 128 |
|
throw new LockedException($path, null, $this->getExistingLockForException($path)); |
| 129 |
|
} |
| 130 |
|
} |
| 131 |
|
$this->setTTL($path); |
| 132 |
|
$this->markChange($path, $targetType); |
| 133 |
|
} |
| 134 |
|
|
| 135 |
|
private function getExistingLockForException($path) { |
| 136 |
|
$existing = $this->memcache->get($path); |