mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-12-10 23:46:10 +00:00
9facd741cc
composer: * mediawiki/mediawiki-codesniffer: 29.0.0 → 30.0.0 npm: * eslint-config-wikimedia: 0.15.0 → 0.15.3 * grunt-stylelint: 0.14.0 → 0.15.0 * stylelint-config-wikimedia: 0.9.0 → 0.10.1 Change-Id: I684372efb0248862700184546a5172bfd6d81ae0
60 lines
1.4 KiB
PHP
60 lines
1.4 KiB
PHP
<?php
|
|
|
|
class Scribunto_LuaStandaloneInterpreterFunction {
|
|
public static $anyChunksDestroyed = [];
|
|
public static $activeChunkIds = [];
|
|
|
|
/**
|
|
* @var int
|
|
*/
|
|
public $interpreterId;
|
|
|
|
/**
|
|
* @var int
|
|
*/
|
|
public $id;
|
|
|
|
/**
|
|
* @param int $interpreterId
|
|
* @param int $id
|
|
*/
|
|
public function __construct( $interpreterId, $id ) {
|
|
$this->interpreterId = $interpreterId;
|
|
$this->id = $id;
|
|
$this->incrementRefCount();
|
|
}
|
|
|
|
public function __clone() {
|
|
$this->incrementRefCount();
|
|
}
|
|
|
|
public function __wakeup() {
|
|
$this->incrementRefCount();
|
|
}
|
|
|
|
public function __destruct() {
|
|
$this->decrementRefCount();
|
|
}
|
|
|
|
private function incrementRefCount() {
|
|
if ( !isset( self::$activeChunkIds[$this->interpreterId] ) ) {
|
|
self::$activeChunkIds[$this->interpreterId] = [ $this->id => 1 ];
|
|
} elseif ( !isset( self::$activeChunkIds[$this->interpreterId][$this->id] ) ) {
|
|
self::$activeChunkIds[$this->interpreterId][$this->id] = 1;
|
|
} else {
|
|
self::$activeChunkIds[$this->interpreterId][$this->id]++;
|
|
}
|
|
}
|
|
|
|
private function decrementRefCount() {
|
|
if ( isset( self::$activeChunkIds[$this->interpreterId][$this->id] ) ) {
|
|
if ( --self::$activeChunkIds[$this->interpreterId][$this->id] <= 0 ) {
|
|
unset( self::$activeChunkIds[$this->interpreterId][$this->id] );
|
|
self::$anyChunksDestroyed[$this->interpreterId] = true;
|
|
}
|
|
} else {
|
|
self::$anyChunksDestroyed[$this->interpreterId] = true;
|
|
}
|
|
}
|
|
}
|