Commit Graph

4712 Commits

Author SHA1 Message Date
Joseph Cloutier
a2e67cdba8 Provide more ways to cancel jobs. 2022-03-28 18:24:11 -04:00
Joseph Cloutier
d4588434b9 Remove references to BackgroundWorker. 2022-03-28 15:01:17 -04:00
Joseph Cloutier
f31adb845f Partially fix HTML5Thread.readMessage(false).
It now works correctly, but it's much slower.
2022-03-27 13:40:08 -04:00
Joseph Cloutier
e487de6153 Document an edge case. 2022-03-27 00:17:17 -04:00
Joseph Cloutier
6655ee10bb Fix equality testing in HTML5. 2022-03-26 23:55:35 -04:00
Joseph Cloutier
08336ea9b2 Improve Future's backwards compatibility. 2022-03-26 23:36:16 -04:00
Joseph Cloutier
a95f398ef4 Convert BackgroundWorker to a typedef.
Over the course of recent commits, `BackgroundWorker` and `ThreadPool`
have become more and more similar, and it got to the point where the
only difference was that `ThreadPool` was deliberately less convenient.

There's no good reason for `ThreadPool` to be this way, so this commit
removes the final difference.
2022-03-26 20:44:05 -04:00
Joseph Cloutier
01ed2c8c58 Improve clarity. 2022-03-25 18:14:08 -04:00
Joseph Cloutier
05322f0dfa Fix duration in multi-threaded mode. 2022-03-25 17:24:43 -04:00
Joseph Cloutier
f5676afa58 Fix errors with Future in HTML5.
This `Map` isn't needed on other targets, but the performance impact is
miniscule, so I opted for simplicity.
2022-03-25 14:48:39 -04:00
Joseph Cloutier
4589773cec Implement Future.withEventualValue().
And use this function to simplify two other classes.

Plus, add some documentation to explain why `MULTI_THREADED` isn't the
default in HTML5.
2022-03-24 23:36:50 -04:00
Joseph Cloutier
3eae01e7c6 Revert variable type.
We need to store an `ActiveJob`, not a `State`.
2022-03-23 16:17:08 -04:00
Joseph Cloutier
ecddb1ec5a Fix useThreads caveat.
Now the argument actually works, instead of only working the first time.
2022-03-21 20:54:34 -04:00
Joseph Cloutier
6b50a9fb8b Implement EventData.duration. 2022-03-21 20:46:24 -04:00
Joseph Cloutier
01a213b5fa Use WorkFunction in Future. 2022-03-14 18:34:48 -04:00
Joseph Cloutier
bcc1c854e7 Update documentation. 2022-03-14 18:34:02 -04:00
Joseph Cloutier
5a8a997bce Safely pass enums. 2022-03-02 22:31:59 -05:00
Joseph Cloutier
8a6848016b Improve cross-platform compatibility. 2022-03-02 13:16:24 -05:00
Joseph Cloutier
649fc2b2bb Simplify HTML5Thread.Message. 2022-03-02 13:12:55 -05:00
Joseph Cloutier
81a2d401e8 Fix docs generation. 2022-03-01 14:58:54 -05:00
Joseph Cloutier
363b397903 Fix performance when transferring large buffers. 2022-03-01 14:52:55 -05:00
Joseph Cloutier
1739370ae6 Allow canceling idle threads. 2022-03-01 14:49:40 -05:00
Joseph Cloutier
5f04b3e613 Properly exit workers, plus small fixes. 2022-03-01 14:43:42 -05:00
Joseph Cloutier
ec4d0b7ee9 Fix errors when generating docs. 2022-02-28 19:39:14 -05: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
b67d4304ff Fix legacy imports. 2022-02-15 12:22:19 -05:00
Joseph Cloutier
7c33cfed54 Improve thread safety.
This actually makes `Future` more thread-safe than its parent classes.
Unfortunately `BackgroundWorker` and `ThreadPool` can't receive the same
treatment, as it'd break backward compatibility.
2022-02-11 19:07:52 -05:00
Joseph Cloutier
dfe70daf18 Add single-thread support to Future.ready(). 2022-02-11 16:05:33 -05:00
Joseph Cloutier
3426b0e7d7 Make ThreadPool set completed.
I worded the documentation so carefully to account for both classes,
then forgot to implement it. Oops!
2022-02-11 16:04:52 -05:00
Joseph Cloutier
a9580a9486 Clarify Future.
The `Future` constructor creates a new `Future` instance, and in other
news, this floor is made out of floor.

Since there's now so much more to read, we should cut out the blatantly
obvious parts.
2022-02-11 15:46:54 -05:00
Joseph Cloutier
1ebff2e795 Remove redundancy. 2022-02-11 15:43:44 -05:00
Joseph Cloutier
cc2611048b Correctly calculate when to close threads.
And add some documentation so I won't make this mistake again.
2022-02-09 15:45:53 -05:00
Joseph Cloutier
f3c35a2fd0 Improve ThreadPool job chaining. 2022-02-09 15:28:13 -05:00
Joseph Cloutier
c6f355941b Catch errors in threads.
Without this, if an error happened during a `ThreadPool` job, that
thread would exit without updating `currentThreads`.

This can almost replace `FutureWork`'s error handling, but not quite.
2022-02-09 12:12:40 -05:00
Joseph Cloutier
f700b2de55 Make FutureWork use new ThreadPool features. 2022-02-02 15:05:06 -05:00
Joseph Cloutier
6560596d0d Update documentation. 2022-02-02 15:04:18 -05:00
Joseph Cloutier
689b78cec2 Implement workLoad. 2022-02-01 19:32:08 -05:00
Joseph Cloutier
fabb7e085a Link to my threading tutorial. 2022-01-31 19:59:26 -05:00
Joseph Cloutier
71305a7bce Use a loop to process events.
Otherwise, `BackgroundWorker` would be limited to one event per frame.
2022-01-31 12:39:19 -05:00
Joseph Cloutier
e47d5f4280 Fix errors in ThreadPool's single-threaded mode. 2022-01-31 12:29:13 -05:00
Joseph Cloutier
3a4ec6daa6 Improve BackgroundWorker's documentation. 2022-01-29 19:20:30 -05:00
Joseph Cloutier
223ab9bcd0 Make run() prefer local variables.
The benefit being that local variables can't be deleted by outside code.

The outside variables must still be set so `__update()` can access them.
2022-01-29 19:20:14 -05:00
Joseph Cloutier
3015a4e72e Enforce thread safety.
Modifying `onUpdate` is not thread safe, and must only be done on the
main thread. This is more important - and more enforceable - than most
of the "only do this on XYZ thread" comments.
2022-01-29 19:19:28 -05:00
Joseph Cloutier
deaa0713d8 Make ThreadPool extend BackgroundWorker.
Plus, add documentation.
2022-01-29 10:41:00 -05:00
Joseph Cloutier
8662d0a1c7 Implement SINGLE_THREADED mode.
Also addresses haxelime/lime#1502.
2022-01-28 17:13:51 -05:00
player-03
2f35e0b24c Merge pull request #1498 from player-03/loadAudioBuffer
Fix error when loading embedded audio.
2021-12-20 10:05:16 -05:00
player-03
8ab755d359 Merge pull request #1497 from player-03/gitignore-obj
Ignore project/obj in extensions.
2021-12-20 10:03:45 -05:00
Josh Tynjala
7bfaa441f2 Github Actions: better .gitignore exclusion 2021-12-09 13:26:36 -08:00
Josh Tynjala
67543f7417 Github Actions: fix typo 2021-12-09 13:09:56 -08:00