208 Commits

Author SHA1 Message Date
Dylan K. Taylor
02b4eeeb9b TaskScheduler: Remove repeating tasks which throw exceptions 2018-05-31 14:10:59 +01:00
Dylan K. Taylor
6b4b4e4bb1 TaskScheduler: remove redundant else branch 2018-05-31 13:01:06 +01:00
Dylan K. Taylor
f2b8d6879f TaskScheduler: remove leftover code that makes no sense
this is impossible now that we have typehints
2018-05-31 12:52:29 +01:00
Dylan K. Taylor
60212cef2f TaskScheduler: adjust disabled scheduler exception 2018-05-31 12:38:36 +01:00
Dylan K. Taylor
15270f8329 Fixed plugin schedulers crashing after disable/reenable 2018-05-31 12:34:22 +01:00
Dylan K. Taylor
05ef13b23a Merge branch 'master' into scheduler-nuke
# Conflicts:
#	src/pocketmine/level/Level.php
2018-05-31 10:40:10 +01:00
Dylan K. Taylor
1b4723d816 AsyncWorker: don't require an attachable logger 2018-05-31 10:34:42 +01:00
Dylan K. Taylor
b3043f9552 Task: remove obsolete doc comment
not anymore sunshine
2018-05-30 21:30:43 +01:00
Dylan K. Taylor
18fdbc2834 TaskScheduler: fix typo in isReady() parameter 2018-05-30 16:45:37 +01:00
Dylan K. Taylor
a8c766be88 Remove TaskHandler dependency on MainLogger
This instead allows the exception to be caught by the scheduler and reported using its logger.
2018-05-30 16:00:25 +01:00
Dylan K. Taylor
e20be3eeba Move task timings responsibility from scheduler to handler 2018-05-30 15:38:39 +01:00
Dylan K. Taylor
51f43fb375 Removed global ServerScheduler - plugins now get their own isolated schedulers
This change breaks pretty much all API pertaining to synchronous task scheduling.

Significant changes:
- Server->getScheduler() has been removed
- Plugin->getScheduler() has been added - every plugin now has its own scheduler
- Because schedulers are now per-plugin, it is now unnecessary for PluginTask to exist because stopping plugin tasks on plugin disable is as simple as destroying the plugin's scheduler. Therefore PluginTask has now been removed and it is expected for things to now use the base Task class instead.

For the most part, plugins will simply need to change Plugin->getServer()->getScheduler()->... to Plugin->getScheduler()->...
Another highlight is that plugin tasks now no longer have global IDs - they are unique to each scheduler.
2018-05-30 14:11:11 +01:00
Dylan K. Taylor
132746aa3d ServerScheduler: Require a Logger instance as ctor param, now non-dependent on Server
yay for unit-testing and reusability!!!
2018-05-30 12:29:19 +01:00
Dylan K. Taylor
d03f36ebee First look at splitting up AsyncPool and ServerScheduler
This commit contains quite a few breaking changes with respect to how AsyncTasks are handled. This is necessary to allow separation of the ServerScheduler and the AsyncPool, because in the future the ServerScheduler may be removed and instead there will be isolated per-plugin sync-task schedulers - but we cannot have every plugin with its own worker pool for memory usage reasons if nothing else.

The following things have changed:
- ServerScheduler: scheduleAsyncTask(), scheduleAsyncTaskToWorker(), getAsyncTaskPoolSize(), increaseAsyncTaskPoolSize() and similar methods have all been removed. Additionally the static \$WORKERS field has been removed.
- Server: added API method getAsyncPool(). This grants you direct access to the server's AsyncPool. Calls to getScheduler()->scheduleAsyncTask() and scheduleAsyncTaskToWorker() should be replaced with getAsyncPool()->submitTask() and submitTaskToWorker() respectively.
2018-05-30 12:20:10 +01:00
Dylan K. Taylor
7fce48d38c AsyncPool: Unstack tasks from workers before entering the below loop 2018-05-30 11:17:16 +01:00
Dylan K. Taylor
81957d133d AsyncTask: Rewrite how thread-local storage works, now non-dependent on Server or ServerScheduler
this implementation was god-awful bad and it was entirely avoidable to make it this complicated.

This utilizes the fact that pthreads treats static properties as thread-local. AsyncTask local storage now utilizes a \SplObjectStorage stored in an AsyncTask private static field.
2018-05-29 19:41:00 +01:00
Dylan K. Taylor
299e4c8a85 ServerScheduler: remove nonsensical condition in addTask()
now that return type declarations exist, it's not possible for this to return a non-Plugin instance.
2018-05-29 18:17:49 +01:00
Dylan K. Taylor
982444949c Fixed typo in AsyncPool
asychronous -> asynchronous
2018-05-26 16:30:49 +01:00
Dylan K. Taylor
6ceb9af749 .-. 2018-05-10 12:51:39 +01:00
Dylan K. Taylor
bcd197d7bb AsyncWorker: fixed __construct() signature 2018-05-10 12:50:09 +01:00
Dylan K. Taylor
3148f692c1 AsyncWorker: No need to register static logger - it's inherited by default with pthreads 3.1.7 2018-05-10 12:49:03 +01:00
Dylan K. Taylor
c9bd60123b Scheduler: shutdown async pool properly instead of relying on ThreadManager 2018-05-09 19:49:12 +01:00
Dylan K. Taylor
73e09392b6 Timings: Clean up some terrible code, move namespaces 2018-03-19 19:05:51 +00:00
Dylan K. Taylor
ac5a91b67e Cleaned up bool comparison mess 2018-03-19 14:10:55 +00:00
Dylan K. Taylor
cd35bd6872 git diff-tree --check $(git hash-object -t tree /dev/null) HEAD 2018-03-11 10:31:25 +00:00
Dylan K. Taylor
e0d5c79848 Scheduler: Catch exceptions thrown from AsyncTask->onCompletion() 2018-02-27 11:33:16 +00:00
Dylan K. Taylor
18b287c3ea AsyncTask: Remove cleanObject() and calls to it
This is no longer needed. Doing worker GC (via collect()) frees the allocated memory anyway, so this function is now redundant.
2018-01-30 16:45:49 +00:00
Dylan K. Taylor
8e1394bf53 MemoryManager: Use get_declared_classes() to build lists of static properties
This makes memory dumping independent from the autoloader implementation, and fixes #1958.
2018-01-23 18:23:53 +00:00
Dylan K. Taylor
4f8e4f0522
Add EOF newlines where missing (bulk) (#1836)
This should solve issues with people making GitHub PRs and having the web editor messing things up. GitHub Web Editor sucks :(
2017-12-20 11:56:36 +00:00
Dylan K. Taylor
74b074753f Bulk addition of constant visibilities
thanks PhpStorm inspections plugin for annoying the shit out of me until
I did this.
2017-11-21 14:44:10 +00:00
jojoe77777
119913da30 Modified misleading comment (#1455)
The plugin isn't supposed to extend PluginTask, the task is
2017-10-09 07:52:40 +01:00
Dylan K. Taylor
7ba193dc2e Set ErrorException handler on AsyncWorkers 2017-09-28 18:01:31 +01:00
Dylan K. Taylor
15b08c1417 Added capability to dump AsyncWorkers' memory (#1379)
This now actually works with PHP 7.2 + latest pthreads, before it was too unstable.
2017-09-14 16:45:48 +01:00
Dylan K. Taylor
aaa3b6e59a Added explicit AsyncTask->storeLocal(), removed AsyncTask->__construct() object storage (#1322)
Far too often I see people using IDEs which generate the constructors for them and then accidentally unintentionally store things in the object store. This parent constructor behaviour is unexpected. If a developer wants to store something, they should now do so explicitly by calling storeLocal().
2017-09-10 20:31:28 +01:00
Dylan K. Taylor
1d338bfdf9 Fixed uncaught exceptions during Task->onCancel() causing all kinds of nasty behaviour
including crashing the server on shutdown, preventing self-cancellation, and causing memory leaks
2017-09-02 19:28:51 +01:00
SOFe
9902d29734 ServerScheduler::scheduleAsyncTask() returns the worker used (#1312) 2017-08-29 10:29:24 +01:00
Dylan K. Taylor
7c212d3d53 Fix formatting issue in AsyncPool 2017-08-25 19:15:57 +01:00
Dylan K. Taylor
d1852834de Revert "Added capability to dump AsyncWorker memory"
This reverts commit eb4594348b6fe4f8af83d5fd386f393956f7b561.

This is far too unstable with more than one worker thread.
2017-08-22 20:46:20 +01:00
Dylan K. Taylor
eb4594348b Added capability to dump AsyncWorker memory 2017-08-22 19:57:00 +01:00
Dylan K. Taylor
17053389b0 Added memory limits for AsyncWorkers 2017-08-20 12:15:48 +01:00
Dylan K. Taylor
57e7c3d91f Missed one 2017-07-15 13:30:02 +01:00
Dylan K. Taylor
2018ad6376 Merge master 2017-07-14 12:12:35 +01:00
Dylan K. Taylor
b5790d19bf Cleaned up MainLogger registration and declared a typehint
Remove null hint from MainLogger::getLogger() so static analysis doesn't complain everywhere
just make sure you register the logger before trying to use MainLogger::getLogger() on a different thread!
2017-07-14 11:39:04 +01:00
Dylan K. Taylor
c3b8be3f60 and more typehints 2017-07-14 10:56:51 +01:00
Dylan K. Taylor
46a2e6cbf8 Some breaking changes for plugins >:D 2017-07-14 08:52:27 +01:00
Dylan K. Taylor
8fc1501e89 Moar typehints 2017-07-14 08:52:27 +01:00
Dylan K. Taylor
2a7b736f18 Heap of bugfixes, cleanup and PHP 7 upgrades 2017-07-13 19:18:56 +01:00
Dylan K. Taylor
9c9095060f Register MainLogger on AsyncWorkers to make MainLogger::getLogger() usable in AsyncTasks
Threaded static properties aren't thread-local anymore in pthreads 3.1.7dev
2017-07-04 16:50:17 +01:00
Dylan K. Taylor
a73c6f1861 Fixed some unnecessary FQNs in docs 2017-06-25 12:43:04 +01:00
Dylan K. Taylor
e18a3ac933 Fixed UUID-related issues 2017-06-07 13:11:03 +01:00