From b98a1236bb829f10ae52966e924b54e3ad89fdbb Mon Sep 17 00:00:00 2001 From: resurtm Date: Tue, 25 Jun 2013 09:08:54 +0600 Subject: [PATCH] Fixes: 1. Proper auto release shutdown callback. 2. Proper Mutex::releaseLock() method. --- extensions/mutex/yii/mutex/Mutex.php | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/extensions/mutex/yii/mutex/Mutex.php b/extensions/mutex/yii/mutex/Mutex.php index c7413a1..9f47501 100644 --- a/extensions/mutex/yii/mutex/Mutex.php +++ b/extensions/mutex/yii/mutex/Mutex.php @@ -33,26 +33,18 @@ abstract class Mutex extends Component public function init() { if ($this->autoRelease) { - $referenceHolder = new stdClass(); - $referenceHolder->mutex = &$this; - $referenceHolder->locks = &$this->_locks; - register_shutdown_function(function ($ref) { - foreach ($ref->locks as $lock) { - $ref->mutex->release($lock); + $references = new stdClass(); + $references->mutex = $this; + $references->locks = &$this->_locks; + register_shutdown_function(function ($refs) { + foreach ($refs->locks as $lock) { + $refs->mutex->release($lock); } - }, $referenceHolder); + }, $references); } } /** - * Never call this method directly under any circumstances. This method is intended for internal use only. - */ - public function shutdownFunction() - { - - } - - /** * @param string $name of the lock to be acquired. Must be unique. * @param integer $timeout to wait for lock to be released. Defaults to zero meaning that method will return * false immediately in case lock was already acquired. @@ -69,14 +61,17 @@ abstract class Mutex extends Component } /** - * Release acquired lock. + * Release acquired lock. This method will return false in case named lock was not found. * @param string $name of the lock to be released. This lock must be already created. - * @return boolean lock release result. + * @return boolean lock release result: false in case named lock was not found.. */ public function releaseLock($name) { if ($this->release($name)) { - unset($this->_locks[array_search($name, $this->_locks)]); + $index = array_search($name, $this->_locks); + if ($index !== false) { + unset($this->_locks[$index]); + } return true; } else { return false;