mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-07 02:21:46 +00:00
Utils: use static property for core count cache, instead of local static variable
This commit is contained in:
parent
222049927a
commit
66cd156d80
@ -109,6 +109,7 @@ final class Utils{
|
|||||||
|
|
||||||
private static ?string $os = null;
|
private static ?string $os = null;
|
||||||
private static ?UuidInterface $serverUniqueId = null;
|
private static ?UuidInterface $serverUniqueId = null;
|
||||||
|
private static ?int $cpuCores = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a readable identifier for the given Closure, including file and line.
|
* Returns a readable identifier for the given Closure, including file and line.
|
||||||
@ -296,14 +297,11 @@ final class Utils{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function getCoreCount(bool $recalculate = false) : int{
|
public static function getCoreCount(bool $recalculate = false) : int{
|
||||||
static $processors = 0;
|
if(self::$cpuCores !== null && !$recalculate){
|
||||||
|
return self::$cpuCores;
|
||||||
if($processors > 0 && !$recalculate){
|
|
||||||
return $processors;
|
|
||||||
}else{
|
|
||||||
$processors = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$processors = 0;
|
||||||
switch(Utils::getOS()){
|
switch(Utils::getOS()){
|
||||||
case Utils::OS_LINUX:
|
case Utils::OS_LINUX:
|
||||||
case Utils::OS_ANDROID:
|
case Utils::OS_ANDROID:
|
||||||
@ -327,7 +325,7 @@ final class Utils{
|
|||||||
$processors = (int) getenv("NUMBER_OF_PROCESSORS");
|
$processors = (int) getenv("NUMBER_OF_PROCESSORS");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return $processors;
|
return self::$cpuCores = $processors;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user