Updated to new pthreads version, updated RakLib

This commit is contained in:
Shoghi Cervantes 2015-09-27 13:37:27 +02:00
parent 0bcf639a98
commit ddc140af5e
10 changed files with 33 additions and 26 deletions

View File

@ -474,8 +474,6 @@ namespace pocketmine {
$logger->shutdown(); $logger->shutdown();
$logger->join(); $logger->join();
$killer->kill();
echo Terminal::$FORMAT_RESET . "\n"; echo Terminal::$FORMAT_RESET . "\n";
exit(0); exit(0);

View File

@ -1970,7 +1970,7 @@ class Server{
$this->getLogger()->debug("Closing console"); $this->getLogger()->debug("Closing console");
$this->console->shutdown(); $this->console->shutdown();
$this->console->kill(); $this->console->notify();
$this->getLogger()->debug("Stopping network interfaces"); $this->getLogger()->debug("Stopping network interfaces");
foreach($this->network->getInterfaces() as $interface){ foreach($this->network->getInterfaces() as $interface){

View File

@ -28,6 +28,7 @@ abstract class Thread extends \Thread{
/** @var \ClassLoader */ /** @var \ClassLoader */
protected $classLoader; protected $classLoader;
protected $isKilled = false;
public function getClassLoader(){ public function getClassLoader(){
return $this->classLoader; return $this->classLoader;
@ -68,16 +69,14 @@ abstract class Thread extends \Thread{
* 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.
*/ */
public function quit(){ public function quit(){
if($this->isRunning()){ $this->isKilled = true;
$this->kill();
}elseif(!$this->isJoined()){ $this->notify();
if(!$this->isJoined()){
if(!$this->isTerminated()){ if(!$this->isTerminated()){
$this->join(); $this->join();
}else{
$this->kill();
} }
}else{
$this->kill();
} }
ThreadManager::getInstance()->remove($this); ThreadManager::getInstance()->remove($this);

View File

@ -42,7 +42,7 @@ class ThreadManager extends \Volatile{
*/ */
public function add($thread){ public function add($thread){
if($thread instanceof Thread or $thread instanceof Worker){ if($thread instanceof Thread or $thread instanceof Worker){
$this->{$thread->getThreadId()} = $thread; $this->{spl_object_hash($thread)} = $thread;
} }
} }
@ -51,7 +51,7 @@ class ThreadManager extends \Volatile{
*/ */
public function remove($thread){ public function remove($thread){
if($thread instanceof Thread or $thread instanceof Worker){ if($thread instanceof Thread or $thread instanceof Worker){
unset($this->{$thread->getThreadId()}); unset($this->{spl_object_hash($thread)});
} }
} }

View File

@ -29,6 +29,8 @@ abstract class Worker extends \Worker{
/** @var \ClassLoader */ /** @var \ClassLoader */
protected $classLoader; protected $classLoader;
protected $isKilled = false;
public function getClassLoader(){ public function getClassLoader(){
return $this->classLoader; return $this->classLoader;
} }
@ -68,17 +70,18 @@ abstract class Worker extends \Worker{
* 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.
*/ */
public function quit(){ public function quit(){
$this->isKilled = true;
$this->notify();
if($this->isRunning()){ if($this->isRunning()){
$this->shutdown();
$this->notify();
$this->unstack(); $this->unstack();
$this->kill();
}elseif(!$this->isJoined()){ }elseif(!$this->isJoined()){
if(!$this->isTerminated()){ if(!$this->isTerminated()){
$this->join(); $this->join();
}else{
$this->kill();
} }
}else{
$this->kill();
} }
ThreadManager::getInstance()->remove($this); ThreadManager::getInstance()->remove($this);

View File

@ -87,6 +87,10 @@ class PluginLogger implements \AttachableLogger{
$this->log(LogLevel::DEBUG, $message); $this->log(LogLevel::DEBUG, $message);
} }
public function logException(\Throwable $e, $trace = null){
Server::getInstance()->getLogger()->logException($e, $trace);
}
public function log($level, $message){ public function log($level, $message){
Server::getInstance()->getLogger()->log($level, $this->pluginName . $message); Server::getInstance()->getLogger()->log($level, $this->pluginName . $message);
foreach($this->attachments as $attachment){ foreach($this->attachments as $attachment){

View File

@ -47,7 +47,7 @@ class AsyncPool{
for($i = 0; $i < $this->size; ++$i){ for($i = 0; $i < $this->size; ++$i){
$this->workerUsage[$i] = 0; $this->workerUsage[$i] = 0;
$this->workers[$i] = new AsyncWorker($this->server->getLogger(), $i); $this->workers[$i] = new AsyncWorker($this->server->getLogger(), $i + 1);
$this->workers[$i]->setClassLoader($this->server->getLoader()); $this->workers[$i]->setClassLoader($this->server->getLoader());
$this->workers[$i]->start(); $this->workers[$i]->start();
} }
@ -62,7 +62,7 @@ class AsyncPool{
if($newSize > $this->size){ if($newSize > $this->size){
for($i = $this->size; $i < $newSize; ++$i){ for($i = $this->size; $i < $newSize; ++$i){
$this->workerUsage[$i] = 0; $this->workerUsage[$i] = 0;
$this->workers[$i] = new AsyncWorker($this->server->getLogger(), $i); $this->workers[$i] = new AsyncWorker($this->server->getLogger(), $i + 1);
$this->workers[$i]->setClassLoader($this->server->getLoader()); $this->workers[$i]->setClassLoader($this->server->getLoader());
$this->workers[$i]->start(); $this->workers[$i]->start();
} }

View File

@ -32,11 +32,14 @@ class ServerKiller extends Thread{
} }
public function run(){ public function run(){
$start = time() + 1;
$this->synchronized(function(){ $this->synchronized(function(){
$this->wait($this->time * 1000000); $this->wait($this->time * 1000000);
}); });
echo "\nTook too long to stop, server was killed forcefully!\n"; if(time() - $start >= $this->time){
@\pocketmine\kill(getmypid()); echo "\nTook too long to stop, server was killed forcefully!\n";
@\pocketmine\kill(getmypid());
}
} }
public function getThreadName(){ public function getThreadName(){

@ -1 +1 @@
Subproject commit f6f207b9e47dc6fdb23b9e39dfcbabb545be9cd0 Subproject commit a5cca45a922ca193a616069f885866efc7158c67

@ -1 +1 @@
Subproject commit 3cd1f13c5d4937a5de1978d1950589082df760d2 Subproject commit 6edaf9802cbada5e7638ceadfe042be9921376d8