From c558118f70c1305b16b117725ef81745b5218fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Wed, 5 Oct 2016 19:01:57 +0200 Subject: [PATCH] libs/vkd3d: Re-use vkd3d_array_reserve() in d3d12_fence_SetEventOnCompletion(). --- libs/vkd3d/command.c | 27 +++++++-------------------- libs/vkd3d/vkd3d_private.h | 4 ++-- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 1baddb83..af099f43 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -179,21 +179,12 @@ static HRESULT STDMETHODCALLTYPE d3d12_fence_SetEventOnCompletion(ID3D12Fence *i } } - if (fence->event_array_size == fence->event_count) + if (!vkd3d_array_reserve((void **)&fence->events, &fence->events_size, + fence->event_count + 1, sizeof(*fence->events))) { - unsigned int new_size = 2 * fence->event_array_size; - struct vkd3d_waiting_event *new_events; - - TRACE("Resizing waiting events array from %u to %u.\n", fence->event_array_size, new_size); - - if (!(new_events = vkd3d_realloc(fence->events, new_size * sizeof(*fence->events)))) - { - pthread_mutex_unlock(&fence->mutex); - return E_OUTOFMEMORY; - } - - fence->event_array_size = new_size; - fence->events = new_events; + WARN("Failed to add event.\n"); + pthread_mutex_unlock(&fence->mutex); + return E_OUTOFMEMORY; } fence->events[fence->event_count].value = value; @@ -280,12 +271,8 @@ static HRESULT d3d12_fence_init(struct d3d12_fence *fence, struct d3d12_device * if (flags) FIXME("Ignoring flags %#x.\n", flags); - fence->event_array_size = 2; - if (!(fence->events = vkd3d_calloc(fence->event_array_size, sizeof(*fence->events)))) - { - pthread_mutex_destroy(&fence->mutex); - return E_OUTOFMEMORY; - } + fence->events = NULL; + fence->events_size = 0; fence->event_count = 0; fence->device = device; diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 66554474..d461a0f3 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -69,9 +69,9 @@ struct d3d12_fence UINT64 value; pthread_mutex_t mutex; - unsigned int event_array_size; - unsigned int event_count; struct vkd3d_waiting_event *events; + size_t events_size; + size_t event_count; struct d3d12_device *device; };