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

Side by Side Diff: base/threading/platform_thread_win.cc

Issue 23147002: Enable high resolution time for TimeTicks::Now on Windows Canary (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Simpler sleep & rebase Created 7 years, 3 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 | « base/test/test_suite.cc ('k') | base/time/time.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/threading/platform_thread.h" 5 #include "base/threading/platform_thread.h"
6 6
7 #include "base/debug/alias.h" 7 #include "base/debug/alias.h"
8 #include "base/debug/profiler.h" 8 #include "base/debug/profiler.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/threading/thread_id_name_manager.h" 10 #include "base/threading/thread_id_name_manager.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 return PlatformThreadHandle(); 128 return PlatformThreadHandle();
129 } 129 }
130 130
131 // static 131 // static
132 void PlatformThread::YieldCurrentThread() { 132 void PlatformThread::YieldCurrentThread() {
133 ::Sleep(0); 133 ::Sleep(0);
134 } 134 }
135 135
136 // static 136 // static
137 void PlatformThread::Sleep(TimeDelta duration) { 137 void PlatformThread::Sleep(TimeDelta duration) {
138 ::Sleep(duration.InMillisecondsRoundedUp()); 138 // When measured with a high resolution clock, Sleep() sometimes returns much
139 // too early. We may need to call it repeatedly to get the desired duration.
140 TimeTicks end = TimeTicks::Now() + duration;
141 TimeTicks now;
142 while ((now = TimeTicks::Now()) < end)
143 ::Sleep((end - now).InMillisecondsRoundedUp());
139 } 144 }
140 145
141 // static 146 // static
142 void PlatformThread::SetName(const char* name) { 147 void PlatformThread::SetName(const char* name) {
143 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name); 148 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name);
144 149
145 // On Windows only, we don't need to tell the profiler about the "BrokerEvent" 150 // On Windows only, we don't need to tell the profiler about the "BrokerEvent"
146 // thread, as it exists only in the chrome.exe image, and never spawns or runs 151 // thread, as it exists only in the chrome.exe image, and never spawns or runs
147 // tasks (items which could be profiled). This test avoids the notification, 152 // tasks (items which could be profiled). This test avoids the notification,
148 // which would also (as a side effect) initialize the profiler in this unused 153 // which would also (as a side effect) initialize the profiler in this unused
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 case kThreadPriority_RealtimeAudio: 230 case kThreadPriority_RealtimeAudio:
226 ::SetThreadPriority(handle.handle_, THREAD_PRIORITY_TIME_CRITICAL); 231 ::SetThreadPriority(handle.handle_, THREAD_PRIORITY_TIME_CRITICAL);
227 break; 232 break;
228 default: 233 default:
229 NOTREACHED() << "Unknown priority."; 234 NOTREACHED() << "Unknown priority.";
230 break; 235 break;
231 } 236 }
232 } 237 }
233 238
234 } // namespace base 239 } // namespace base
OLDNEW
« no previous file with comments | « base/test/test_suite.cc ('k') | base/time/time.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698