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

Unified Diff: webrtc/base/task_queue_gcd.cc

Issue 2708353003: Add support for priorities to TaskQueue. (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 d5a4a6c1c6b59867261456224c033d9f134bd1b3..296da16fdb554d64255a7ac7756489b088e419bb 100644
--- a/webrtc/base/task_queue_gcd.cc
+++ b/webrtc/base/task_queue_gcd.cc
@@ -21,6 +21,22 @@
#include "webrtc/base/task_queue_posix.h"
namespace rtc {
+namespace {
+
+using Priority = TaskQueue::Priority;
+
+int TaskQueuePriorityToGCD(Priority priority) {
+ switch (priority) {
+ case Priority::NORMAL:
+ return DISPATCH_QUEUE_PRIORITY_DEFAULT;
+ case Priority::HIGH:
+ return DISPATCH_QUEUE_PRIORITY_HIGH;
+ case Priority::LOW:
+ return DISPATCH_QUEUE_PRIORITY_LOW;
+ }
+}
+}
+
using internal::GetQueuePtrTls;
using internal::AutoSetCurrentQueuePtr;
@@ -94,7 +110,7 @@ struct TaskQueue::PostTaskAndReplyContext : public TaskQueue::TaskContext {
dispatch_queue_t reply_queue_;
};
-TaskQueue::TaskQueue(const char* queue_name)
+TaskQueue::TaskQueue(const char* queue_name, Priority priority /*= NORMAL*/)
: queue_(dispatch_queue_create(queue_name, DISPATCH_QUEUE_SERIAL)),
context_(new QueueContext(this)) {
RTC_DCHECK(queue_name);
@@ -104,6 +120,9 @@ TaskQueue::TaskQueue(const char* queue_name)
// to the queue is released. This may run after the TaskQueue object has
// been deleted.
dispatch_set_finalizer_f(queue_, &QueueContext::DeleteContext);
+
+ dispatch_set_target_queue(
+ queue_, dispatch_get_global_queue(TaskQueuePriorityToGCD(priority), 0));
}
TaskQueue::~TaskQueue() {
« 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