From b18dd6ebb0b1b16aaa4004397be44c82df3aa8d0 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 28 Jun 2019 16:56:16 -0700 Subject: [PATCH] lockmanager: make NullLockManager do reference counting for consistency Change-Id: I9ebdad0544ffcf87e671f4aca81a91e377c2c7ed --- includes/libs/lockmanager/NullLockManager.php | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/includes/libs/lockmanager/NullLockManager.php b/includes/libs/lockmanager/NullLockManager.php index b83462c798..339a7ee43a 100644 --- a/includes/libs/lockmanager/NullLockManager.php +++ b/includes/libs/lockmanager/NullLockManager.php @@ -22,15 +22,38 @@ */ /** - * Simple version of LockManager that does nothing + * Simple version of LockManager that only does lock reference counting * @since 1.19 */ class NullLockManager extends LockManager { protected function doLock( array $paths, $type ) { + foreach ( $paths as $path ) { + if ( isset( $this->locksHeld[$path][$type] ) ) { + ++$this->locksHeld[$path][$type]; + } else { + $this->locksHeld[$path][$type] = 1; + } + } + return StatusValue::newGood(); } protected function doUnlock( array $paths, $type ) { - return StatusValue::newGood(); + $status = StatusValue::newGood(); + + foreach ( $paths as $path ) { + if ( isset( $this->locksHeld[$path][$type] ) ) { + if ( --$this->locksHeld[$path][$type] <= 0 ) { + unset( $this->locksHeld[$path][$type] ); + if ( !$this->locksHeld[$path] ) { + unset( $this->locksHeld[$path] ); // clean up + } + } + } else { + $status->warning( 'lockmanager-notlocked', $path ); + } + } + + return $status; } } -- 2.20.1