aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Macnak <natsu@google.com>2024-03-15 16:08:31 -0700
committerJason Macnak <natsu@google.com>2024-03-15 16:08:31 -0700
commit3dc9050f12b0ed4a450ffc7658b34009543ad451 (patch)
tree8dc26aa11cfadf4a3b6601d7bedb6e1f66c07cb4
parentc63f29e5f3a86f07b8575c31b444dffa9bbfb50b (diff)
downloadaemu-3dc9050f12b0ed4a450ffc7658b34009543ad451.tar.gz
Avoid holding device lock while destroying specific context
Bug: b/329287602 Test: GfxstreamEnd2EndVkTest.MultiThreadedShutdown with 50000 iterations Change-Id: I923ef0f99f12cd273278aadf7059541f7312eab7
-rw-r--r--host-common/address_space_device.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/host-common/address_space_device.cpp b/host-common/address_space_device.cpp
index c7951be..73d7f63 100644
--- a/host-common/address_space_device.cpp
+++ b/host-common/address_space_device.cpp
@@ -69,8 +69,22 @@ public:
void destroyHandle(uint32_t handle) {
AS_DEVICE_DPRINT("erase handle: %u", handle);
- AutoLock lock(mContextsLock);
- mContexts.erase(handle);
+
+ std::unique_ptr<AddressSpaceDeviceContext> context;
+
+ {
+ AutoLock lock(mContextsLock);
+
+ auto contextDescriptionIt = mContexts.find(handle);
+ if (contextDescriptionIt == mContexts.end()) return;
+ auto& contextDescription = contextDescriptionIt->second;
+
+ context = std::move(contextDescription.device_context);
+
+ mContexts.erase(contextDescriptionIt);
+ }
+
+ // Destroy `context` without holding the lock.
}
void tellPingInfo(uint32_t handle, uint64_t gpa) {