From 37201e742fcfbf8fd212b96c5197ea17372ebc8f Mon Sep 17 00:00:00 2001 From: prideout Date: Fri, 18 Jan 2019 15:36:13 -0800 Subject: [PATCH] Add missing locks to VulkanDriver. --- filament/src/driver/vulkan/VulkanDriver.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/filament/src/driver/vulkan/VulkanDriver.h b/filament/src/driver/vulkan/VulkanDriver.h index 440eec1a5b..674f8e603c 100644 --- a/filament/src/driver/vulkan/VulkanDriver.h +++ b/filament/src/driver/vulkan/VulkanDriver.h @@ -82,16 +82,19 @@ private: using Blob = std::vector; using HandleMap = std::unordered_map; HandleMap mHandleMap; + std::mutex mHandleMapMutex; HandleBase::HandleId mNextId = 1; template Handle alloc_handle() { + std::lock_guard lock(mHandleMapMutex); mHandleMap[mNextId] = Blob(sizeof(Dp)); return Handle(mNextId++); } template Dp* handle_cast(HandleMap& handleMap, Handle& handle) noexcept { + std::lock_guard lock(mHandleMapMutex); assert(handle); auto iter = handleMap.find(handle.getId()); assert(iter != handleMap.end()); @@ -102,6 +105,7 @@ private: template const Dp* handle_const_cast(HandleMap& handleMap, const Handle& handle) noexcept { + std::lock_guard lock(mHandleMapMutex); assert(handle); auto iter = handleMap.find(handle.getId()); assert(iter != handleMap.end()); @@ -112,6 +116,7 @@ private: template Dp* construct_handle(HandleMap& handleMap, Handle& handle, ARGS&& ... args) noexcept { + std::lock_guard lock(mHandleMapMutex); auto iter = handleMap.find(handle.getId()); assert(iter != handleMap.end()); Blob& blob = iter->second; @@ -123,8 +128,13 @@ private: template void destruct_handle(HandleMap& handleMap, Handle& handle) noexcept { + std::lock_guard lock(mHandleMapMutex); // Call the destructor, remove the blob, don't bother reclaiming the integer id. - handle_cast(handleMap, handle)->~Dp(); + auto iter = handleMap.find(handle.getId()); + assert(iter != handleMap.end()); + Blob& blob = iter->second; + assert(blob.size() == sizeof(Dp)); + reinterpret_cast(blob.data())->~Dp(); handleMap.erase(handle.getId()); }