Makes CollectionStorage thread safe for parallel initialization of collections by one or multiple IPC consumers without requring framework thread synchronization.#529
Open
Mayo66 wants to merge 8 commits intoxivdev:masterfrom
Conversation
… collection logic; removed duplicate calls Adding / removing collections do not require framework thread access. It is only when assigning via AssignTemporaryCollection(), it needs to access `(ObjectManager)objects[actorIndex]` when framework thread is needed.
Author
|
now increments upon generating a new id to avoid scenarios when two threads call an |
ebfbb42 to
12542fe
Compare
Author
|
added locking to public methods |
12542fe to
0bf9fde
Compare
Maintainers expect _currentCollectionIdValue to start at 1, and I don't want to change that
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
As of now, most collection operations require being called on the framework thread despite not needing access to game objects.
However, It is only when assigning via
AssignTemporaryCollection(), in which it accesses(ObjectManager)objects[actorIndex]when framework thread is needed.By making the internal data structures thread-safe, we can move collection management operations off the framework thread when safe and in doing so avoiding framework thread bottlenecks and reduce hitches, while avoiding desynchronizations between multiple consumers.
Changes
_collectionsByLocal: Changed toConcurrentDictionaryfor lock free concurrent access_collections: Added locking to protect concurrent modificationsCurrentCollectionId: Implemented atomic incrementAdd()for clarity.This should make the following IPC methods safe for off-framework access:
CreateTemporaryCollection()DeleteTemporaryCollection()AssignTemporaryCollection()still needs framework access as it is the crucial step when a collection is associated with a game object.Misc
There was also a duplicate operation at line 189 in the original file, method
RemoveCollection():_collectionsByLocal.Remove(collection.Identity.LocalId);at line 183 in the original file,
Delete(collection);is called, which is simplyThe call at line 189 looks like a duplicate, and this PR also removes said duplicate operation.