OLD | NEW |
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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 // static | 143 // static |
144 void PlatformThread::YieldCurrentThread() { | 144 void PlatformThread::YieldCurrentThread() { |
145 ::Sleep(0); | 145 ::Sleep(0); |
146 } | 146 } |
147 | 147 |
148 // static | 148 // static |
149 void PlatformThread::Sleep(TimeDelta duration) { | 149 void PlatformThread::Sleep(TimeDelta duration) { |
150 // When measured with a high resolution clock, Sleep() sometimes returns much | 150 // When measured with a high resolution clock, Sleep() sometimes returns much |
151 // too early. We may need to call it repeatedly to get the desired duration. | 151 // too early. We may need to call it repeatedly to get the desired duration. |
152 TimeTicks end = TimeTicks::Now() + duration; | 152 TimeTicks end = TimeTicks::Now() + duration; |
153 TimeTicks now; | 153 for (TimeTicks now = TimeTicks::Now(); now < end; now = TimeTicks::Now()) |
154 while ((now = TimeTicks::Now()) < end) | 154 ::Sleep(static_cast<DWORD>((end - now).InMillisecondsRoundedUp())); |
155 ::Sleep((end - now).InMillisecondsRoundedUp()); | |
156 } | 155 } |
157 | 156 |
158 // static | 157 // static |
159 void PlatformThread::SetName(const char* name) { | 158 void PlatformThread::SetName(const char* name) { |
160 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name); | 159 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name); |
161 | 160 |
162 // On Windows only, we don't need to tell the profiler about the "BrokerEvent" | 161 // On Windows only, we don't need to tell the profiler about the "BrokerEvent" |
163 // thread, as it exists only in the chrome.exe image, and never spawns or runs | 162 // thread, as it exists only in the chrome.exe image, and never spawns or runs |
164 // tasks (items which could be profiled). This test avoids the notification, | 163 // tasks (items which could be profiled). This test avoids the notification, |
165 // which would also (as a side effect) initialize the profiler in this unused | 164 // 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 Loading... |
242 case kThreadPriority_RealtimeAudio: | 241 case kThreadPriority_RealtimeAudio: |
243 ::SetThreadPriority(handle.handle_, THREAD_PRIORITY_TIME_CRITICAL); | 242 ::SetThreadPriority(handle.handle_, THREAD_PRIORITY_TIME_CRITICAL); |
244 break; | 243 break; |
245 default: | 244 default: |
246 NOTREACHED() << "Unknown priority."; | 245 NOTREACHED() << "Unknown priority."; |
247 break; | 246 break; |
248 } | 247 } |
249 } | 248 } |
250 | 249 |
251 } // namespace base | 250 } // namespace base |
OLD | NEW |