OLD | NEW |
---|---|
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 short events, | 77 short events, |
78 void (*callback)(int, short, void*), | 78 void (*callback)(int, short, void*), |
79 void* arg) { | 79 void* arg) { |
80 #if defined(_EVENT2_EVENT_H_) | 80 #if defined(_EVENT2_EVENT_H_) |
81 RTC_CHECK_EQ(0, event_assign(ev, base, fd, events, callback, arg)); | 81 RTC_CHECK_EQ(0, event_assign(ev, base, fd, events, callback, arg)); |
82 #else | 82 #else |
83 event_set(ev, fd, events, callback, arg); | 83 event_set(ev, fd, events, callback, arg); |
84 RTC_CHECK_EQ(0, event_base_set(base, ev)); | 84 RTC_CHECK_EQ(0, event_base_set(base, ev)); |
85 #endif | 85 #endif |
86 } | 86 } |
87 | |
88 ThreadPriority TaskQueuePriorityToThreadPriority(TaskQueue::Priority priority) { | |
89 switch (priority) { | |
90 case TaskQueue::HIGH: | |
91 return kRealtimePriority; | |
92 case TaskQueue::LOW: | |
93 return kLowPriority; | |
94 case TaskQueue::NORMAL: | |
95 default: | |
the sun
2017/02/24 09:03:43
If compiler won't warn about an unhandled "case",
tommi
2017/02/24 17:34:41
Done.
| |
96 break; | |
97 } | |
98 return kNormalPriority; | |
99 } | |
87 } // namespace | 100 } // namespace |
88 | 101 |
89 struct TaskQueue::QueueContext { | 102 struct TaskQueue::QueueContext { |
90 explicit QueueContext(TaskQueue* q) : queue(q), is_active(true) {} | 103 explicit QueueContext(TaskQueue* q) : queue(q), is_active(true) {} |
91 TaskQueue* queue; | 104 TaskQueue* queue; |
92 bool is_active; | 105 bool is_active; |
93 // Holds a list of events pending timers for cleanup when the loop exits. | 106 // Holds a list of events pending timers for cleanup when the loop exits. |
94 std::list<TimerEvent*> pending_timers_; | 107 std::list<TimerEvent*> pending_timers_; |
95 }; | 108 }; |
96 | 109 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 std::move(task_), | 207 std::move(task_), |
195 post_time > milliseconds_ ? 0 : milliseconds_ - post_time); | 208 post_time > milliseconds_ ? 0 : milliseconds_ - post_time); |
196 return true; | 209 return true; |
197 } | 210 } |
198 | 211 |
199 std::unique_ptr<QueuedTask> task_; | 212 std::unique_ptr<QueuedTask> task_; |
200 const uint32_t milliseconds_; | 213 const uint32_t milliseconds_; |
201 const uint32_t posted_; | 214 const uint32_t posted_; |
202 }; | 215 }; |
203 | 216 |
204 TaskQueue::TaskQueue(const char* queue_name) | 217 TaskQueue::TaskQueue(const char* queue_name, Priority priority /*= NORMAL*/) |
205 : event_base_(event_base_new()), | 218 : event_base_(event_base_new()), |
206 wakeup_event_(new event()), | 219 wakeup_event_(new event()), |
207 thread_(&TaskQueue::ThreadMain, this, queue_name) { | 220 thread_(&TaskQueue::ThreadMain, |
221 this, | |
222 queue_name, | |
223 TaskQueuePriorityToThreadPriority(priority)) { | |
208 RTC_DCHECK(queue_name); | 224 RTC_DCHECK(queue_name); |
209 int fds[2]; | 225 int fds[2]; |
210 RTC_CHECK(pipe(fds) == 0); | 226 RTC_CHECK(pipe(fds) == 0); |
211 SetNonBlocking(fds[0]); | 227 SetNonBlocking(fds[0]); |
212 SetNonBlocking(fds[1]); | 228 SetNonBlocking(fds[1]); |
213 wakeup_pipe_out_ = fds[0]; | 229 wakeup_pipe_out_ = fds[0]; |
214 wakeup_pipe_in_ = fds[1]; | 230 wakeup_pipe_in_ = fds[1]; |
215 | 231 |
216 EventAssign(wakeup_event_.get(), event_base_, wakeup_pipe_out_, | 232 EventAssign(wakeup_event_.get(), event_base_, wakeup_pipe_out_, |
217 EV_READ | EV_PERSIST, OnWakeup, this); | 233 EV_READ | EV_PERSIST, OnWakeup, this); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 delete timer; | 416 delete timer; |
401 } | 417 } |
402 | 418 |
403 void TaskQueue::PrepareReplyTask(scoped_refptr<ReplyTaskOwnerRef> reply_task) { | 419 void TaskQueue::PrepareReplyTask(scoped_refptr<ReplyTaskOwnerRef> reply_task) { |
404 RTC_DCHECK(reply_task); | 420 RTC_DCHECK(reply_task); |
405 CritScope lock(&pending_lock_); | 421 CritScope lock(&pending_lock_); |
406 pending_replies_.push_back(std::move(reply_task)); | 422 pending_replies_.push_back(std::move(reply_task)); |
407 } | 423 } |
408 | 424 |
409 } // namespace rtc | 425 } // namespace rtc |
OLD | NEW |