template<
typename ObjectType>
class UE::Geometry::TConstObjectSharedAccess< ObjectType >
TConstObjectSharedAccess provides a way for the owner of some object (eg a Mesh) to share read-only access to that object with background threads.
This avoids the obvious alternative, using TSharedPtr, which tends to result in some bad patterns (in particular calling code that /doesn't/ have a shared pointer to the object, now has to make a copy, or also convert all related code to use a shared pointer).
Currently TConstObjectSharedAccess's template ObjectType must be default constructible. This allows the background threads to still access an instance of ObjectType even if the owner thread/code decides to revoke access. In that case, TConstObjectSharedAccess provides an "empty" ObjectType instead. (the background processing code must handle this case).
TConstObjectSharedAccess can be constructed with either a raw pointer to ObjectType, or a TSharedPtr. In the raw pointer case, the creator is responsible for destruction.
The standard usage pattern is:
[Owner thread] T* ObjectPtr = (...); TSharedPtr<TConstObjectSharedAccess<T>> SharedAccess = MakeShared<TConstObjectSharedAccess<T>>(ObjectPtr); pass_to_background_thread(SharedAccess);
[Background thread] SharedAccess->AccessSharedObject( [](const ObjectType& Object) { do_my_stuff(Object); } );
[Owner thread (later)] SharedAccess->ReleaseSharedObject();
Note that a TSharedPtr does not strictly need to be used. However this allows the Owner thread to destruct the Object, and/or terminate, and the background thread can still safely access a shared ObjectType (now empty).