/** * @return bool */ public function unlock() { $released = sem_release($this->lock); sem_remove($this->lock); $this->lock = null; return $released; }
/** * Tests removing semaphore fails. * * @test * @expectedException bandwidthThrottle\tokenBucket\storage\StorageException * @expectedExceptionMessage Could not remove semaphore. */ public function testfailRemovingSemaphore() { $key = ftok(__FILE__, "a"); $storage = new IPCStorage($key); sem_remove(sem_get($key)); @$storage->remove(); }
public static function store($key, $value) { self::getHandle(); if (!shm_put_var(self::$handle, self::getVarKey($key), $value)) { sem_remove(self::$semaphore); shm_remove(self::$handle); die('couldn\'t write to shared memory.'); } self::release(); }
function drop($key) { try { return sem_remove($this->locks[$key]); } catch (ExecutionContextException $e) { unset($this->locks[$key]); // already race-removed return false; } }
public function remove() { if (!shm_remove($this->memory)) { throw new StorageException("Could not release shared memory."); } $this->memory = null; if (!sem_remove($this->semaphore)) { throw new StorageException("Could not remove semaphore."); } $this->semaphore = null; }
public function drop($key) { if (isset($this->pool[$key])) { try { return sem_remove($this->pool[$key]); } catch (BaseException $e) { unset($this->pool[$key]); // already race-removed return false; } } return null; }
function delete() { if ($this->shm) { sem_acquire($this->sem()); try { $this->shm->delete(); sem_release($this->sem()); } catch (Exception $e) { sem_release($this->sem()); } } $this->logger->debug(sprintf("Delete semaphore (key: 0x%08x)", $this->semKey)); sem_remove($this->sem()); if (isset($e)) { throw $e; } }
function setUniqueValue($value, $user, $userid = 0) { $conn = create_db_connection(); $key = md5($value . ":unique-value:" . $user); $sem = 0; if (function_exists("sem_get")) { $sem = sem_get(ftok(realpath("config/upload.php"), 'R')); sem_acquire($sem); } $conn->openselect("select * from " . getUserConfig("dbprefix") . "uniquevalues where md5='" . $key . "' and user='******' and userid=0" . intval($userid)); if ($conn->eof()) { $conn->execute("insert into " . getUserConfig("dbprefix") . "uniquevalues(md5,util,user,userid) values('" . $conn->escape($key) . "','" . $conn->escape($value) . "','" . $conn->escape($user) . "',0" . intval($userid) . ")"); } else { resetUniqueValue($key, $value, $user, $userid); } if ($sem) { sem_release($sem); sem_remove($sem); } $conn->close(); return $key; }
/** * Release the lock * * @return boolean Returns TRUE on success or FALSE on failure */ public function release() { if (!$this->isAcquired) { return TRUE; } $success = TRUE; switch ($this->method) { case 'simple': if (unlink($this->resource) == FALSE) { $success = FALSE; } break; case 'flock': if (flock($this->filepointer, LOCK_UN) == FALSE) { $success = FALSE; } fclose($this->filepointer); unlink($this->resource); break; case 'semaphore': if (@sem_release($this->resource)) { sem_remove($this->resource); } else { $success = FALSE; } break; case 'disable': $success = FALSE; break; } $this->isAcquired = FALSE; return $success; }
/** * Destroys the resource associated with the lock * * @return void */ public function destroy() { if ($this->resource) { sem_remove($this->resource); @unlink($this->filePath); } }
public static function unlock($semId) { sem_release($semId); sem_remove($semId); }
/** * Force release */ public function destroy() { sem_remove($this->__mutex); shm_remove($this->__shm); }
public function __destruct() { foreach ($this->activeMegaListeners as $listener) { $this->megaApi->removeListener($listener); } foreach ($this->activeMegaRequestListeners as $listener) { $this->megaApi->removeRequestListener($listener); } foreach ($this->activeMegaTransferListeners as $listener) { $this->megaApi->removeTransferListener($listener); } foreach ($this->activeMegaGlobalListeners as $listener) { $this->megaApi->removeGlobalListener($listener); } sem_remove($this->semaphore); }
/** * Release the lock * * @return boolean Returns TRUE on success or FALSE on failure */ public function release() { if (!$this->isAcquired) { return TRUE; } $success = TRUE; switch ($this->method) { case 'flock': if (flock($this->filepointer, LOCK_UN) == FALSE) { $success = FALSE; } fclose($this->filepointer); //if (\TYPO3\CMS\Core\Utility\GeneralUtility::isAllowedAbsPath($this->resource) && \TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($this->resource, PATH_site . 'typo3temp'.DIRECTORY_SEPARATOR.'extbase_hijax'.DIRECTORY_SEPARATOR.'locks'.DIRECTORY_SEPARATOR)) { // TODO: add a scheduler task to remove old lock files // unlink($this->resource); //} break; case 'semaphore': if (@sem_release($this->resource)) { sem_remove($this->resource); } else { $success = FALSE; } break; case 'disable': $success = FALSE; break; } $this->isAcquired = FALSE; return $success; }
/** * Release all resource after process end * Call by destruct * * @return void */ protected function __release() { // release global space for vars $this->global->remove(); // release shared space for vars $this->shared->remove(); // remove mutex for lock @sem_remove($this->mutex); }
/** * Destroy every resource and wait for zombies. */ protected function destroyAndWaitForChildren() { msg_remove_queue($this->getQueueManager()); sem_remove($this->getLockManager()); for ($i = 0; $i <= $this->childNumber; $i++) { pcntl_wait($status); } }
/** * When the parent process exits, cleans shared memory and semaphore. * * This is called using 'register_shutdown_function' pattern. * @see http://php.net/register_shutdown_function */ public function onShutdown() { if (posix_getpid() == $this->_nParentPid) { $this->_log('INFO: Parent shutdown, cleaning memory...'); @shm_remove($this->_hShm) && @shm_detach($this->_hShm); @sem_remove($this->_hSem); } }
/** * {@inheritdoc} * @see Scalr_System_Cronjob_MultiProcess_DefaultWorker::endForking() */ function endForking() { $this->lastCleanup->delete(); sem_remove($this->cleanupSem); }
/** * Destructor: * Releases lock automatically when instance is destroyed and release resources */ public function __destruct() { $this->release(); switch ($this->method) { case self::LOCKING_METHOD_FLOCK: if (GeneralUtility::isAllowedAbsPath($this->resource) && GeneralUtility::isFirstPartOfStr($this->resource, PATH_site . self::FILE_LOCK_FOLDER)) { @unlink($this->resource); } break; case self::LOCKING_METHOD_SEMAPHORE: @sem_remove($this->resource); break; default: // do nothing } }
public function remove() { sem_remove($this->semaphore); }
function delete() { $this->logger->debug(sprintf("Delete shm set (key: 0x%08x)", $this->shm->key)); if (!sem_acquire($this->sem)) { throw new Scalr_System_Ipc_Exception("Cannot acquire semaphore"); } try { $this->shm->delete(); unset($this->shm); } catch (Exception $ignore) { } sem_release($this->sem); sem_remove($this->sem); }
/** * Cleans up the crawler after it has finished. */ protected function cleanup() { $abort_reason = $this->checkForAbort(); if ($abort_reason != null && $abort_reason != PHPCrawlerAbortReasons::ABORTREASON_PASSEDTHROUGH) { $crawler_status = $this->CrawlerStatusHandler->getCrawlerStatus(); $crawler_status->documents_received = 0; $crawler_status->bytes_received = 0; $crawler_status->links_followed = 0; $crawler_status->previous_abort_reason = $abort_reason; $crawler_status->abort_reason = null; $this->CrawlerStatusHandler->setCrawlerStatus($crawler_status); } else { // Free/unlock caches $this->CookieCache->cleanup(); $this->LinkCache->cleanup(); // Delete working-dir PHPCrawlerUtils::rmDir($this->working_directory); // Remove semaphore (if multiprocess-mode) if ($this->multiprocess_mode != PHPCrawlerMultiProcessModes::MPMODE_NONE) { $sem_key = sem_get($this->crawler_uniqid); sem_remove($sem_key); } } }
/** * Removes and detaches shared memory * * @access private * @return boolean */ private function RemoveSharedMem() { if (isset($this->mutexid) && $this->mutexid !== false && (isset($this->memid) && $this->memid !== false)) { @sem_acquire($this->mutexid); $memid = $this->memid; $this->memid = false; @sem_release($this->mutexid); @sem_remove($this->mutexid); @shm_remove($memid); @shm_detach($memid); $this->mutexid = false; return true; } return false; }
/** * Cleans up the crawler after it has finished. */ protected function cleanup() { // Delete working-dir PHPCrawlerUtils::rmDir($this->working_directory); // Remove semaphore (if multiprocess-mode) if ($this->multiprocess_mode != PHPCrawlerMultiProcessModes::MPMODE_NONE) { $sem_key = sem_get($this->crawler_uniqid); sem_remove($sem_key); } }
function remove() { sem_remove($this->sem_id); }
$sem = sem_get($key); for ($i = 0; $i < 2; $i++) { $pid = pcntl_fork(); if ($pid < 0) { die("fork failed"); } elseif ($pid > 0) { //echo "parent process \n"; } else { echo "child process {$i} is born. \n"; obtainLock($sem, $i); } } while (pcntl_waitpid(0, $status) != -1) { $status = pcntl_wexitstatus($status); echo "Child {$status} completed\n"; } sem_remove($sem); // finally remove the sem function obtainLock($sem, $i) { echo "process {$i} is getting the sem \n"; $res = sem_acquire($sem, true); sleep(1); if (!$res) { echo "process {$i} unable to get sem. \n"; } else { echo "process {$i} successfully got the sem \n"; sem_release($sem); } exit; }
function free_db_access() { global $ZBX_SEM_ID; if ($ZBX_SEM_ID && function_exists('sem_remove')) { sem_remove($ZBX_SEM_ID); } $ZBX_SEM_ID = false; }
/** * Removes a semaphore * * After removing the semaphore, it is no longer accessible. */ public function remove() { if (is_resource($this->handle)) { sem_remove($this->handle); $this->handle = null; } }
function shmop_write_with_lock($shm_id, $sem_id, $s, $offset = 0) { //Acquire the semaphore if (!sem_acquire($sem_id)) { //If not available this will stall until the semaphore is released by the other process logformat("Failed to acquire shared memory semaphore!\n"); sem_remove($sem_id); //Use even if we didn't create the semaphore as something has gone wrong and its usually debugging so lets no lock up this semaphore key exit(1); } shmop_write($shm_id, $s, $offset); //Release the semaphore if (!sem_release($sem_id)) { //Must be called after sem_acquire() so that another process can acquire the semaphore logformat("Failed to release shared memory semaphore!\n"); } }
/** * Remove the semaphore created. * @return true on successful removal otherwise false */ public function remove() { return !is_null($this->semaphore->get_sem_res()) && strncmp(gettype($this->semaphore->get_sem_res()), "resource", 8) == 0 ? sem_remove($this->semaphore->get_sem_res()) : true; }