Jamm\Memory\Shm\SingleMemory::lock_key PHP Метод

lock_key() публичный Метод

Get exclusive mutex for key. Key will be still accessible to read and write, but another process can exclude dog-pile effect, if before updating the key he will try to get this mutex.
public lock_key ( mixed $key, mixed &$auto_unlocker_variable )
$key mixed
$auto_unlocker_variable mixed - pass empty, just declared variable
    public function lock_key($key, &$auto_unlocker_variable)
    {
        $auto_unlocker = NULL;
        if (!$this->sem->get_access_write($auto_unlocker)) {
            return false;
        }
        $this->readmemory();
        $key = (string) $key;
        if (isset($this->mem[self::map_key_locks][$key])) {
            return false;
        }
        $this->mem[self::map_key_locks][$key] = 1;
        if ($this->refresh()) {
            $auto_unlocker_variable = new \Jamm\Memory\KeyAutoUnlocker(array($this, 'unlock_key'));
            $auto_unlocker_variable->setKey($key);
            return true;
        } else {
            return false;
        }
    }