pmmpthread support

This commit is contained in:
Dylan K. Taylor
2023-05-20 01:29:26 +01:00
parent 8454076235
commit e0630fbb25
24 changed files with 159 additions and 126 deletions

View File

@@ -23,7 +23,11 @@ declare(strict_types=1);
namespace pocketmine\scheduler;
use pmmp\thread\Runnable;
use pmmp\thread\Thread as NativeThread;
use pmmp\thread\ThreadSafeArray;
use pocketmine\thread\NonThreadSafeValue;
use function assert;
use function igbinary_serialize;
use function igbinary_unserialize;
use function is_null;
@@ -54,7 +58,7 @@ use function spl_object_id;
* If you want to store non-thread-safe objects to access when the task completes, store them using
* {@link AsyncTask::storeLocal}.
*/
abstract class AsyncTask extends \ThreadedRunnable{
abstract class AsyncTask extends Runnable{
/**
* @var \ArrayObject|mixed[]|null object hash => mixed data
* @phpstan-var \ArrayObject<int, array<string, mixed>>|null
@@ -63,11 +67,8 @@ abstract class AsyncTask extends \ThreadedRunnable{
*/
private static ?\ArrayObject $threadLocalStorage = null;
/** @var AsyncWorker|null $worker */
public $worker = null;
/** @phpstan-var \ThreadedArray<int, string> */
public \ThreadedArray $progressUpdates;
/** @phpstan-var ThreadSafeArray<int, string> */
public ThreadSafeArray $progressUpdates;
/** @phpstan-var NonThreadSafeValue<mixed>|string|int|bool|float|null */
private NonThreadSafeValue|string|int|bool|null|float $result = null;
@@ -85,12 +86,15 @@ abstract class AsyncTask extends \ThreadedRunnable{
$this->onRun();
}catch(\Throwable $e){
$this->crashed = true;
$this->worker->handleException($e);
\GlobalLogger::get()->logException($e);
}
}
$this->finished = true;
$this->worker->getNotifier()->wakeupSleeper();
$worker = NativeThread::getCurrentThread();
assert($worker instanceof AsyncWorker);
$worker->getNotifier()->wakeupSleeper();
}
public function isCrashed() : bool{