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

Unified Diff: webrtc/base/task_queue_gcd.cc

Issue 2709603002: Fix potential deadlock in TaskQueue's libevent PostTaskAndReply implementation (Closed)
Patch Set: Address comments 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
« no previous file with comments | « webrtc/base/task_queue.h ('k') | webrtc/base/task_queue_libevent.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..d5a4a6c1c6b59867261456224c033d9f134bd1b3 100644
--- a/webrtc/base/task_queue_gcd.cc
+++ b/webrtc/base/task_queue_gcd.cc
@@ -69,14 +69,13 @@ 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_);
- }
- ~PostTaskAndReplyContext() override {
- dispatch_release(first_queue_ctx->queue->queue_);
+ dispatch_retain(reply_queue_);
}
+ ~PostTaskAndReplyContext() override { dispatch_release(reply_queue_); }
static void RunTask(void* context) {
auto* rc = static_cast<PostTaskAndReplyContext*>(context);
@@ -87,11 +86,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)
« no previous file with comments | « webrtc/base/task_queue.h ('k') | webrtc/base/task_queue_libevent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698