mesa: create locked version of HashWalk
authorTimothy Arceri <tarceri@itsqueeze.com>
Mon, 24 Apr 2017 05:59:23 +0000 (15:59 +1000)
committerTimothy Arceri <tarceri@itsqueeze.com>
Mon, 24 Apr 2017 23:58:39 +0000 (09:58 +1000)
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/mesa/main/hash.c
src/mesa/main/hash.h

index b7a7bd9f64804498c4fd716ee362a38addf15bef..a3772bdfb58843fa511e376accee82c0ab27eeff 100644 (file)
@@ -411,6 +411,23 @@ _mesa_HashDeleteAll(struct _mesa_HashTable *table,
  * \param userData  arbitrary pointer to pass along to the callback
  *                  (this is typically a struct gl_context pointer)
  */
+static void
+hash_walk_unlocked(const struct _mesa_HashTable *table,
+                   void (*callback)(GLuint key, void *data, void *userData),
+                   void *userData)
+{
+   assert(table);
+   assert(callback);
+
+   struct hash_entry *entry;
+   hash_table_foreach(table->ht, entry) {
+      callback((uintptr_t)entry->key, entry->data, userData);
+   }
+   if (table->deleted_key_data)
+      callback(DELETED_KEY_VALUE, table->deleted_key_data, userData);
+}
+
+
 void
 _mesa_HashWalk(const struct _mesa_HashTable *table,
                void (*callback)(GLuint key, void *data, void *userData),
@@ -418,19 +435,20 @@ _mesa_HashWalk(const struct _mesa_HashTable *table,
 {
    /* cast-away const */
    struct _mesa_HashTable *table2 = (struct _mesa_HashTable *) table;
-   struct hash_entry *entry;
 
-   assert(table);
-   assert(callback);
    mtx_lock(&table2->Mutex);
-   hash_table_foreach(table->ht, entry) {
-      callback((uintptr_t)entry->key, entry->data, userData);
-   }
-   if (table->deleted_key_data)
-      callback(DELETED_KEY_VALUE, table->deleted_key_data, userData);
+   hash_walk_unlocked(table, callback, userData);
    mtx_unlock(&table2->Mutex);
 }
 
+void
+_mesa_HashWalkLocked(const struct _mesa_HashTable *table,
+               void (*callback)(GLuint key, void *data, void *userData),
+               void *userData)
+{
+   hash_walk_unlocked(table, callback, userData);
+}
+
 static void
 debug_print_entry(GLuint key, void *data, void *userData)
 {
index 52a6c5d9ddc9ec608ee576eaab67ee6492657c5f..9eb0f0eac6c7887209a7ec18266be948db9b284e 100644 (file)
@@ -66,6 +66,11 @@ _mesa_HashWalk(const struct _mesa_HashTable *table,
                void (*callback)(GLuint key, void *data, void *userData),
                void *userData);
 
+extern void
+_mesa_HashWalkLocked(const struct _mesa_HashTable *table,
+                     void (*callback)(GLuint key, void *data, void *userData),
+                     void *userData);
+
 extern void _mesa_HashPrint(const struct _mesa_HashTable *table);
 
 extern GLuint _mesa_HashFindFreeKeyBlock(struct _mesa_HashTable *table, GLuint numKeys);