Commit Graph

230 Commits

Author SHA1 Message Date
b638967d01 Revert "Return error when no ResourceFormatLoader found."
This reverts commit 6df3621b47.

Fixes #97153.
2024-09-19 12:41:51 +02:00
e3ddf3d44a ResourceLoader: Fixup resource changed feature (no. 2) 2024-09-13 11:32:55 +02:00
effbc07976 Merge pull request #96617 from RandomShaper/res_loader_pending
ResourceLoader: Add last resort life-time insurance for tokens
2024-09-06 22:38:41 +02:00
97197ff5e9 ResourceLoader: Fixup resource changed feature
This is a complement to: https://github.com/godotengine/godot/pull/96593
2024-09-06 18:31:51 +02:00
ccd470d33c ResourceLoader: Add last resort life-time insurance for tokens 2024-09-06 14:00:10 +02:00
74b9c38d58 ResourceLoader: Add thread-aware resource changed mechanism 2024-09-06 08:57:09 +02:00
c450f4d667 ResourceLoader: Simplify handling of unregistered tasks 2024-09-05 09:54:03 +02:00
e33fdb4296 Use MutexLock in more places 2024-08-29 14:12:59 +02:00
0441c67de6 ResourceLoader: Handle another case of user tokens 2024-08-28 13:53:39 +02:00
bfb5570c03 Fix ResourceLoader is not verbosely printing a resource path on loading 2024-08-28 03:37:51 +07:00
ce44c91223 Merge pull request #93739 from AThousandShips/lock_unlock
[Core] Allow locking/unlocking of `MutexLock`
2024-08-26 22:45:13 +02:00
b78da13e2a Merge pull request #93064 from Hilderin/fix-fileSystem-dock-wont-show-any-file-folders
Fix FileSystem dock won't show any file folders (v2)
2024-08-26 22:45:04 +02:00
723f5500f4 [Core] Allow locking/unlocking of MutexLock 2024-08-26 12:38:03 +02:00
f4d76853b9 WorkerThreadPool (plus friends): Overhaul unlock allowance zones
This fixes a rare but possible deadlock, maybe due to undefined behavior. The new implementation is safer, at the cost of some added boilerplate.
2024-08-21 12:22:52 +02:00
df23858488 ResourceLoader: Fix edge cases in the management of user tokens
1. Make handling of user tokens atomic:
   Loads started with the external-facing API used to perform a two-step setup of the user token. Between both, the mutex was unlocked without its reference count having been increased. A non-user-initiated load could therefore destroy the load task when it unreferenced the token.
   Those stages now happen atomically so in the one hand, the described race condition can't happen so the load task life insurance doesn't have a gap anymore and, on the other hand, the ugliness that the call to load could return `ERR_BUSY` if happening while other thread was between both steps is gone.
   The code has been refactored so the user token concerns are still outside the inner load start function, which is agnostic to that for a cleaner implementation.
2. Clear ambiguity between load operations running on `WorkerThreadPool`:
   The two cases are: single-loaded thread directly started by a user pool task and a load started by the system as part of a multi-threaded load.
   Since ensuring all the code dealing with this distinction would make it very complex, and error-prone, a different measure is applied instead: just take one of the cases out of the dicotomy. We now ensure every load happening on a pool thread has been initiated by the system.
   The way of achieving that is that a single-threaded user-started load initiated from a pool thread, is run as another task.
2024-08-21 12:22:52 +02:00
5c970db2e4 ResourceLoader: Optimize remap check by deferring until a non-mutex zone 2024-08-21 12:19:43 +02:00
28619e26cf ResourceLoader: Enhance deadlock prevention
Benefits:
- Simpler code. The main load function is renamed so it's apparent that it's not just a thread entry point anymore.
- Cache and thread modes of the original task are honored. A beautiful consequence of this is that, unlike formerly, re-issued loads can use the resource cache, which makes this mechanism much more performant.
- The newly added getter for caller task id in WorkerThreadPool allows to remove the custom tracking of that in ResourceLoader.
- The check to replace a cached resource and the replacement itself happen atomically. That fixes deadlock prevention leading to multiple resource instances of the same one on disk. As a side effect, it also makes the regular check for replace load mode more robust.
2024-08-21 12:19:43 +02:00
bd0959ebdd ResourceLoader: Properly push & pop TLS state on recursive load tasks 2024-08-21 12:19:43 +02:00
5ca419e32c Merge pull request #94801 from gamelessone/fix-cond-var
Fix use-after-free of `ConditionVariable` in `ResourceLoader`
2024-08-21 11:14:22 +02:00
1b0c5cbc01 Fix FileSystem dock won't show any file folders (v2) 2024-08-20 21:23:13 -04:00
6a829d5a86 Merge pull request #95508 from Summersay415/loaded-when-not
Return error when no ResourceFormatLoader found
2024-08-19 14:34:17 +02:00
e9407d4877 ResourceLoader: Revert workaround resource loading crashes due to buggy TLS
This reverts commit 41c0785636.
2024-08-19 12:22:31 +02:00
f01e052162 Merge pull request #95549 from timothyqiu/split-translation-server
Split `TranslationServer` into its own file
2024-08-16 14:36:16 +02:00
ae2044dccb Merge pull request #95477 from RandomShaper/res_load_dev_bugs
ResourceLoader: Use better error handling for possible engine bugs
2024-08-16 10:36:33 +02:00
7343dc3a5d Split TranslationServer into its own file 2024-08-15 15:00:47 +08:00
6df3621b47 Return error when no ResourceFormatLoader found. 2024-08-14 11:45:23 +07:00
31a9e10ddb ResourceLoader: Use better error handling for possible engine bugs 2024-08-13 12:52:08 +02:00
17ea4b405a ResourceLoader: Fix error on querying progress for uncached loads 2024-08-13 12:41:11 +02:00
f5bb14dceb [ResourceLoader] Add check to prevent double free crashes. 2024-08-06 08:31:03 +03:00
2ff6594928 Fix use condition_variable after free 2024-07-30 13:59:20 +03:00
5640e8adc9 ResourceLoader: Let resource setup late steps invoke loading in turn 2024-07-29 18:13:37 +02:00
28a7a95531 ResourceLoader: Fix sync issues with error reporting
This is about not letting the resource format loader set the error code directly on the task anymore. Instead, it's stored locally and assigned only when it is right to do so.

Otherwise, other tasks may see an error code in the current one before it's state having transitioned to errored. While this, besides the technically true data race, may not be a problem in practice, it causes surprising situations during debugging as it breaks assumptions.
2024-07-19 10:00:41 +02:00
5b5cdf2414 Fixup recent changes to threading concerns
ResourceLoader:
- Fix invalid tokens being returned.
- Remove no longer written `ThreadLoadTask::dependent_path` and the code reading from it.
- Clear deadlock hazard by keeping the mutex unlocked during userland polling.

WorkerThreadPool:
- Include thread call queue override in the thread state reset set, which allows to simplify the code that handled that (imperfectly) in the ResourceLoader.
- Handle the mutex type correctly on entering an allowance zone.

CommandQueueMT:
- Handle the additional possibility of command buffer reallocation that mutex unlock allowance introduces.
2024-07-16 11:03:02 +02:00
a426479b3f ResourceLoader: Fix error message due to already-awaited tasks being re-awaited 2024-07-08 12:19:44 +02:00
f952d3956c ResourceLoader: Fixup management of thread-specific status
- Allows the message queue override to flush after loading each resource, which was the original intent.
- Removes a redundant call to mark the thread as safe-for-nodes.
2024-07-08 10:30:25 +02:00
ec61c5064c ResourceLoader: Support polling and get-before-complete on the main thread 2024-06-28 11:25:10 +02:00
c1391489e3 GDScript: Enhance handling of cyclic dependencies 2024-06-26 17:44:32 +02:00
884d1da938 ResourceLoader: Fix handling of uncached loads
- `CACHE_MODE_IGNORE_DEEP` is checked in addition to `CACHE_MODE_IGNORE` to determine if a load is uncached. This avoids crashes in uncached loads due to prematurely freed load tasks.
- Cached load tasks are isolated (not registered in the task map ever). This avoids regular loads from reusing in-flight cached loads, which is not correct.
2024-06-24 11:25:57 +02:00
087ef4b942 Merge pull request #93124 from RandomShaper/skull_trio
`ResourceLoader`: Let the caller thread use its own message queue override
2024-06-14 17:13:38 +02:00
cc6f5d1a7a ResourceLoader: Let the caller thread use its own message queue override 2024-06-13 10:31:11 +02:00
21c03d1956 WorkerThreadPool: Fix thread message queue not restored after overridden in a task
Also, simplifies the thread override teardown in MessageQueue.
2024-06-13 10:31:08 +02:00
bdcceef0e2 ResourceLoader: Avoid deadlock when awaiting a loader thread that failed early 2024-06-12 13:49:37 +02:00
e4fa8543ea Revert "Fix FileSystem dock won't show any file folders"
This reverts commit 72856d633a.

Fixes #93022.
2024-06-11 11:46:35 +02:00
72856d633a Fix FileSystem dock won't show any file folders 2024-06-10 19:54:37 -04:00
00cc0a3e8f Merge pull request #90091 from ajreckof/Fix-load-subtask-not-being-registered-leading-to-false-progress-values-
Fix load subtask not being registered leading to false progress values.
2024-04-24 18:55:04 +02:00
ca020ad8cd Fix load subtask not being registered leading to false progress values. 2024-04-13 01:42:29 +02:00
64146cb7f3 [Core] Add iteration support to Array 2024-04-10 14:49:34 +02:00
0274877def [Core] Fix ResourceLoader.load cache with relative paths
Paths were not simplified meaning that `res://foo.bar` was treated
differently from `./foo.bar` and similar
2024-03-30 12:50:08 +01:00
5e144022e7 Enhance cache modes in resource loading
- Unify documentation, hoping to clear misconcepctions about about propagation of the cache mode across dependant loads.
- Clarify in docs that `CACHE_MODE_REPLACE` now also works on the main resource (from #87008).
- Add two recursive modes, counterparts of `CACHE_MODE_REPLACE` and `CACHE_MODE_IGNORE`, since it seems some need them (see #59669, #82830).
- Let resources, even loaded with one of the ignore-cache modes, get a path, which is useful for tools.
2024-02-26 14:59:04 +01:00
851f1d49d7 Remove spammy dev-mode message about load deadlock prevention 2024-02-23 14:54:03 +01:00