From bed55ba330c30680916edb2ec852a12ea90cb566 Mon Sep 17 00:00:00 2001 From: Dennis Tsiang Date: Thu, 30 Sep 2021 08:46:35 +0100 Subject: [PATCH] Synchronise access to the ring buffer pool We need to synchronise access to the ring buffer pool in order to avoid concurrency bugs as multiple threads can mutate the state of the ring buffer and if we do not serialise these changes then they can result in errors. Change-Id: If96e1707716370bcf57416cd505d16aa75c0d68c Signed-off-by: Dennis Tsiang --- wsi/swapchain_base.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/wsi/swapchain_base.cpp b/wsi/swapchain_base.cpp index fb38a24..7f93c14 100644 --- a/wsi/swapchain_base.cpp +++ b/wsi/swapchain_base.cpp @@ -71,8 +71,10 @@ void swapchain_base::page_flip_thread() /* We want to present the oldest queued for present image from our present queue, * which we can find at the sc->pending_buffer_pool.head index. */ + std::unique_lock image_status_lock(m_image_status_mutex); auto pending_index = m_pending_buffer_pool.pop_front(); assert(pending_index.has_value()); + image_status_lock.unlock(); /* We may need to wait for the payload of the present sync of the oldest pending image to be finished. */ vk_res = image_wait_present(sc_images[*pending_index], timeout); @@ -466,7 +468,9 @@ VkResult swapchain_base::queue_present(VkQueue queue, const VkPresentInfoKHR *pr } m_swapchain_images[image_index].status = swapchain_image::PENDING; - m_pending_buffer_pool.push_back(image_index); + bool buffer_pool_res = m_pending_buffer_pool.push_back(image_index); + (void)buffer_pool_res; + assert(buffer_pool_res); m_page_flip_semaphore.post(); return VK_SUCCESS; }