/**
  * 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);
             }
         }
     }
     $this->markChange($path, $targetType);
 }
 /**
  * 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);
         }
         unset($this->acquiredLocks['exclusive'][$path]);
         if (!isset($this->acquiredLocks['shared'][$path])) {
             $this->acquiredLocks['shared'][$path] = 0;
         }
         $this->acquiredLocks['shared'][$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);
             }
             $this->acquiredLocks['exclusive'][$path] = true;
             $this->acquiredLocks['shared'][$path]--;
         }
     }
 }
 public function tearDown()
 {
     $this->memcache->clear();
     parent::tearDown();
 }