/** * @param string $key * @param string $storageName * @param boolean $keyAutoConvert * @return Mutex */ public function create($key, $storageName = null, $keyAutoConvert = true) { if ($keyAutoConvert) { $key = $this->makeMutexKey($key); } if (preg_match('/[^0-9a-zA-z_]/um', $key) || strlen($key) > 250) { throw new WrongNameMutexException($key); } $mutex = $this->registry->get($key); if ($mutex === null) { if ($storageName === null) { if (empty($this->storages)) { throw new NoStorageMutexException(); } $storage = reset($this->storages); } else { if (!isset($this->storages[$storageName])) { throw new StorageNotFoundMutexException($storageName); } $storage = $this->storages[$storageName]; } $mutex = new Mutex($key, $this->registry, $storage); $this->registry->add($key, $mutex); } return $mutex; }
public function free() { $this->checkFreeState(); $this->registry->remove($this->key, $this); $this->free = true; }