Improved chunk sending, moved chunk encoding and compression to another thread

This commit is contained in:
Shoghi Cervantes
2014-07-05 20:41:30 +02:00
parent 417cb94ea3
commit 22552cdd72
9 changed files with 253 additions and 85 deletions

View File

@ -29,36 +29,49 @@ use pocketmine\Server;
*/
abstract class AsyncTask extends \Threaded{
private $complete;
private $finished;
private $result;
private $complete = null;
private $finished = null;
private $result = null;
public function run(){
$this->lock();
$this->finished = false;
$this->complete = false;
$this->result = null;
$this->unlock();
$this->onRun();
$this->lock();
$this->finished = true;
$this->unlock();
}
/**
* @return bool
*/
public function isFinished(){
return $this->synchronized(function(){
return $this->finished === true;
});
return $this->finished === true;
}
/**
* @return bool
*/
public function isCompleted(){
return $this->complete === true;
}
public function setCompleted(){
$this->complete = true;
}
/**
* @return mixed
*/
public function getResult(){
return $this->synchronized(function (){
$this->finished = true;
return @unserialize($this->result);
});
return @unserialize($this->result);
}
/**

View File

@ -215,12 +215,12 @@ class ServerScheduler{
if($this->asyncTasks > 0){ //Garbage collector
$this->asyncPool->collect(function (AsyncTask $task){
if($task->isFinished()){
if($task->isFinished() and !$task->isCompleted()){
--$this->asyncTasks;
$task->onCompletion(Server::getInstance());
$task->setCompleted();
return true;
}
return false;
});
}