From a29ee00f1a6ac53425295d7d6c52c8b93f937ff5 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 14 Dec 2012 13:06:39 -0800 Subject: [PATCH] [LockManager] Moved ScopedLock to its own file. Change-Id: I7430604d3a23a25e8b82036b022336a73cbbc996 --- includes/AutoLoader.php | 2 +- .../filebackend/lockmanager/LockManager.php | 66 -------------- .../filebackend/lockmanager/ScopedLock.php | 89 +++++++++++++++++++ 3 files changed, 90 insertions(+), 67 deletions(-) create mode 100644 includes/filebackend/lockmanager/ScopedLock.php diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index bd996a2f2b..05929d2219 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -563,7 +563,7 @@ $wgAutoloadLocalClasses = array( 'NullFileJournal' => 'includes/filebackend/filejournal/FileJournal.php', 'LockManagerGroup' => 'includes/filebackend/lockmanager/LockManagerGroup.php', 'LockManager' => 'includes/filebackend/lockmanager/LockManager.php', - 'ScopedLock' => 'includes/filebackend/lockmanager/LockManager.php', + 'ScopedLock' => 'includes/filebackend/lockmanager/ScopedLock.php', 'FSLockManager' => 'includes/filebackend/lockmanager/FSLockManager.php', 'DBLockManager' => 'includes/filebackend/lockmanager/DBLockManager.php', 'LSLockManager' => 'includes/filebackend/lockmanager/LSLockManager.php', diff --git a/includes/filebackend/lockmanager/LockManager.php b/includes/filebackend/lockmanager/LockManager.php index 07853f8757..51454a4f85 100644 --- a/includes/filebackend/lockmanager/LockManager.php +++ b/includes/filebackend/lockmanager/LockManager.php @@ -122,72 +122,6 @@ abstract class LockManager { abstract protected function doUnlock( array $paths, $type ); } -/** - * Self-releasing locks - * - * LockManager helper class to handle scoped locks, which - * release when an object is destroyed or goes out of scope. - * - * @ingroup LockManager - * @since 1.19 - */ -class ScopedLock { - /** @var LockManager */ - protected $manager; - /** @var Status */ - protected $status; - /** @var Array List of resource paths*/ - protected $paths; - - protected $type; // integer lock type - - /** - * @param $manager LockManager - * @param $paths Array List of storage paths - * @param $type integer LockManager::LOCK_* constant - * @param $status Status - */ - protected function __construct( - LockManager $manager, array $paths, $type, Status $status - ) { - $this->manager = $manager; - $this->paths = $paths; - $this->status = $status; - $this->type = $type; - } - - /** - * Get a ScopedLock object representing a lock on resource paths. - * Any locks are released once this object goes out of scope. - * The status object is updated with any errors or warnings. - * - * @param $manager LockManager - * @param $paths Array List of storage paths - * @param $type integer LockManager::LOCK_* constant - * @param $status Status - * @return ScopedLock|null Returns null on failure - */ - public static function factory( - LockManager $manager, array $paths, $type, Status $status - ) { - $lockStatus = $manager->lock( $paths, $type ); - $status->merge( $lockStatus ); - if ( $lockStatus->isOK() ) { - return new self( $manager, $paths, $type, $status ); - } - return null; - } - - function __destruct() { - $wasOk = $this->status->isOK(); - $this->status->merge( $this->manager->unlock( $this->paths, $this->type ) ); - if ( $wasOk ) { - // Make sure status is OK, despite any unlockFiles() fatals - $this->status->setResult( true, $this->status->value ); - } - } -} - /** * Version of LockManager that uses a quorum from peer servers for locks. * The resource space can also be sharded into separate peer groups. diff --git a/includes/filebackend/lockmanager/ScopedLock.php b/includes/filebackend/lockmanager/ScopedLock.php new file mode 100644 index 0000000000..5a80bee8b3 --- /dev/null +++ b/includes/filebackend/lockmanager/ScopedLock.php @@ -0,0 +1,89 @@ +manager = $manager; + $this->paths = $paths; + $this->status = $status; + $this->type = $type; + } + + /** + * Get a ScopedLock object representing a lock on resource paths. + * Any locks are released once this object goes out of scope. + * The status object is updated with any errors or warnings. + * + * @param $manager LockManager + * @param $paths Array List of storage paths + * @param $type integer LockManager::LOCK_* constant + * @param $status Status + * @return ScopedLock|null Returns null on failure + */ + public static function factory( + LockManager $manager, array $paths, $type, Status $status + ) { + $lockStatus = $manager->lock( $paths, $type ); + $status->merge( $lockStatus ); + if ( $lockStatus->isOK() ) { + return new self( $manager, $paths, $type, $status ); + } + return null; + } + + function __destruct() { + $wasOk = $this->status->isOK(); + $this->status->merge( $this->manager->unlock( $this->paths, $this->type ) ); + if ( $wasOk ) { + // Make sure status is OK, despite any unlockFiles() fatals + $this->status->setResult( true, $this->status->value ); + } + } +} -- 2.20.1