| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 void* thread_context; | 42 void* thread_context; |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 void CALLBACK InitializeQueueThread(ULONG_PTR param) { | 45 void CALLBACK InitializeQueueThread(ULONG_PTR param) { |
| 46 MSG msg; | 46 MSG msg; |
| 47 ::PeekMessage(&msg, nullptr, WM_USER, WM_USER, PM_NOREMOVE); | 47 ::PeekMessage(&msg, nullptr, WM_USER, WM_USER, PM_NOREMOVE); |
| 48 ThreadStartupData* data = reinterpret_cast<ThreadStartupData*>(param); | 48 ThreadStartupData* data = reinterpret_cast<ThreadStartupData*>(param); |
| 49 ::TlsSetValue(GetQueuePtrTls(), data->thread_context); | 49 ::TlsSetValue(GetQueuePtrTls(), data->thread_context); |
| 50 data->started->Set(); | 50 data->started->Set(); |
| 51 } | 51 } |
| 52 |
| 53 ThreadPriority TaskQueuePriorityToThreadPriority(TaskQueue::Priority priority) { |
| 54 switch (priority) { |
| 55 case TaskQueue::HIGH: |
| 56 return kRealtimePriority; |
| 57 case TaskQueue::LOW: |
| 58 return kLowPriority; |
| 59 case TaskQueue::NORMAL: |
| 60 default: |
| 61 break; |
| 62 } |
| 63 return kNormalPriority; |
| 64 } |
| 52 } // namespace | 65 } // namespace |
| 53 | 66 |
| 54 class TaskQueue::MultimediaTimer { | 67 class TaskQueue::MultimediaTimer { |
| 55 public: | 68 public: |
| 56 // kMaxTimers defines the limit of how many MultimediaTimer instances should | 69 // kMaxTimers defines the limit of how many MultimediaTimer instances should |
| 57 // be created. | 70 // be created. |
| 58 // Background: The maximum number of supported handles for Wait functions, is | 71 // Background: The maximum number of supported handles for Wait functions, is |
| 59 // MAXIMUM_WAIT_OBJECTS - 1 (63). | 72 // MAXIMUM_WAIT_OBJECTS - 1 (63). |
| 60 // There are some ways to work around the limitation but as it turns out, the | 73 // There are some ways to work around the limitation but as it turns out, the |
| 61 // limit of concurrently active multimedia timers per process, is much lower, | 74 // limit of concurrently active multimedia timers per process, is much lower, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 } | 151 } |
| 139 } | 152 } |
| 140 | 153 |
| 141 HANDLE event_ = nullptr; | 154 HANDLE event_ = nullptr; |
| 142 MMRESULT timer_id_ = 0; | 155 MMRESULT timer_id_ = 0; |
| 143 std::unique_ptr<QueuedTask> task_; | 156 std::unique_ptr<QueuedTask> task_; |
| 144 | 157 |
| 145 RTC_DISALLOW_COPY_AND_ASSIGN(MultimediaTimer); | 158 RTC_DISALLOW_COPY_AND_ASSIGN(MultimediaTimer); |
| 146 }; | 159 }; |
| 147 | 160 |
| 148 TaskQueue::TaskQueue(const char* queue_name) | 161 TaskQueue::TaskQueue(const char* queue_name, Priority priority /*= NORMAL*/) |
| 149 : thread_(&TaskQueue::ThreadMain, this, queue_name) { | 162 : thread_(&TaskQueue::ThreadMain, |
| 163 this, |
| 164 queue_name, |
| 165 TaskQueuePriorityToThreadPriority(priority)) { |
| 150 RTC_DCHECK(queue_name); | 166 RTC_DCHECK(queue_name); |
| 151 thread_.Start(); | 167 thread_.Start(); |
| 152 Event event(false, false); | 168 Event event(false, false); |
| 153 ThreadStartupData startup = {&event, this}; | 169 ThreadStartupData startup = {&event, this}; |
| 154 RTC_CHECK(thread_.QueueAPC(&InitializeQueueThread, | 170 RTC_CHECK(thread_.QueueAPC(&InitializeQueueThread, |
| 155 reinterpret_cast<ULONG_PTR>(&startup))); | 171 reinterpret_cast<ULONG_PTR>(&startup))); |
| 156 event.Wait(Event::kForever); | 172 event.Wait(Event::kForever); |
| 157 } | 173 } |
| 158 | 174 |
| 159 TaskQueue::~TaskQueue() { | 175 TaskQueue::~TaskQueue() { |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 } | 371 } |
| 356 } else { | 372 } else { |
| 357 ::TranslateMessage(&msg); | 373 ::TranslateMessage(&msg); |
| 358 ::DispatchMessage(&msg); | 374 ::DispatchMessage(&msg); |
| 359 } | 375 } |
| 360 } | 376 } |
| 361 return msg.message != WM_QUIT; | 377 return msg.message != WM_QUIT; |
| 362 } | 378 } |
| 363 | 379 |
| 364 } // namespace rtc | 380 } // namespace rtc |
| OLD | NEW |