コード例 #1
0
 /**
  * @param string $path
  * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE
  * @throws \OCP\Lock\LockedException
  */
 public function acquireLock($path, $type)
 {
     if ($type === self::LOCK_SHARED) {
         if (!$this->memcache->inc($path)) {
             throw new LockedException($path);
         }
     } else {
         $this->memcache->add($path, 0);
         if (!$this->memcache->cas($path, 0, 'exclusive')) {
             throw new LockedException($path);
         }
     }
     $this->markAcquire($path, $type);
 }
コード例 #2
0
 /**
  * @param string $path
  * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE
  * @throws \OCP\Lock\LockedException
  */
 public function acquireLock($path, $type)
 {
     if ($type === self::LOCK_SHARED) {
         if (!$this->memcache->inc($path)) {
             throw new LockedException($path);
         }
         if (!isset($this->acquiredLocks['shared'][$path])) {
             $this->acquiredLocks['shared'][$path] = 0;
         }
         $this->acquiredLocks['shared'][$path]++;
     } else {
         $this->memcache->add($path, 0);
         if (!$this->memcache->cas($path, 0, 'exclusive')) {
             throw new LockedException($path);
         }
         $this->acquiredLocks['exclusive'][$path] = true;
     }
 }