diff --git a/src/venus/vkr_context.c b/src/venus/vkr_context.c index f4f3d95..4ffff55 100644 --- a/src/venus/vkr_context.c +++ b/src/venus/vkr_context.c @@ -27,6 +27,24 @@ #include "vkr_ring.h" #include "vkr_transport.h" +void +vkr_context_add_instance(struct vkr_context *ctx, struct vkr_instance *instance) +{ + vkr_context_add_object(ctx, &instance->base); + + assert(!ctx->instance); + ctx->instance = instance; +} + +void +vkr_context_remove_instance(struct vkr_context *ctx, struct vkr_instance *instance) +{ + assert(ctx->instance && ctx->instance == instance); + ctx->instance = NULL; + + vkr_context_remove_object(ctx, &instance->base); +} + static void vkr_dispatch_debug_log(UNUSED struct vn_dispatch_context *dispatch, const char *msg) { diff --git a/src/venus/vkr_context.h b/src/venus/vkr_context.h index 9e3aba8..3a5c8fb 100644 --- a/src/venus/vkr_context.h +++ b/src/venus/vkr_context.h @@ -93,4 +93,10 @@ vkr_context_remove_objects(struct vkr_context *ctx, struct list_head *objects) /* objects should be reinitialized if to be reused */ } +void +vkr_context_add_instance(struct vkr_context *ctx, struct vkr_instance *instance); + +void +vkr_context_remove_instance(struct vkr_context *ctx, struct vkr_instance *instance); + #endif /* VKR_CONTEXT_H */ diff --git a/src/venus/vkr_instance.c b/src/venus/vkr_instance.c index 33fdef7..71aaf4a 100644 --- a/src/venus/vkr_instance.c +++ b/src/venus/vkr_instance.c @@ -222,9 +222,7 @@ vkr_dispatch_vkCreateInstance(struct vn_dispatch_context *dispatch, } } - vkr_context_add_object(ctx, &instance->base); - - ctx->instance = instance; + vkr_context_add_instance(ctx, instance); } void @@ -248,7 +246,7 @@ vkr_instance_destroy(struct vkr_context *ctx, struct vkr_instance *instance) free(instance->physical_device_handles); free(instance->physical_devices); - vkr_context_remove_object(ctx, &instance->base); + vkr_context_remove_instance(ctx, instance); } static void @@ -264,8 +262,6 @@ vkr_dispatch_vkDestroyInstance(struct vn_dispatch_context *dispatch, } vkr_instance_destroy(ctx, instance); - - ctx->instance = NULL; } void