[Mesa-dev] [PATCH 1/2] mesa: handle callback functions that remove the ht entry in _mesa_HashDeleteAll()

Timothy Arceri timothy.arceri at collabora.com
Sun Nov 6 21:45:36 UTC 2016


Now that we use recursive locking for the hash table mutex, it is possible
to pass a callback to that remove the entry to _mesa_HashDeleteAll() without
getting stuck waiting for a lock. However we will end up removing the entry
twice and the hash table entry counts will get messed up.

To avoid messing up the entry counts we check to see if the entry is already
deleted before calling remove in _mesa_HashDeleteAll().
---
 src/mesa/main/hash.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/mesa/main/hash.c b/src/mesa/main/hash.c
index 670438a..e7f3333 100644
--- a/src/mesa/main/hash.c
+++ b/src/mesa/main/hash.c
@@ -389,7 +389,12 @@ _mesa_HashDeleteAll(struct _mesa_HashTable *table,
    table->InDeleteAll = GL_TRUE;
    hash_table_foreach(table->ht, entry) {
       callback((uintptr_t)entry->key, entry->data, userData);
-      _mesa_hash_table_remove(table->ht, entry);
+     /* Check that the cb didn't already remove the entry. If not
+      * remove it.
+      */
+     if (entry->key != table->ht->deleted_key) {
+        _mesa_hash_table_remove(table->ht, entry);
+     }
    }
    if (table->deleted_key_data) {
       callback(DELETED_KEY_VALUE, table->deleted_key_data, userData);
-- 
2.7.4



More information about the mesa-dev mailing list