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

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

Issue 2728663008: Increase tick precision in TaskQueue on Windows 64. (Closed)
Patch Set: Created 3 years, 9 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_unittest.cc ('k') | no next file » | 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 case Priority::LOW: 59 case Priority::LOW:
60 return kLowPriority; 60 return kLowPriority;
61 case Priority::NORMAL: 61 case Priority::NORMAL:
62 return kNormalPriority; 62 return kNormalPriority;
63 default: 63 default:
64 RTC_NOTREACHED(); 64 RTC_NOTREACHED();
65 break; 65 break;
66 } 66 }
67 return kNormalPriority; 67 return kNormalPriority;
68 } 68 }
69
70 DWORD GetTick() {
71 static const UINT kPeriod = 1;
72 bool high_res = (timeBeginPeriod(kPeriod) == TIMERR_NOERROR);
73 DWORD ret = timeGetTime();
henrika_webrtc 2017/03/03 12:24:55 What happens if high_res is false?
tommi 2017/03/03 12:39:01 Default behavior of timeGetTime(): https://msdn.m
henrika_webrtc 2017/03/03 12:42:32 Got it. I was more thinking about what will be ret
tommi 2017/03/03 12:59:34 TIMERR_NOCANDO is one possibility. I don't think t
henrika_webrtc 2017/03/03 13:00:53 Sorry. My brain added a {} below and I therefore f
tommi 2017/03/03 13:10:21 ack :)
74 if (high_res)
75 timeEndPeriod(kPeriod);
76 return ret;
77 }
78
69 } // namespace 79 } // namespace
70 80
71 class TaskQueue::MultimediaTimer { 81 class TaskQueue::MultimediaTimer {
72 public: 82 public:
73 // kMaxTimers defines the limit of how many MultimediaTimer instances should 83 // kMaxTimers defines the limit of how many MultimediaTimer instances should
74 // be created. 84 // be created.
75 // Background: The maximum number of supported handles for Wait functions, is 85 // Background: The maximum number of supported handles for Wait functions, is
76 // MAXIMUM_WAIT_OBJECTS - 1 (63). 86 // MAXIMUM_WAIT_OBJECTS - 1 (63).
77 // There are some ways to work around the limitation but as it turns out, the 87 // There are some ways to work around the limitation but as it turns out, the
78 // limit of concurrently active multimedia timers per process, is much lower, 88 // limit of concurrently active multimedia timers per process, is much lower,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 217 }
208 } 218 }
209 219
210 void TaskQueue::PostDelayedTask(std::unique_ptr<QueuedTask> task, 220 void TaskQueue::PostDelayedTask(std::unique_ptr<QueuedTask> task,
211 uint32_t milliseconds) { 221 uint32_t milliseconds) {
212 WPARAM wparam; 222 WPARAM wparam;
213 #if defined(_WIN64) 223 #if defined(_WIN64)
214 // GetTickCount() returns a fairly coarse tick count (resolution or about 8ms) 224 // GetTickCount() returns a fairly coarse tick count (resolution or about 8ms)
215 // so this compensation isn't that accurate, but since we have unused 32 bits 225 // so this compensation isn't that accurate, but since we have unused 32 bits
216 // on Win64, we might as well use them. 226 // on Win64, we might as well use them.
217 wparam = (static_cast<WPARAM>(::GetTickCount()) << 32) | milliseconds; 227 wparam = (static_cast<WPARAM>(GetTick()) << 32) | milliseconds;
218 #else 228 #else
219 wparam = milliseconds; 229 wparam = milliseconds;
220 #endif 230 #endif
221 if (::PostThreadMessage(thread_.GetThreadRef(), WM_QUEUE_DELAYED_TASK, wparam, 231 if (::PostThreadMessage(thread_.GetThreadRef(), WM_QUEUE_DELAYED_TASK, wparam,
222 reinterpret_cast<LPARAM>(task.get()))) { 232 reinterpret_cast<LPARAM>(task.get()))) {
223 task.release(); 233 task.release();
224 } 234 }
225 } 235 }
226 236
227 void TaskQueue::PostTaskAndReply(std::unique_ptr<QueuedTask> task, 237 void TaskQueue::PostTaskAndReply(std::unique_ptr<QueuedTask> task,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 if (task->Run()) 328 if (task->Run())
319 delete task; 329 delete task;
320 break; 330 break;
321 } 331 }
322 case WM_QUEUE_DELAYED_TASK: { 332 case WM_QUEUE_DELAYED_TASK: {
323 std::unique_ptr<QueuedTask> task( 333 std::unique_ptr<QueuedTask> task(
324 reinterpret_cast<QueuedTask*>(msg.lParam)); 334 reinterpret_cast<QueuedTask*>(msg.lParam));
325 uint32_t milliseconds = msg.wParam & 0xFFFFFFFF; 335 uint32_t milliseconds = msg.wParam & 0xFFFFFFFF;
326 #if defined(_WIN64) 336 #if defined(_WIN64)
327 // Subtract the time it took to queue the timer. 337 // Subtract the time it took to queue the timer.
328 const DWORD now = GetTickCount(); 338 const DWORD now = GetTick();
329 DWORD post_time = now - (msg.wParam >> 32); 339 DWORD post_time = now - (msg.wParam >> 32);
330 milliseconds = 340 milliseconds =
331 post_time > milliseconds ? 0 : milliseconds - post_time; 341 post_time > milliseconds ? 0 : milliseconds - post_time;
332 #endif 342 #endif
333 bool timer_queued = false; 343 bool timer_queued = false;
334 if (timers->size() < MultimediaTimer::kMaxTimers) { 344 if (timers->size() < MultimediaTimer::kMaxTimers) {
335 MultimediaTimer* timer = nullptr; 345 MultimediaTimer* timer = nullptr;
336 auto available = std::find_if( 346 auto available = std::find_if(
337 timers->begin(), timers->end(), 347 timers->begin(), timers->end(),
338 [](const MultimediaTimer& t) { return !t.is_active(); }); 348 [](const MultimediaTimer& t) { return !t.is_active(); });
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 } 385 }
376 } else { 386 } else {
377 ::TranslateMessage(&msg); 387 ::TranslateMessage(&msg);
378 ::DispatchMessage(&msg); 388 ::DispatchMessage(&msg);
379 } 389 }
380 } 390 }
381 return msg.message != WM_QUIT; 391 return msg.message != WM_QUIT;
382 } 392 }
383 393
384 } // namespace rtc 394 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/task_queue_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698