From 1d0f44739db924280f38c15b85ecdfc158f8ec04 Mon Sep 17 00:00:00 2001 From: Rebecca Mckeever Date: Wed, 29 Jan 2025 20:33:26 -0800 Subject: [PATCH] util/hash_table: Add _mesa_hash_table_u64_replace() This function updates the data of a u64 hash_table entry and is safe to use inside a hash_table_u64_foreach() loop. Fixes: 7bea6f86 ("panvk: Overhaul the Bifrost descriptor set implementation") Signed-off-by: Rebecca Mckeever Reviewed-by: Boris Brezillon Reviewed-by: Erik Faye-Lund Part-of: --- src/util/hash_table.c | 18 ++++++++++++++++++ src/util/hash_table.h | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/src/util/hash_table.c b/src/util/hash_table.c index b02ae2f02dc..3835ead9255 100644 --- a/src/util/hash_table.c +++ b/src/util/hash_table.c @@ -1006,3 +1006,21 @@ _mesa_hash_table_u64_next_entry(struct hash_table_u64 *ht, ._entry = next, }; } + +/* Updates the data of a u64 hash_table entry inside a + * hash_table_u64_foreach() loop + */ +void +_mesa_hash_table_u64_replace(struct hash_table_u64 *ht, + const struct hash_entry_u64 *ent, + void *new_data) +{ + if (ent->_entry) { + ent->_entry->data = new_data; + } else if (ent->key == FREED_KEY_VALUE) { + ht->freed_key_data = new_data; + } else { + assert(ent->key == DELETED_KEY_VALUE); + ht->deleted_key_data = new_data; + } +} diff --git a/src/util/hash_table.h b/src/util/hash_table.h index 84e6003f83d..31441e28c6e 100644 --- a/src/util/hash_table.h +++ b/src/util/hash_table.h @@ -220,6 +220,11 @@ _mesa_hash_table_u64_search(struct hash_table_u64 *ht, uint64_t key); void _mesa_hash_table_u64_remove(struct hash_table_u64 *ht, uint64_t key); +void +_mesa_hash_table_u64_replace(struct hash_table_u64 *ht, + const struct hash_entry_u64 *he, + void *new_data); + void _mesa_hash_table_u64_clear(struct hash_table_u64 *ht);