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

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

Issue 2728663008: Increase tick precision in TaskQueue on Windows 64. (Closed)
Patch Set: Only define GetTick for win64 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 #if defined(_WIN64)
71 DWORD GetTick() {
72 static const UINT kPeriod = 1;
73 bool high_res = (timeBeginPeriod(kPeriod) == TIMERR_NOERROR);
74 DWORD ret = timeGetTime();
75 if (high_res)
76 timeEndPeriod(kPeriod);
77 return ret;
78 }
79 #endif
69 } // namespace 80 } // namespace
70 81
71 class TaskQueue::MultimediaTimer { 82 class TaskQueue::MultimediaTimer {
72 public: 83 public:
73 // kMaxTimers defines the limit of how many MultimediaTimer instances should 84 // kMaxTimers defines the limit of how many MultimediaTimer instances should
74 // be created. 85 // be created.
75 // Background: The maximum number of supported handles for Wait functions, is 86 // Background: The maximum number of supported handles for Wait functions, is
76 // MAXIMUM_WAIT_OBJECTS - 1 (63). 87 // MAXIMUM_WAIT_OBJECTS - 1 (63).
77 // There are some ways to work around the limitation but as it turns out, the 88 // 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, 89 // limit of concurrently active multimedia timers per process, is much lower,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 218 }
208 } 219 }
209 220
210 void TaskQueue::PostDelayedTask(std::unique_ptr<QueuedTask> task, 221 void TaskQueue::PostDelayedTask(std::unique_ptr<QueuedTask> task,
211 uint32_t milliseconds) { 222 uint32_t milliseconds) {
212 WPARAM wparam; 223 WPARAM wparam;
213 #if defined(_WIN64) 224 #if defined(_WIN64)
214 // GetTickCount() returns a fairly coarse tick count (resolution or about 8ms) 225 // 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 226 // so this compensation isn't that accurate, but since we have unused 32 bits
216 // on Win64, we might as well use them. 227 // on Win64, we might as well use them.
217 wparam = (static_cast<WPARAM>(::GetTickCount()) << 32) | milliseconds; 228 wparam = (static_cast<WPARAM>(GetTick()) << 32) | milliseconds;
218 #else 229 #else
219 wparam = milliseconds; 230 wparam = milliseconds;
220 #endif 231 #endif
221 if (::PostThreadMessage(thread_.GetThreadRef(), WM_QUEUE_DELAYED_TASK, wparam, 232 if (::PostThreadMessage(thread_.GetThreadRef(), WM_QUEUE_DELAYED_TASK, wparam,
222 reinterpret_cast<LPARAM>(task.get()))) { 233 reinterpret_cast<LPARAM>(task.get()))) {
223 task.release(); 234 task.release();
224 } 235 }
225 } 236 }
226 237
227 void TaskQueue::PostTaskAndReply(std::unique_ptr<QueuedTask> task, 238 void TaskQueue::PostTaskAndReply(std::unique_ptr<QueuedTask> task,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 if (task->Run()) 329 if (task->Run())
319 delete task; 330 delete task;
320 break; 331 break;
321 } 332 }
322 case WM_QUEUE_DELAYED_TASK: { 333 case WM_QUEUE_DELAYED_TASK: {
323 std::unique_ptr<QueuedTask> task( 334 std::unique_ptr<QueuedTask> task(
324 reinterpret_cast<QueuedTask*>(msg.lParam)); 335 reinterpret_cast<QueuedTask*>(msg.lParam));
325 uint32_t milliseconds = msg.wParam & 0xFFFFFFFF; 336 uint32_t milliseconds = msg.wParam & 0xFFFFFFFF;
326 #if defined(_WIN64) 337 #if defined(_WIN64)
327 // Subtract the time it took to queue the timer. 338 // Subtract the time it took to queue the timer.
328 const DWORD now = GetTickCount(); 339 const DWORD now = GetTick();
329 DWORD post_time = now - (msg.wParam >> 32); 340 DWORD post_time = now - (msg.wParam >> 32);
330 milliseconds = 341 milliseconds =
331 post_time > milliseconds ? 0 : milliseconds - post_time; 342 post_time > milliseconds ? 0 : milliseconds - post_time;
332 #endif 343 #endif
333 bool timer_queued = false; 344 bool timer_queued = false;
334 if (timers->size() < MultimediaTimer::kMaxTimers) { 345 if (timers->size() < MultimediaTimer::kMaxTimers) {
335 MultimediaTimer* timer = nullptr; 346 MultimediaTimer* timer = nullptr;
336 auto available = std::find_if( 347 auto available = std::find_if(
337 timers->begin(), timers->end(), 348 timers->begin(), timers->end(),
338 [](const MultimediaTimer& t) { return !t.is_active(); }); 349 [](const MultimediaTimer& t) { return !t.is_active(); });
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 } 386 }
376 } else { 387 } else {
377 ::TranslateMessage(&msg); 388 ::TranslateMessage(&msg);
378 ::DispatchMessage(&msg); 389 ::DispatchMessage(&msg);
379 } 390 }
380 } 391 }
381 return msg.message != WM_QUIT; 392 return msg.message != WM_QUIT;
382 } 393 }
383 394
384 } // namespace rtc 395 } // 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