[Mesa-dev] [PATCH 03/18] util: Add a pointer map clone function
Thomas Helland
thomashelland90 at gmail.com
Wed Apr 11 18:48:12 UTC 2018
---
src/util/pointer_map.c | 23 +++++++++++++++++++++++
src/util/pointer_map.h | 3 +++
2 files changed, 26 insertions(+)
diff --git a/src/util/pointer_map.c b/src/util/pointer_map.c
index 8076bd827f..463fa19282 100644
--- a/src/util/pointer_map.c
+++ b/src/util/pointer_map.c
@@ -102,6 +102,29 @@ _mesa_pointer_map_create(void *mem_ctx)
return map;
}
+struct pointer_map *
+_mesa_pointer_map_clone(struct pointer_map *src, void *dst_mem_ctx)
+{
+ struct pointer_map *pm = ralloc(dst_mem_ctx, struct pointer_map);
+
+ if (pm == NULL)
+ return NULL;
+
+ memcpy(pm, src, sizeof(struct pointer_map));
+
+ pm->map = ralloc_array(pm, struct map_entry, pm->size);
+ pm->metadata = ralloc_array(pm, uint8_t, pm->size);
+
+ if (pm->map == NULL || pm->metadata == NULL) {
+ ralloc_free(pm);
+ return NULL;
+ }
+
+ memcpy(pm->map, src->map, pm->size * sizeof(struct map_entry));
+ memcpy(pm->metadata, src->metadata, pm->size * sizeof(uint8_t));
+
+ return pm;
+}
/**
* Frees the pointer map.
diff --git a/src/util/pointer_map.h b/src/util/pointer_map.h
index e1cef418d8..4bfc306a5f 100644
--- a/src/util/pointer_map.h
+++ b/src/util/pointer_map.h
@@ -55,6 +55,9 @@ struct pointer_map {
struct pointer_map *
_mesa_pointer_map_create(void *mem_ctx);
+struct pointer_map *
+_mesa_pointer_map_clone(struct pointer_map *, void *dst_mem_ctx);
+
void _mesa_pointer_map_destroy(struct pointer_map *map,
void (*delete_function)(struct map_entry *entry));
--
2.16.2
More information about the mesa-dev
mailing list