82 private $isMightWaitKey;
86 private static $acquiredMightWaitKey = 0;
99 $this->workers = $conf[
'workers'];
100 $this->maxqueue = $conf[
'maxqueue'];
101 $this->timeout = $conf[
'timeout'];
102 if ( isset( $conf[
'slots'] ) ) {
103 $this->slots = $conf[
'slots'];
105 $this->fastStale = $conf[
'fastStale'] ??
false;
107 if ( $this->slots ) {
112 $this->isMightWaitKey = !preg_match(
'/^nowait:/', $this->key );
156 if ( $this->isMightWaitKey ) {
157 if ( self::$acquiredMightWaitKey ) {
166 return Status::newFatal(
'poolcounter-usage-error',
167 'You may only aquire a single non-nowait lock.' );
169 } elseif ( $this->timeout !== 0 ) {
170 return Status::newFatal(
'poolcounter-usage-error',
171 'Locks starting in nowait: must have 0 timeout.' );
173 return Status::newGood();
181 self::$acquiredMightWaitKey |= $this->isMightWaitKey;
189 self::$acquiredMightWaitKey &= !$this->isMightWaitKey;
205 return $type .
':' . ( hexdec( substr( sha1(
$key ), 0, 4 ) ) %
$slots );
215 return $this->fastStale;
Semaphore semantics to restrict how many workers may concurrently perform a task.
int $workers
Maximum number of workers working on tasks with the same key simultaneously.
acquireForAnyone( $timeout=null)
I want to do this task, but if anyone else does it instead, it's also fine for me.
onAcquire()
Update any lock tracking information when the lock is acquired.
__construct(array $conf, string $type, string $key)
int $maxqueue
If this number of workers are already working/waiting, fail instead of wait.
isFastStaleEnabled()
Is fast stale mode (T250248) enabled? This may be overridden by the PoolCounterWork subclass.
string $key
All workers with the same key share the lock.
int $slots
Maximum number of workers working on this task type, regardless of key.
hashKeyIntoSlots( $type, $key, $slots)
Given a key (any string) and the number of lots, returns a slot key (a prefix with a suffix integer f...
release()
I have successfully finished my task.
precheckAcquire()
Checks that the lock request is sensible.
acquireForMe( $timeout=null)
I want to do this task and I need to do it myself.
int $timeout
Maximum time in seconds to wait for the lock.
onRelease()
Update any lock tracking information when the lock is released.