lockmanager: make NullLockManager do reference counting for consistency
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 28 Jun 2019 23:56:16 +0000 (16:56 -0700)
committerKrinkle <krinklemail@gmail.com>
Tue, 2 Jul 2019 22:06:12 +0000 (22:06 +0000)
Change-Id: I9ebdad0544ffcf87e671f4aca81a91e377c2c7ed

includes/libs/lockmanager/NullLockManager.php

index b83462c..339a7ee 100644 (file)
  */
 
 /**
- * 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;
        }
 }