summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/hash.c
diff options
context:
space:
mode:
authorTimothy Arceri <t_arceri@yahoo.com.au>2013-08-28 12:32:18 +1000
committerBrian Paul <brianp@vmware.com>2013-09-04 07:47:48 -0600
commit60f435319c7046658ece72167c42e09c7a7a44e0 (patch)
tree505528fce2e0a1e297765fa3418351711cf4ef56 /src/mesa/main/hash.c
parentf5badf467155599755258e2370845622d2e8c496 (diff)
downloadexternal_mesa3d-60f435319c7046658ece72167c42e09c7a7a44e0.zip
external_mesa3d-60f435319c7046658ece72167c42e09c7a7a44e0.tar.gz
external_mesa3d-60f435319c7046658ece72167c42e09c7a7a44e0.tar.bz2
mesa: Add a clone function to mesa hash
V2: const qualify table parameter Signed-off-by: Timothy Arceri <t_arceri@yahoo.com.au> Reviewed-by: Brian Paul <brianp@vmware.com>
Diffstat (limited to 'src/mesa/main/hash.c')
-rw-r--r--src/mesa/main/hash.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/mesa/main/hash.c b/src/mesa/main/hash.c
index 6591af9..b31fd48 100644
--- a/src/mesa/main/hash.c
+++ b/src/mesa/main/hash.c
@@ -302,6 +302,34 @@ _mesa_HashDeleteAll(struct _mesa_HashTable *table,
/**
+ * 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);
+ _glthread_LOCK_MUTEX(table2->Mutex);
+
+ clonetable = _mesa_NewHashTable();
+ assert(clonetable);
+ hash_table_foreach(table->ht, entry) {
+ _mesa_HashInsert(clonetable, (GLint)(uintptr_t)entry->key, entry->data);
+ }
+
+ _glthread_UNLOCK_MUTEX(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