diff options
author | Robin Appelman <icewind@owncloud.com> | 2015-05-29 14:34:21 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2015-06-01 13:24:02 +0200 |
commit | a1372b2fb5acc51eacf70012a6702a96c78e61ff (patch) | |
tree | 391f8392a034c276ec7838698cd4af3a8bd6fbd5 /lib/private/lock/memcachelockingprovider.php | |
parent | 43772e2a9a4b1400e7e3a8874130ac817aa64058 (diff) | |
download | nextcloud-server-a1372b2fb5acc51eacf70012a6702a96c78e61ff.tar.gz nextcloud-server-a1372b2fb5acc51eacf70012a6702a96c78e61ff.zip |
add method to atomically change between shared and exclusive lock
Diffstat (limited to 'lib/private/lock/memcachelockingprovider.php')
-rw-r--r-- | lib/private/lock/memcachelockingprovider.php | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/private/lock/memcachelockingprovider.php b/lib/private/lock/memcachelockingprovider.php index 1334d007314..368ff450325 100644 --- a/lib/private/lock/memcachelockingprovider.php +++ b/lib/private/lock/memcachelockingprovider.php @@ -99,6 +99,26 @@ class MemcacheLockingProvider implements ILockingProvider { } /** + * Change the type of an existing lock + * + * @param string $path + * @param int $targetType self::LOCK_SHARED or self::LOCK_EXCLUSIVE + * @throws \OCP\Lock\LockedException + */ + public function changeLock($path, $targetType) { + if ($targetType === self::LOCK_SHARED) { + if (!$this->memcache->cas($path, 'exclusive', 1)) { + throw new LockedException($path); + } + } else if ($targetType === self::LOCK_EXCLUSIVE) { + // we can only change a shared lock to an exclusive if there's only a single owner of the shared lock + if (!$this->memcache->cas($path, 1, 'exclusive')) { + throw new LockedException($path); + } + } + } + + /** * release all lock acquired by this instance */ public function releaseAll() { |