mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-29 06:05:54 +00:00
Thread/Worker run() are now final, to set up common environment things
This commit is contained in:
parent
e07f3e8e65
commit
44c791f03e
@ -23,6 +23,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine;
|
namespace pocketmine;
|
||||||
|
|
||||||
|
use function error_reporting;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class must be extended by all custom threading classes
|
* This class must be extended by all custom threading classes
|
||||||
*/
|
*/
|
||||||
@ -73,6 +75,19 @@ abstract class Thread extends \Thread{
|
|||||||
return parent::start($options);
|
return parent::start($options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final public function run() : void{
|
||||||
|
error_reporting(-1);
|
||||||
|
$this->registerClassLoader();
|
||||||
|
//set this after the autoloader is registered
|
||||||
|
\ErrorUtils::setErrorExceptionHandler();
|
||||||
|
$this->onRun();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs code on the thread.
|
||||||
|
*/
|
||||||
|
abstract protected function onRun() : void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops the thread using the best way possible. Try to stop it yourself before calling this.
|
* Stops the thread using the best way possible. Try to stop it yourself before calling this.
|
||||||
*/
|
*/
|
||||||
|
@ -23,6 +23,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine;
|
namespace pocketmine;
|
||||||
|
|
||||||
|
use function error_reporting;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class must be extended by all custom threading classes
|
* This class must be extended by all custom threading classes
|
||||||
*/
|
*/
|
||||||
@ -73,6 +75,17 @@ abstract class Worker extends \Worker{
|
|||||||
return parent::start($options);
|
return parent::start($options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final public function run() : void{
|
||||||
|
error_reporting(-1);
|
||||||
|
$this->registerClassLoader();
|
||||||
|
$this->onRun();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs code on the thread.
|
||||||
|
*/
|
||||||
|
abstract protected function onRun() : void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops the thread using the best way possible. Try to stop it yourself before calling this.
|
* Stops the thread using the best way possible. Try to stop it yourself before calling this.
|
||||||
*/
|
*/
|
||||||
|
@ -184,9 +184,7 @@ class CommandReader extends Thread{
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run() : void{
|
protected function onRun() : void{
|
||||||
$this->registerClassLoader();
|
|
||||||
|
|
||||||
if($this->type !== self::TYPE_READLINE){
|
if($this->type !== self::TYPE_READLINE){
|
||||||
$this->initStdin();
|
$this->initStdin();
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ namespace pocketmine\scheduler;
|
|||||||
|
|
||||||
use pocketmine\utils\MainLogger;
|
use pocketmine\utils\MainLogger;
|
||||||
use pocketmine\Worker;
|
use pocketmine\Worker;
|
||||||
use function error_reporting;
|
|
||||||
use function gc_enable;
|
use function gc_enable;
|
||||||
use function ini_set;
|
use function ini_set;
|
||||||
|
|
||||||
@ -45,14 +44,7 @@ class AsyncWorker extends Worker{
|
|||||||
$this->memoryLimit = $memoryLimit;
|
$this->memoryLimit = $memoryLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run() : void{
|
protected function onRun() : void{
|
||||||
error_reporting(-1);
|
|
||||||
|
|
||||||
$this->registerClassLoader();
|
|
||||||
|
|
||||||
//set this after the autoloader is registered
|
|
||||||
\ErrorUtils::setErrorExceptionHandler();
|
|
||||||
|
|
||||||
\GlobalLogger::set($this->logger);
|
\GlobalLogger::set($this->logger);
|
||||||
if($this->logger instanceof MainLogger){
|
if($this->logger instanceof MainLogger){
|
||||||
$this->logger->registerStatic();
|
$this->logger->registerStatic();
|
||||||
|
@ -38,8 +38,7 @@ class ServerKiller extends Thread{
|
|||||||
$this->time = $time;
|
$this->time = $time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run() : void{
|
protected function onRun() : void{
|
||||||
$this->registerClassLoader();
|
|
||||||
$start = time();
|
$start = time();
|
||||||
$this->synchronized(function(){
|
$this->synchronized(function(){
|
||||||
if(!$this->stopped){
|
if(!$this->stopped){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user