Commit Graph

137 Commits

Author SHA1 Message Date
player-03
f6393fc107 Overhaul ThreadPool job scheduling. (#1837, #1958)
* Store the job's thread in `JobData`.

Since we're storing more and more in `JobData`, and the background thread only needs three bits of that data, I added those to `ThreadEvent` so we don't have to pass the full object. This may improve performance in HTML5 specifically, where passing a class instance incurs an overhead.

* Allow a single `ThreadPool` to run jobs in both modes.

* Remove unnecessary `@:forward.new`.

* Improve check for whether to call `Thread.returnMessage()`.

Now that thread pools can manage both types of job at once, we can't rely on `mode` to determine whether we're on a background thread. Honestly, I shouldn't have relied on it in the first place.

* Improve `ThreadPool.isMainThread()`.

No need to set `__mainThread` based on `isWorker()` when `isWorker()` already gives the information we're after.

* Correct and clarify documentation.

* Start new jobs immediately when a slot opens up.

For single-threaded jobs, this means a pool can now handle multiple per frame. For multi-threaded jobs, this only slightly reduces the delay between jobs.

* Fix missing function call.

* Add missing import.

Forgot this when overriding the "send" functions.

* Simplify comment.

It's a private variable, so all it really needs to do is mention the location it gets used.

* Don't count the main thread in `currentThreads`.

Plus, alphabetize the variables.

In 8.2.0, a single-threaded pool would report `currentThreads == 1` when running a job, meaning it counted the main thread. But in retrospect, this was both redundant (with `activeJobs`) and unexpected, so I'm counting it as a bug.

* Update documentation.

* Remove redundant check.

All the jobs in `__multiThreadedJobs` are already known to be running in multi-threaded mode. This is left over from when pools were locked to a single mode.

* Handle error case differently.

We still need to throw an error when `mode` is `MULTI_THREADED`, but this can now vary per job, so the check must happen during `run()`.

Also, the old error message was out of date. You can't pass a function to the `ThreadPool` constructor.

* Remove unnecessary `#if`s.

On other targets, it will return `true`, which will be inlined and optimized out. The conditional compilation just added clutter.

* Rewrite `ThreadPool` to use `Deque` on native targets.

Using the flag `lime_threads_deque` to distinguish between this and the old approach. Hopefully someday we can remove this flag, once we implement something akin to `Deque` in HTML5.

That aside, the hardest part is keeping track of the state of each thread. That's why there's so much more complexity: whenever the main thread sends a message to a worker, it needs to wait for confirmation, but also not send any more messages while waiting. And the code that tracks all this needs to work in both modes (with and without `Deque`).

* Bug fix: `firstLoop = false` can get skipped.

* Fix misplaced `#if`.

* Add missing `#if`.

* Make sure all events are received before removing the update listener.

After all jobs are done, threads will send `EXIT` events. These must be processed before removing `__update`, otherwise they'll linger in the queue until the next job starts.

* Keep better track of how many threads are idle.

Previously, while a thread was exiting, `ThreadPool` could think it was still idle. This would cause it not to spin up a new thread for the next job, leading to a pending job with no threads available to handle it.

* Remove redundant code.

* Fix null pointer error.

* Fix bugs in `cancel()` and `cancelJob()`.

* Don't shut down a `ThreadPool` while work events are queued.

Co-authored-by: Barış Yıldırım <25794892+barisyild@users.noreply.github.com>

* Add missing `#if`.

---------

Co-authored-by: Barış Yıldırım <25794892+barisyild@users.noreply.github.com>
2025-07-07 16:22:41 -04:00
Joseph Cloutier
593f4fa52c Rename web-workerallow-web-workers for clarity.
The former was unclear about how the dependency would relate to web workers. Would it only be available to workers? Would it automatically spin up a worker?

`allow-web-workers` isn't 100% perfect, but it implies the correct answers to the questions above (no and no) and isn't too long.
2024-06-15 22:13:05 -04:00
player-03
7019abb9fc Don't try to load lzma_worker-min.js in web workers. 2024-06-11 16:22:10 -04:00
Joshua Granick
d0678156dd Add initial support for LZMA decompression on HTML5 target 2024-05-31 08:09:28 -07:00
Joseph Cloutier
630aa1a62f Fix web worker errors.
It took a lot of work to get web workers to work, but web workers finally work!

`transferList` doesn't seem to work, though. It makes the object
inaccessible as expected, but it doesn't seem to affect performance.
2022-02-28 19:15:19 -05:00
Joseph Cloutier
218f763977 Begin adding web workers (major commit).
Not well-tested yet, especially the web workers.

In addition to web workers, this completely rewrites both
`BackgroundWorker` and `ThreadPool`. It adds thread safety via the
`WorkOutput` object, adds flexibility by making `BackgroundWorker` build
off `ThreadPool`, and exposes an `eventSource` variable that tells
listeners which job dispatched a given event.

This improves the old web worker implementation by reusing the _entire_
JS file. This is slower but ensures that all classes are available,
simplifying the end user experience. Web workers are now forbidden from
using instance functions, which also simplifies things. And finally, the
code attempts to restore the prototypes of all class instances passed
across threads, though this relies on the exact way Haxe generates
JavaScript, and may not work in Haxe 3 or Haxe 5.
2022-02-22 19:27:51 -05:00
Joseph Cloutier
265946877a Improve the error message for an unsupported use case
Lime requires the `Deque` class to target HashLink, which only
became available in Haxe 4. If you try, Lime should at least let
you know what's wrong.

Closes #1403... at least for now.
2020-11-10 10:32:08 -08:00
Joshua Granick
ba6fafeefa Remove iOS Bluetooth dependency 2020-09-29 11:04:23 -07:00
Joshua Granick
43666e816d iOS build fix 2020-03-18 18:54:13 -07:00
Joshua Granick
cac82509da Add support for embedded JS dependencies (embed Lime dependencies by default) 2019-02-12 13:30:07 -08:00
Joshua Granick
e588fc9526 Minor fix 2018-10-12 11:09:07 -07:00
Joshua Granick
78e99bf1d9 Remove whitespace lines 2018-07-18 17:32:51 -07:00
Joshua Granick
f051a9adae MojoAL enabled for static linking 2018-07-13 14:53:32 -07:00
Joshua Granick
7708866b50 Define fix 2018-07-12 13:38:26 -07:00
Joshua Granick
22965fa6f5 Documentation update 2018-07-10 16:49:02 -07:00
Joshua Granick
5aa71b1f8d Add stubs for AIR sys API support 2018-07-10 12:27:15 -07:00
Joshua Granick
fc56de8f32 Merge Harfbuzz bindings 2018-07-05 09:34:00 -07:00
Joshua Granick
55ee251bb7 Fix command-line tools 2018-07-05 09:33:58 -07:00
Joshua Granick
ecd7876c4b Add external platform code for use with HXP 2018-06-21 16:33:33 -07:00
Joshua Granick
55a640c48b Add support for HL libraries 2018-06-09 09:26:40 -07:00
Jens Fischer
25e9bbcdf1 Disable curl for lime-switch 2018-05-29 15:19:55 -07:00
Jens Fischer
f9422aa99b lime-switch compile fix 2018-05-29 09:26:14 -07:00
Joshua Granick
e496d09527 Revert "ALC bindings for HL"
This reverts commit 8d1ff873d8.

Revert "Binding fix"

This reverts commit c606ec5139.

Revert "Add support for HL libraries"

This reverts commit 6b49f4d240.

Revert "Minor fixes"

This reverts commit dcacb9f04a.

Revert "Compile fixes"

This reverts commit 3b9e572f8b.

Revert "Sync with Haxe std library (remove some overrides)"

This reverts commit c05061c970.

Revert "Initial support for HL target in tools (for testing)"

This reverts commit 1dadbb725c.
2018-04-27 06:32:17 -07:00
Joshua Granick
6b49f4d240 Add support for HL libraries 2018-04-26 13:55:28 -07:00
Joshua Granick
ebd0f63733 Update macOS builds for current Xcode 2018-03-20 19:16:49 -07:00
Joshua Granick
e3aad88399 Static build fixes (resolve #1156) 2018-02-19 10:50:13 -08:00
James Gray
c325dd1d5d include.xml: clean up ndll conditionals for static_link 2018-02-11 16:54:19 -06:00
Joshua Granick
bc3a5f7468 Rename older 'modular' behavior to 'lime-modular' 2018-01-26 13:57:25 -08:00
Joshua Granick
0fa5ad30ad Add ability to set HTML5 module name 2017-11-29 13:28:42 -08:00
Joshua Granick
1287b2e30d Implement fileDialog.save for HTML5 2017-11-01 11:04:51 -07:00
Joshua Granick
a213294661 Working toward Java CFFI 2017-10-18 11:46:07 -07:00
Joshua Granick
801b3be275 Update default macOS deployment to 10.7 2017-10-12 09:55:23 -07:00
Joshua Granick
c3e49e01ed Be more aggressive about adding MACOSX_DEPLOYMENT_TARGET 2017-10-10 08:58:32 -07:00
Joshua Granick
761cc21c7b Enable Flash debugging on debug builds by default 2017-09-25 10:57:47 -07:00
Joshua Granick
1409f6c00d Use HXCPP std only for older Haxe releases 2017-09-11 15:46:45 -07:00
Joshua Granick
9991e99fee Initial support for AIR 2017-08-24 12:50:13 -07:00
Joshua Granick
d77cfc3e64 Minor -Dmodular fix 2017-06-30 17:23:48 -07:00
Joshua Granick
32f5a0509b HTML5 -Dmodular improvements 2017-06-26 15:55:18 -07:00
Joshua Granick
44020adfc3 Emscripten fixes 2017-06-23 15:22:40 -07:00
Joshua Granick
31d0cd20d9 -Dmodular compile fix 2017-06-21 12:45:11 -07:00
Joshua Granick
1836701398 Add linkage for Lime Switch target 2017-05-05 12:23:19 -07:00
Joshua Granick
7f7273fff4 Initial Vorbis bindings, rename lime.audio to lime.media 2017-01-06 17:39:35 -08:00
Joshua Granick
001f03a277 Misread the chart, need to include ARMv7 for now on iOS 2017-01-04 15:46:24 -08:00
Joshua Granick
9fefcb400c Fix 'has feature' in Haxe compiler for HTML5 module build (resolve openfl/openfl#1338) 2016-11-02 23:44:02 -07:00
Joshua Granick
a631d57f4e Workaround 'dont add haxe/std to path' error 2016-11-01 12:24:02 -07:00
Joshua Granick
8be354b073 Check Haxe version once 2016-10-31 10:03:11 -07:00
Valentin Lemière
31b9b87b53 Add haxe variable with version value + error if haxe is less than 3.2.0. Fix #820 2016-10-30 11:26:51 +01:00
Joshua Granick
7668f0ea93 Minor Haxe dev build fix 2016-10-24 16:50:46 -07:00
Joshua Granick
6442d54787 Use 10.6 as the minimum macOS target 2016-10-24 11:05:18 -07:00
Joshua Granick
e14d8e7db0 Initial support for modular JS output 2016-10-21 15:24:37 -07:00