Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(855)

Unified Diff: services/ui/public/cpp/gpu/client_gpu_memory_buffer_manager.cc

Issue 2651443002: Fix potential shutdown deadlock in UI service (Closed)
Patch Set: . Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/ui/public/cpp/gpu/client_gpu_memory_buffer_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/ui/public/cpp/gpu/client_gpu_memory_buffer_manager.cc
diff --git a/services/ui/public/cpp/gpu/client_gpu_memory_buffer_manager.cc b/services/ui/public/cpp/gpu/client_gpu_memory_buffer_manager.cc
index e91fce823c9a275b56d5c4d4c2ac701edd965d31..efff978265a194c569cf66a21390ef61eb3c0bee 100644
--- a/services/ui/public/cpp/gpu/client_gpu_memory_buffer_manager.cc
+++ b/services/ui/public/cpp/gpu/client_gpu_memory_buffer_manager.cc
@@ -22,13 +22,6 @@ namespace ui {
namespace {
-void OnGpuMemoryBufferAllocated(gfx::GpuMemoryBufferHandle* ret_handle,
- base::WaitableEvent* wait,
- const gfx::GpuMemoryBufferHandle& handle) {
- *ret_handle = handle;
- wait->Signal();
-}
-
void NotifyDestructionOnCorrectThread(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const DestructionCallback& callback,
@@ -58,12 +51,24 @@ ClientGpuMemoryBufferManager::~ClientGpuMemoryBufferManager() {
void ClientGpuMemoryBufferManager::InitThread(mojom::GpuPtrInfo gpu_info) {
gpu_.Bind(std::move(gpu_info));
+ gpu_.set_connection_error_handler(
+ base::Bind(&ClientGpuMemoryBufferManager::DisconnectGpuOnThread,
+ base::Unretained(this)));
weak_ptr_ = weak_ptr_factory_.GetWeakPtr();
}
void ClientGpuMemoryBufferManager::TearDownThread() {
weak_ptr_factory_.InvalidateWeakPtrs();
+ DisconnectGpuOnThread();
+}
+
+void ClientGpuMemoryBufferManager::DisconnectGpuOnThread() {
+ if (!gpu_.is_bound())
+ return;
gpu_.reset();
+ for (auto& waiter : pending_allocation_waiters_)
+ waiter->Signal();
+ pending_allocation_waiters_.clear();
}
void ClientGpuMemoryBufferManager::AllocateGpuMemoryBufferOnThread(
@@ -76,9 +81,24 @@ void ClientGpuMemoryBufferManager::AllocateGpuMemoryBufferOnThread(
// |handle| and |wait| are both on the stack, and will be alive until |wait|
// is signaled. So it is safe for OnGpuMemoryBufferAllocated() to operate on
// these.
+ pending_allocation_waiters_.insert(wait);
gpu_->CreateGpuMemoryBuffer(
gfx::GpuMemoryBufferId(++counter_), size, format, usage,
- base::Bind(&OnGpuMemoryBufferAllocated, handle, wait));
+ base::Bind(
+ &ClientGpuMemoryBufferManager::OnGpuMemoryBufferAllocatedOnThread,
+ base::Unretained(this), handle, wait));
+}
+
+void ClientGpuMemoryBufferManager::OnGpuMemoryBufferAllocatedOnThread(
+ gfx::GpuMemoryBufferHandle* ret_handle,
+ base::WaitableEvent* wait,
+ const gfx::GpuMemoryBufferHandle& handle) {
+ auto it = pending_allocation_waiters_.find(wait);
+ DCHECK(it != pending_allocation_waiters_.end());
+ pending_allocation_waiters_.erase(it);
+
+ *ret_handle = handle;
+ wait->Signal();
}
void ClientGpuMemoryBufferManager::DeletedGpuMemoryBuffer(
« no previous file with comments | « services/ui/public/cpp/gpu/client_gpu_memory_buffer_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698