mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-12-13 16:58:26 +00:00
cb39fead91
Change-Id: Idb7ff848ba702eac2cde31c6198a70311e3bdb69
62 lines
1.4 KiB
PHP
62 lines
1.4 KiB
PHP
<?php
|
|
|
|
class Scribunto_LuaStandaloneInterpreterFunction {
|
|
/** @var bool[] */
|
|
public static $anyChunksDestroyed = [];
|
|
/** @var int[][] */
|
|
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;
|
|
}
|
|
}
|
|
}
|