Yay generation uses async tasks

This commit is contained in:
Shoghi Cervantes
2015-03-26 18:21:39 +01:00
parent 668ddeeb13
commit 72c4c01542
18 changed files with 287 additions and 1124 deletions

View File

@ -14,7 +14,7 @@
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
@ -51,6 +51,10 @@ class AsyncPool{
}
}
public function getSize(){
return $this->size;
}
public function submitTask(AsyncTask $task){
if(isset($this->tasks[$task->getTaskId()]) or $task->isGarbage()){
return;

View File

@ -30,6 +30,9 @@ use pocketmine\Server;
*/
abstract class AsyncTask extends \Collectable{
/** @var AsyncWorker $worker */
public $worker = null;
private $result = null;
private $serialized = false;
/** @var int */
@ -83,6 +86,32 @@ abstract class AsyncTask extends \Collectable{
return $this->taskId;
}
/**
* Gets something into the local thread store.
* You have to initialize this in some way from the task on run
*
* @param string $identifier
* @return mixed
*/
public function getFromThreadStore($identifier){
global $store;
return $this->isGarbage() ? null : $store[$identifier];
}
/**
* Saves something into the local thread store.
* This might get deleted at any moment.
*
* @param string $identifier
* @param mixed $value
*/
public function saveToThreadStore($identifier, $value){
global $store;
if(!$this->isGarbage()){
$store[$identifier] = $value;
}
}
/**
* Actions to execute when run
*

View File

@ -38,6 +38,9 @@ class AsyncWorker extends Worker{
require(\pocketmine\PATH . "src/pocketmine/CompatibleClassLoader.php");
}
$this->loader->register(true);
global $store;
$store = [];
}
public function start($options = PTHREADS_INHERIT_NONE){

View File

@ -1,32 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
*
*
*/
namespace pocketmine\scheduler;
class GarbageCollectionTask extends Task{
public function onRun($currentTicks){
gc_collect_cycles();
memory_get_usage();
memory_get_usage(true);
}
}