From: Timothy Arceri Date: Wed, 28 Aug 2013 02:32:18 +0000 (+1000) Subject: mesa: Add a clone function to mesa hash X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=60f435319c7046658ece72167c42e09c7a7a44e0;p=mesa.git mesa: Add a clone function to mesa hash V2: const qualify table parameter Signed-off-by: Timothy Arceri Reviewed-by: Brian Paul --- diff --git a/src/mesa/main/hash.c b/src/mesa/main/hash.c index 6591af9a69a..b31fd483906 100644 --- a/src/mesa/main/hash.c +++ b/src/mesa/main/hash.c @@ -301,6 +301,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 diff --git a/src/mesa/main/hash.h b/src/mesa/main/hash.h index 142d2842c33..b34f32848a5 100644 --- a/src/mesa/main/hash.h +++ b/src/mesa/main/hash.h @@ -50,6 +50,9 @@ _mesa_HashDeleteAll(struct _mesa_HashTable *table, void (*callback)(GLuint key, void *data, void *userData), void *userData); +extern struct _mesa_HashTable * +_mesa_HashClone(const struct _mesa_HashTable *table); + extern void _mesa_HashWalk(const struct _mesa_HashTable *table, void (*callback)(GLuint key, void *data, void *userData),