Merge "Drop zh-tw message "saveprefs""
[lhc/web/wiklou.git] / includes / poolcounter / PoolCounterRedis.php
index d609f61..d7357cf 100644 (file)
@@ -76,7 +76,7 @@ class PoolCounterRedis extends PoolCounter {
        const AWAKE_ONE = 1; // wake-up if when a slot can be taken from an existing process
        const AWAKE_ALL = 2; // wake-up if an existing process finishes and wake up such others
 
-       /** @var array List of active PoolCounterRedis objects in this script */
+       /** @var PoolCounterRedis[] List of active PoolCounterRedis objects in this script */
        protected static $active = null;
 
        function __construct( $conf, $type, $key ) {
@@ -121,20 +121,24 @@ class PoolCounterRedis extends PoolCounter {
        }
 
        function acquireForMe() {
-               $section = new ProfileSection( __METHOD__ );
+               $status = $this->precheckAcquire();
+               if ( !$status->isGood() ) {
+                       return $status;
+               }
 
                return $this->waitForSlotOrNotif( self::AWAKE_ONE );
        }
 
        function acquireForAnyone() {
-               $section = new ProfileSection( __METHOD__ );
+               $status = $this->precheckAcquire();
+               if ( !$status->isGood() ) {
+                       return $status;
+               }
 
                return $this->waitForSlotOrNotif( self::AWAKE_ALL );
        }
 
        function release() {
-               $section = new ProfileSection( __METHOD__ );
-
                if ( $this->slot === null ) {
                        return Status::newGood( PoolCounter::NOT_LOCKED ); // not locked
                }
@@ -183,7 +187,7 @@ class PoolCounterRedis extends PoolCounter {
                return 1
 LUA;
                try {
-                       $res = $conn->luaEval( $script,
+                       $conn->luaEval( $script,
                                array(
                                        $this->getSlotListKey(),
                                        $this->getSlotRTimeSetKey(),
@@ -207,6 +211,8 @@ LUA;
                $this->onRelease = null;
                unset( self::$active[$this->session] );
 
+               $this->onRelease();
+
                return Status::newGood( PoolCounter::RELEASED );
        }
 
@@ -266,6 +272,8 @@ LUA;
                        self::$active[$this->session] = $this;
                }
 
+               $this->onAcquire();
+
                return Status::newGood( $slot === 'w' ? PoolCounter::DONE : PoolCounter::LOCKED );
        }