This patch solves two problems with the HostDataToTargetMap (HDTT
map) which caused races and crashes before:
- Any access to the HDTT map needs to be exclusive access. This was not the case for the "dump table" traversals that could collide with updates by other threads. The new Accessor and ProtectedObject wrappers will ensure we have a hard time introducing similar races in the future. Note that we could allow multiple concurrent read-accesses but that feature can be added to the Accessor API later.
- The elements of the HDTT map were HostDataToTargetTy objects which meant that they could be copied/moved/deleted as the map was changed. However, we sometimes kept pointers to these elements around after we gave up the map lock which caused potential races again. The new indirection through HostDataToTargetMapKeyTy will allows us to modify the map while keeping the (interesting part of the) entries valid. To offset potential cost we duplicate the ordering key of the entry which avoids an additional indirect lookup.
We should replace more objects with "protected objects" as we go.
I don't see a way to give this thing ownership of a resource after constructing it with DoNotGetAccess. Perhaps replace that Boolean flag with a default constructor that sets the pointer to null.