diff options
Diffstat (limited to 'mesalib/src/util')
-rw-r--r-- | mesalib/src/util/ralloc.c | 26 | ||||
-rw-r--r-- | mesalib/src/util/ralloc.h | 15 | ||||
-rw-r--r-- | mesalib/src/util/u_atomic_test.c | 5 |
3 files changed, 42 insertions, 4 deletions
diff --git a/mesalib/src/util/ralloc.c b/mesalib/src/util/ralloc.c index 36bc61fd0..01719c888 100644 --- a/mesalib/src/util/ralloc.c +++ b/mesalib/src/util/ralloc.c @@ -271,6 +271,32 @@ ralloc_steal(const void *new_ctx, void *ptr) add_child(parent, info); } +void +ralloc_adopt(const void *new_ctx, void *old_ctx) +{ + ralloc_header *new_info, *old_info, *child; + + if (unlikely(old_ctx == NULL)) + return; + + old_info = get_header(old_ctx); + new_info = get_header(new_ctx); + + /* If there are no children, bail. */ + if (unlikely(old_info->child == NULL)) + return; + + /* Set all the children's parent to new_ctx; get a pointer to the last child. */ + for (child = old_info->child; child->next != NULL; child = child->next) { + child->parent = new_info; + } + + /* Connect the two lists together; parent them to new_ctx; make old_ctx empty. */ + child->next = new_info->child; + new_info->child = old_info->child; + old_info->child = NULL; +} + void * ralloc_parent(const void *ptr) { diff --git a/mesalib/src/util/ralloc.h b/mesalib/src/util/ralloc.h index f088a3627..7587e1190 100644 --- a/mesalib/src/util/ralloc.h +++ b/mesalib/src/util/ralloc.h @@ -46,16 +46,16 @@ #ifndef RALLOC_H #define RALLOC_H -#ifdef __cplusplus -extern "C" { -#endif - #include <stddef.h> #include <stdarg.h> #include <stdbool.h> #include "macros.h" +#ifdef __cplusplus +extern "C" { +#endif + /** * \def ralloc(ctx, type) * Allocate a new object chained off of the given context. @@ -235,6 +235,13 @@ void ralloc_free(void *ptr); void ralloc_steal(const void *new_ctx, void *ptr); /** + * Reparent all children from one context to another. + * + * This effectively calls ralloc_steal(new_ctx, child) for all children of \p old_ctx. + */ +void ralloc_adopt(const void *new_ctx, void *old_ctx); + +/** * Return the given pointer's ralloc context. */ void *ralloc_parent(const void *ptr); diff --git a/mesalib/src/util/u_atomic_test.c b/mesalib/src/util/u_atomic_test.c index 939cfe445..7844f6162 100644 --- a/mesalib/src/util/u_atomic_test.c +++ b/mesalib/src/util/u_atomic_test.c @@ -36,6 +36,11 @@ #include "u_atomic.h" +#ifdef _MSC_VER +#pragma warning( disable : 28112 ) /* Accessing a local variable via an Interlocked function */ +#pragma warning( disable : 28113 ) /* A variable which is accessed via an Interlocked function must always be accessed via an Interlocked function */ +#endif + /* Test only assignment-like operations, which are supported on all types */ #define test_atomic_assign(type, ones) \ |