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

Unified Diff: webrtc/base/task_queue_gcd.cc

Issue 2709603002: Fix potential deadlock in TaskQueue's libevent PostTaskAndReply implementation (Closed)
Patch Set: Update comment Created 3 years, 10 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: webrtc/base/task_queue_gcd.cc
diff --git a/webrtc/base/task_queue_gcd.cc b/webrtc/base/task_queue_gcd.cc
index 2c7d649fc9598723994189ee39f82b26e89c1111..ea0bdc970e54f5a28a8309495e9d5fa323bc09ef 100644
--- a/webrtc/base/task_queue_gcd.cc
+++ b/webrtc/base/task_queue_gcd.cc
@@ -69,13 +69,14 @@ struct TaskQueue::PostTaskAndReplyContext : public TaskQueue::TaskContext {
std::unique_ptr<QueuedTask> second_task)
: TaskContext(second_queue_ctx, std::move(second_task)),
first_queue_ctx(first_queue_ctx),
- first_task(std::move(first_task)) {
+ first_task(std::move(first_task)),
+ reply_queue_(second_queue_ctx->queue->queue_) {
// Retain the reply queue for as long as this object lives.
// If we don't, we may have memory leaks and/or failures.
- dispatch_retain(first_queue_ctx->queue->queue_);
+ dispatch_retain(reply_queue_);
}
~PostTaskAndReplyContext() override {
- dispatch_release(first_queue_ctx->queue->queue_);
+ dispatch_release(reply_queue_);
}
static void RunTask(void* context) {
@@ -87,11 +88,12 @@ struct TaskQueue::PostTaskAndReplyContext : public TaskQueue::TaskContext {
}
// Post the reply task. This hands the work over to the parent struct.
// This task will eventually delete |this|.
- dispatch_async_f(rc->queue_ctx->queue->queue_, rc, &TaskContext::RunTask);
+ dispatch_async_f(rc->reply_queue_, rc, &TaskContext::RunTask);
}
QueueContext* const first_queue_ctx;
std::unique_ptr<QueuedTask> first_task;
+ dispatch_queue_t reply_queue_;
};
TaskQueue::TaskQueue(const char* queue_name)

Powered by Google App Engine
This is Rietveld 408576698