Switch vk command pool reset mutex to use SkMutex and guard it.

The original code here used a std::recusive_mutex. Looking at the code
I don't see today how any of the code that grabs the mutex could call
back into a function that grabs the mutex again on the same thread.
Maybe this was more of an issue back when this was originally added?
Regardless today it should be safe to just use an SkMutex.

Change-Id: I81c8ea3bf5b2defe893dd9fff7a6a2eda10cace8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/391256
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Greg Daniel 2021-03-31 13:04:47 -04:00 committed by Skia Commit-Bot
parent 10d45b867f
commit 0a6cd5a352
2 changed files with 14 additions and 13 deletions

View File

@ -398,7 +398,7 @@ void GrVkResourceProvider::recycleDescriptorSet(const GrVkDescriptorSet* descSet
}
GrVkCommandPool* GrVkResourceProvider::findOrCreateCommandPool() {
std::unique_lock<std::recursive_mutex> lock(fBackgroundMutex);
SkAutoMutexExclusive lock(fBackgroundMutex);
GrVkCommandPool* result;
if (fAvailableCommandPools.count()) {
result = fAvailableCommandPools.back();
@ -506,11 +506,14 @@ void GrVkResourceProvider::destroyResources() {
}
fActiveCommandPools.reset();
for (GrVkCommandPool* pool : fAvailableCommandPools) {
SkASSERT(pool->unique());
pool->unref();
{
SkAutoMutexExclusive lock(fBackgroundMutex);
for (GrVkCommandPool* pool : fAvailableCommandPools) {
SkASSERT(pool->unique());
pool->unref();
}
fAvailableCommandPools.reset();
}
fAvailableCommandPools.reset();
// We must release/destroy all command buffers and pipeline states before releasing the
// GrVkDescriptorSetManagers. Additionally, we must release all uniform buffers since they hold
@ -523,7 +526,7 @@ void GrVkResourceProvider::destroyResources() {
}
void GrVkResourceProvider::releaseUnlockedBackendObjects() {
std::unique_lock<std::recursive_mutex> lock(fBackgroundMutex);
SkAutoMutexExclusive lock(fBackgroundMutex);
for (GrVkCommandPool* pool : fAvailableCommandPools) {
SkASSERT(pool->unique());
pool->unref();
@ -556,7 +559,7 @@ void GrVkResourceProvider::reset(GrVkCommandPool* pool) {
TRACE_EVENT0("skia.gpu", TRACE_FUNC);
SkASSERT(pool->unique());
pool->reset(fGpu);
std::unique_lock<std::recursive_mutex> providerLock(fBackgroundMutex);
SkAutoMutexExclusive lock(fBackgroundMutex);
fAvailableCommandPools.push_back(pool);
}

View File

@ -9,6 +9,7 @@
#define GrVkResourceProvider_DEFINED
#include "include/gpu/vk/GrVkTypes.h"
#include "include/private/SkMutex.h"
#include "include/private/SkTArray.h"
#include "src/core/SkLRUCache.h"
#include "src/core/SkTDynamicHash.h"
@ -26,9 +27,6 @@
#include "src/gpu/vk/GrVkSamplerYcbcrConversion.h"
#include "src/gpu/vk/GrVkUtil.h"
#include <mutex>
#include <thread>
class GrVkCommandPool;
class GrVkGpu;
class GrVkPipeline;
@ -318,8 +316,10 @@ private:
// Array of command pools that we are waiting on
SkSTArray<4, GrVkCommandPool*, true> fActiveCommandPools;
SkMutex fBackgroundMutex;
// Array of available command pools that are not in flight
SkSTArray<4, GrVkCommandPool*, true> fAvailableCommandPools;
SkSTArray<4, GrVkCommandPool*, true> fAvailableCommandPools SK_GUARDED_BY(fBackgroundMutex);
// Stores GrVkSampler objects that we've already created so we can reuse them across multiple
// GrVkPipelineStates
@ -335,8 +335,6 @@ private:
GrVkDescriptorSetManager::Handle fUniformDSHandle;
GrVkDescriptorSetManager::Handle fInputDSHandle;
std::recursive_mutex fBackgroundMutex;
};
#endif