| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Scribunto\Engines\LuaStandalone; |
| 4 |
|
| 5 |
class LuaStandaloneInterpreterFunction { |
| 6 |
|
| 7 |
public static $anyChunksDestroyed = []; |
| 8 |
|
| 9 |
public static $activeChunkIds = []; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
public $interpreterId; |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
public $id; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
public function __construct( $interpreterId, $id ) { |
| 26 |
$this->interpreterId = $interpreterId; |
| 27 |
$this->id = $id; |
| 28 |
$this->incrementRefCount(); |
| 29 |
} |
| 30 |
|
| 31 |
public function __clone() { |
| 32 |
$this->incrementRefCount(); |
| 33 |
} |
| 34 |
|
| 35 |
public function __wakeup() { |
| 36 |
$this->incrementRefCount(); |
| 37 |
} |
| 38 |
|
| 39 |
public function __destruct() { |
| 40 |
$this->decrementRefCount(); |
| 41 |
} |
| 42 |
|
| 43 |
private function incrementRefCount() { |
| 44 |
if ( !isset( self::$activeChunkIds[$this->interpreterId] ) ) { |
| 45 |
self::$activeChunkIds[$this->interpreterId] = [ $this->id => 1 ]; |
| 46 |
} elseif ( !isset( self::$activeChunkIds[$this->interpreterId][$this->id] ) ) { |
| 47 |
self::$activeChunkIds[$this->interpreterId][$this->id] = 1; |
| 48 |
} else { |
| 49 |
self::$activeChunkIds[$this->interpreterId][$this->id]++; |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
private function decrementRefCount() { |
| 54 |
if ( isset( self::$activeChunkIds[$this->interpreterId][$this->id] ) ) { |
| 55 |
if ( --self::$activeChunkIds[$this->interpreterId][$this->id] <= 0 ) { |
| 56 |
unset( self::$activeChunkIds[$this->interpreterId][$this->id] ); |
| 57 |
self::$anyChunksDestroyed[$this->interpreterId] = true; |
| 58 |
} |
| 59 |
} else { |
| 60 |
self::$anyChunksDestroyed[$this->interpreterId] = true; |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
class_alias( LuaStandaloneInterpreterFunction::class, 'Scribunto_LuaStandaloneInterpreterFunction' ); |