vkd3d: Make hashmap compatible with reader-writer locks.

Yield insertion when there is a match.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
This commit is contained in:
Hans-Kristian Arntzen 2020-12-02 11:42:28 +01:00
parent e0382cc451
commit f96e60b6ac
2 changed files with 10 additions and 5 deletions

View File

@ -167,16 +167,21 @@ static inline struct hash_map_entry *hash_map_insert(struct hash_map *hash_map,
if (!(current->flags & HASH_MAP_ENTRY_OCCUPIED) ||
(current->hash_value == hash_value && hash_map->compare_func(key, entry)))
target = current;
entry_idx = hash_map_next_entry_idx(hash_map, entry_idx);
else
entry_idx = hash_map_next_entry_idx(hash_map, entry_idx);
}
if (!(target->flags & HASH_MAP_ENTRY_OCCUPIED))
{
hash_map->used_count += 1;
memcpy(target, entry, hash_map->entry_size);
target->flags = HASH_MAP_ENTRY_OCCUPIED;
target->hash_value = hash_value;
}
/* If target is occupied, we already have an entry in the hashmap.
* Return old one, caller is responsible for cleaning up the node we attempted to add. */
memcpy(target, entry, hash_map->entry_size);
target->flags = HASH_MAP_ENTRY_OCCUPIED;
target->hash_value = hash_value;
return target;
}

View File