bevy/crates/bevy_ecs/src
James Liu e34fb68677
refactor: Extract parallel queue abstraction (#7348)
# Objective
There's a repeating pattern of `ThreadLocal<Cell<Vec<T>>>` which is very
useful for low overhead, low contention multithreaded queues that have
cropped up in a few places in the engine. This pattern is surprisingly
useful when building deferred mutation across multiple threads, as noted
by it's use in `ParallelCommands`.

However, `ThreadLocal<Cell<Vec<T>>>` is not only a mouthful, it's also
hard to ensure the thread-local queue is replaced after it's been
temporarily removed from the `Cell`.

## Solution
Wrap the pattern into `bevy_utils::Parallel<T>` which codifies the
entire pattern and ensures the user follows the contract. Instead of
fetching indivdual cells, removing the value, mutating it, and replacing
it, `Parallel::get` returns a `ParRef<'a, T>` which contains the
temporarily removed value and a reference back to the cell, and will
write the mutated value back to the cell upon being dropped.

I would like to use this to simplify the remaining part of #4899 that
has not been adopted/merged.

---

## Changelog
TODO

---------

Co-authored-by: Joseph <21144246+JoJoJet@users.noreply.github.com>
2024-02-19 16:31:15 +00:00
..
entity Move EntityHash related types into bevy_ecs (#11498) 2024-02-12 15:02:24 +00:00
identifier Unified identifer for entities & relations (#9797) 2024-01-13 01:09:32 +00:00
query Update documentation for WorldQuery and filters (#11952) 2024-02-18 21:58:26 +00:00
reflect Move EntityHash related types into bevy_ecs (#11498) 2024-02-12 15:02:24 +00:00
schedule Immediately poll the executor once before spawning it as a task (#11801) 2024-02-12 15:33:35 +00:00
storage Double the capacity when BlobVec is full (#11167) 2024-01-22 15:05:34 +00:00
system refactor: Extract parallel queue abstraction (#7348) 2024-02-19 16:31:15 +00:00
world Use question mark operator when possible (#11865) 2024-02-14 18:44:33 +00:00
archetype.rs Make Archetypes.archetype_component_count private (#10774) 2024-02-03 00:07:50 +00:00
bundle.rs Fix small docs misformat in BundleInfo::new (#11855) 2024-02-13 22:14:05 +00:00
change_detection.rs Mention Resource where missing from component/resource related type docs (#11769) 2024-02-08 06:31:48 +00:00
component.rs Mention Resource where missing from component/resource related type docs (#11769) 2024-02-08 06:31:48 +00:00
event.rs Fix bug where events are not being dropped (#11528) 2024-02-02 21:14:54 +00:00
lib.rs Use TypeIdMap whenever possible (#11684) 2024-02-03 23:47:04 +00:00
removal_detection.rs Docs reflect that RemovalDetection also yields despawned entities (#11795) 2024-02-10 11:18:05 +00:00