+/**
+ * Clone all entries in a hash table, into a new table.
+ *
+ * \param table the hash table to clone
+ */
+struct _mesa_HashTable *
+_mesa_HashClone(const struct _mesa_HashTable *table)
+{
+ /* cast-away const */
+ struct _mesa_HashTable *table2 = (struct _mesa_HashTable *) table;
+ struct hash_entry *entry;
+ struct _mesa_HashTable *clonetable;
+
+ ASSERT(table);
+ mtx_lock(&table2->Mutex);
+
+ clonetable = _mesa_NewHashTable();
+ assert(clonetable);
+ hash_table_foreach(table->ht, entry) {
+ _mesa_HashInsert(clonetable, (GLint)(uintptr_t)entry->key, entry->data);
+ }
+
+ mtx_unlock(&table2->Mutex);
+
+ return clonetable;
+}
+
+
+/**
+ * Walk over all entries in a hash table, calling callback function for each.
+ * Note: we use a separate mutex in this function to avoid a recursive
+ * locking deadlock (in case the callback calls _mesa_HashRemove()) and to
+ * prevent multiple threads/contexts from getting tangled up.
+ * A lock-less version of this function could be used when the table will
+ * not be modified.
+ * \param table the hash table to walk
+ * \param callback the callback function
+ * \param userData arbitrary pointer to pass along to the callback
+ * (this is typically a struct gl_context pointer)
+ */
+void
+_mesa_HashWalk(const struct _mesa_HashTable *table,
+ void (*callback)(GLuint key, void *data, void *userData),
+ void *userData)
+{
+ /* cast-away const */
+ struct _mesa_HashTable *table2 = (struct _mesa_HashTable *) table;
+ struct hash_entry *entry;
+
+ ASSERT(table);
+ ASSERT(callback);
+ mtx_lock(&table2->WalkMutex);
+ 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);
+ mtx_unlock(&table2->WalkMutex);
+}
+
+static void
+debug_print_entry(GLuint key, void *data, void *userData)
+{
+ _mesa_debug(NULL, "%u %p\n", key, data);
+}