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

Side by Side Diff: webrtc/base/task_queue_libevent.cc

Issue 2701283002: Add support for priorities in TaskQueue (Closed)
Patch Set: Rebase 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 unified diff | Download patch
« no previous file with comments | « webrtc/base/task_queue_gcd.cc ('k') | webrtc/base/task_queue_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 short events, 54 short events,
55 void (*callback)(int, short, void*), 55 void (*callback)(int, short, void*),
56 void* arg) { 56 void* arg) {
57 #if defined(_EVENT2_EVENT_H_) 57 #if defined(_EVENT2_EVENT_H_)
58 RTC_CHECK_EQ(0, event_assign(ev, base, fd, events, callback, arg)); 58 RTC_CHECK_EQ(0, event_assign(ev, base, fd, events, callback, arg));
59 #else 59 #else
60 event_set(ev, fd, events, callback, arg); 60 event_set(ev, fd, events, callback, arg);
61 RTC_CHECK_EQ(0, event_base_set(base, ev)); 61 RTC_CHECK_EQ(0, event_base_set(base, ev));
62 #endif 62 #endif
63 } 63 }
64
65 ThreadPriority TaskQueuePriorityToThreadPriority(TaskQueue::Priority priority) {
66 switch (priority) {
67 case TaskQueue::HIGH:
68 return kRealtimePriority;
69 case TaskQueue::LOW:
70 return kLowPriority;
71 case TaskQueue::NORMAL:
72 default:
73 break;
74 }
75 return kNormalPriority;
76 }
64 } // namespace 77 } // namespace
65 78
66 struct TaskQueue::QueueContext { 79 struct TaskQueue::QueueContext {
67 explicit QueueContext(TaskQueue* q) : queue(q), is_active(true) {} 80 explicit QueueContext(TaskQueue* q) : queue(q), is_active(true) {}
68 TaskQueue* queue; 81 TaskQueue* queue;
69 bool is_active; 82 bool is_active;
70 // Holds a list of events pending timers for cleanup when the loop exits. 83 // Holds a list of events pending timers for cleanup when the loop exits.
71 std::list<TimerEvent*> pending_timers_; 84 std::list<TimerEvent*> pending_timers_;
72 }; 85 };
73 86
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 std::move(task_), 139 std::move(task_),
127 post_time > milliseconds_ ? 0 : milliseconds_ - post_time); 140 post_time > milliseconds_ ? 0 : milliseconds_ - post_time);
128 return true; 141 return true;
129 } 142 }
130 143
131 std::unique_ptr<QueuedTask> task_; 144 std::unique_ptr<QueuedTask> task_;
132 const uint32_t milliseconds_; 145 const uint32_t milliseconds_;
133 const uint32_t posted_; 146 const uint32_t posted_;
134 }; 147 };
135 148
136 TaskQueue::TaskQueue(const char* queue_name) 149 TaskQueue::TaskQueue(const char* queue_name, Priority priority /*= NORMAL*/)
137 : event_base_(event_base_new()), 150 : event_base_(event_base_new()),
138 wakeup_event_(new event()), 151 wakeup_event_(new event()),
139 thread_(&TaskQueue::ThreadMain, this, queue_name) { 152 thread_(&TaskQueue::ThreadMain,
153 this,
154 queue_name,
155 TaskQueuePriorityToThreadPriority(priority)) {
140 RTC_DCHECK(queue_name); 156 RTC_DCHECK(queue_name);
141 int fds[2]; 157 int fds[2];
142 RTC_CHECK(pipe(fds) == 0); 158 RTC_CHECK(pipe(fds) == 0);
143 SetNonBlocking(fds[0]); 159 SetNonBlocking(fds[0]);
144 SetNonBlocking(fds[1]); 160 SetNonBlocking(fds[1]);
145 wakeup_pipe_out_ = fds[0]; 161 wakeup_pipe_out_ = fds[0];
146 wakeup_pipe_in_ = fds[1]; 162 wakeup_pipe_in_ = fds[1];
147 EventAssign(wakeup_event_.get(), event_base_, wakeup_pipe_out_, 163 EventAssign(wakeup_event_.get(), event_base_, wakeup_pipe_out_,
148 EV_READ | EV_PERSIST, OnWakeup, this); 164 EV_READ | EV_PERSIST, OnWakeup, this);
149 event_add(wakeup_event_.get(), 0); 165 event_add(wakeup_event_.get(), 0);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 CritScope lock(&pending_lock_); 341 CritScope lock(&pending_lock_);
326 pending_replies_.push_back(reply_task); 342 pending_replies_.push_back(reply_task);
327 } 343 }
328 344
329 void TaskQueue::ReplyTaskDone(PostAndReplyTask* reply_task) { 345 void TaskQueue::ReplyTaskDone(PostAndReplyTask* reply_task) {
330 CritScope lock(&pending_lock_); 346 CritScope lock(&pending_lock_);
331 pending_replies_.remove(reply_task); 347 pending_replies_.remove(reply_task);
332 } 348 }
333 349
334 } // namespace rtc 350 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/task_queue_gcd.cc ('k') | webrtc/base/task_queue_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698