* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Lock\Store; use Symfony\Component\Lock\Exception\InvalidArgumentException; use Symfony\Component\Lock\Exception\LockConflictedException; use Symfony\Component\Lock\Exception\NotSupportedException; use Symfony\Component\Lock\Key; use Symfony\Component\Lock\StoreInterface; /** * SemaphoreStore is a StoreInterface implementation using Semaphore as store engine. * * @author Jérémy Derussé */ class SemaphoreStore implements StoreInterface { /** * Returns whether or not the store is supported. * * @param bool|null $blocking when not null, checked again the blocking mode * * @return bool * * @internal */ public static function isSupported($blocking = null) { if (!extension_loaded('sysvsem')) { return false; } if (false === $blocking && \PHP_VERSION_ID < 50601) { return false; } return true; } public function __construct() { if (!static::isSupported()) { throw new InvalidArgumentException('Semaphore extension (sysvsem) is required'); } } /** * {@inheritdoc} */ public function save(Key $key) { $this->lock($key, false); } /** * {@inheritdoc} */ public function waitAndSave(Key $key) { $this->lock($key, true); } private function lock(Key $key, $blocking) { if ($key->hasState(__CLASS__)) { return; } $resource = sem_get(crc32($key)); if (\PHP_VERSION_ID < 50601) { if (!$blocking) { throw new NotSupportedException(sprintf('The store "%s" does not supports non blocking locks.', get_class($this))); } $acquired = sem_acquire($resource); } else { $acquired = sem_acquire($resource, !$blocking); } if (!$acquired) { throw new LockConflictedException(); } $key->setState(__CLASS__, $resource); } /** * {@inheritdoc} */ public function delete(Key $key) { // The lock is maybe not acquired. if (!$key->hasState(__CLASS__)) { return; } $resource = $key->getState(__CLASS__); sem_release($resource); $key->removeState(__CLASS__); } /** * {@inheritdoc} */ public function putOffExpiration(Key $key, $ttl) { // do nothing, the semaphore locks forever. } /** * {@inheritdoc} */ public function exists(Key $key) { return $key->hasState(__CLASS__); } } __halt_compiler();----SIGNATURE:----tBuqbXr9CmOvb7Du5iUABU5xNpEAgr7D5Cw0+iLzfnYo5gF3mwNfVRWouEQkIFbwR6d0/I9yXCuV8H4E1+ObsLQ2bfMxlIeaBeBmshnL7/pv3G32PJA2H9XZntcrhgRoBVxYExKpGImetMWO0ID/hGfNJzgOkPakkWiXO9FWxKSihIbO6QBvQX3HxJpleuaiXOOXAq+S9GY/fwZ6tljokScdiEzXrkIh+4cOR9HX9L0XzvBNxdwtEi9QuF/CBe/zXq60CyIHCHxZwC1RvKX4DEEPm8uX8UHyVJXB4fMlPaZkWSQqgvJsoaxXVp10a6oZl/tibf1r6oxB3DUKxAkK54sT9F7Q2k+tn/IXfF7Z3ENfmmBuTT/oeDdzu67dhM61qCDy9S2UkKQBtXC2MXR6cPCRPTajFEXO4lDIVtMzEY9gQqR6ylNoCRTy4TIskZctl/xhPi57xX5v080MlGOy7UkUUviSfcOL9Vcw2V9IvoAqdL9SWFldH+L/IiUJgxnv5fRw5G+FbGoCZ5ZQ/0isBf6w9wrFcR08tVQBr+tIz5We/0HxyL9peD+wynLleFcsBJXaFuUcrqxxSy+3fDyXm8L9Fcn4KQo34OrOk8XcC5e+859tzzT9um9hrGybDu+mmSEj62U4GKB4hmJAPDgh/13mPHB8vdM4U/CK8JM8+xk=----ATTACHMENT:----NzMxODEyMjA5MTM1MzEzIDE3MTk3NjEwMDAyNTc0MDYgODMyNjQ4MDg1MDAwMTQ1Mw==