mesa: Lock mutex around _mesa_HashLookup linked list chase.
[mesa.git] / src / mesa / main / hash.c
index 7c3c7a6bdbb8533b97eaf97c2ac53c6430ca6339..fdfbe6b4f43995bd0593d9639cb7b45d7f25d494 100644 (file)
@@ -128,7 +128,7 @@ _mesa_DeleteHashTable(struct _mesa_HashTable *table)
  * \return pointer to user's data or NULL if key not in table
  */
 void *
-_mesa_HashLookup(const struct _mesa_HashTable *table, GLuint key)
+_mesa_HashLookup(struct _mesa_HashTable *table, GLuint key)
 {
    GLuint pos;
    const struct HashEntry *entry;
@@ -137,13 +137,16 @@ _mesa_HashLookup(const struct _mesa_HashTable *table, GLuint key)
    assert(key);
 
    pos = HASH_FUNC(key);
+   _glthread_LOCK_MUTEX(table->Mutex);
    entry = table->Table[pos];
    while (entry) {
       if (entry->Key == key) {
-        return entry->Data;
+         _glthread_UNLOCK_MUTEX(table->Mutex);
+         return entry->Data;
       }
       entry = entry->Next;
    }
+   _glthread_UNLOCK_MUTEX(table->Mutex);
    return NULL;
 }