VkPipelineCache: Do not publically expose internal mutexes They make it unnecessarily easy to write code that violates the mutex lock requirements. Replace with the `getOrCreate` pattern already used in vk::Device, which keeps the locking internal. This change fixes a couple of places that we were accesssing data without correct locking (real bugs). Bug: b/153194656 Change-Id: I132c450594f4042160b575197789bca7f1a5e25f Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/43650 Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: Ben Clayton <bclayton@google.com> Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Vulkan/VkDevice.hpp b/src/Vulkan/VkDevice.hpp index 3ba442d..8931949 100644 --- a/src/Vulkan/VkDevice.hpp +++ b/src/Vulkan/VkDevice.hpp
@@ -86,8 +86,14 @@ }; }; + // getOrCreate() queries the cache for a Routine with the given key. + // If one is found, it is returned, otherwise createRoutine(key) is + // called, the returned Routine is added to the cache, and it is + // returned. + // Function must be a function of the signature: + // std::shared_ptr<rr::Routine>(const Key &) template<typename Function> - std::shared_ptr<rr::Routine> getOrCreate(const Key &key, Function createRoutine) + std::shared_ptr<rr::Routine> getOrCreate(const Key &key, Function &&createRoutine) { std::lock_guard<std::mutex> lock(mutex);