Makes CollectionStorage thread safe for parallel initialization of collections by one or multiple IPC consumers without requring framework thread synchronization.
#529
+105
−50
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.