mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 01:46:04 +00:00
Yay generation uses async tasks
This commit is contained in:
@ -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;
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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){
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user