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

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
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..802ef4f0fe55ea69b4bc3ad3b3eaeb5af1ccd5a1 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,15 @@ 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();
- gpu_.reset();
+ DisconnectGpuOnThread();
}
void ClientGpuMemoryBufferManager::AllocateGpuMemoryBufferOnThread(
@@ -76,9 +72,12 @@ 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::DeletedGpuMemoryBuffer(
@@ -138,4 +137,25 @@ void ClientGpuMemoryBufferManager::SetDestructionSyncToken(
sync_token);
}
+void ClientGpuMemoryBufferManager::DisconnectGpuOnThread() {
+ if (gpu_.is_bound()) {
sadrul 2017/01/21 02:54:31 early return if not bound?
Ken Rockot(use gerrit already) 2017/01/23 18:00:49 Done
+ gpu_.reset();
+ for (auto& waiter : pending_allocation_waiters_)
+ waiter->Signal();
+ pending_allocation_waiters_.clear();
+ }
+}
+
+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();
+}
+
} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698