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 <errno.h> | 7 #include <errno.h> |
8 #include <sched.h> | 8 #include <sched.h> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 return reinterpret_cast<int64>(pthread_self()); | 169 return reinterpret_cast<int64>(pthread_self()); |
170 #endif | 170 #endif |
171 } | 171 } |
172 | 172 |
173 // static | 173 // static |
174 void PlatformThread::YieldCurrentThread() { | 174 void PlatformThread::YieldCurrentThread() { |
175 sched_yield(); | 175 sched_yield(); |
176 } | 176 } |
177 | 177 |
178 // static | 178 // static |
| 179 void PlatformThread::Sleep(int duration_ms) { |
| 180 // NOTE: This function will be supplanted by the other version of Sleep |
| 181 // in the future. See issue 108171 for more information. |
| 182 Sleep(TimeDelta::FromMilliseconds(duration_ms)); |
| 183 } |
| 184 |
| 185 // static |
179 void PlatformThread::Sleep(TimeDelta duration) { | 186 void PlatformThread::Sleep(TimeDelta duration) { |
180 struct timespec sleep_time, remaining; | 187 struct timespec sleep_time, remaining; |
181 | 188 |
182 // Break the duration into seconds and nanoseconds. | 189 // Break the duration into seconds and nanoseconds. |
183 // NOTE: TimeDelta's microseconds are int64s while timespec's | 190 // NOTE: TimeDelta's microseconds are int64s while timespec's |
184 // nanoseconds are longs, so this unpacking must prevent overflow. | 191 // nanoseconds are longs, so this unpacking must prevent overflow. |
185 sleep_time.tv_sec = duration.InSeconds(); | 192 sleep_time.tv_sec = duration.InSeconds(); |
186 duration -= TimeDelta::FromSeconds(sleep_time.tv_sec); | 193 duration -= TimeDelta::FromSeconds(sleep_time.tv_sec); |
187 sleep_time.tv_nsec = duration.InMicroseconds() * 1000; // nanoseconds | 194 sleep_time.tv_nsec = duration.InMicroseconds() * 1000; // nanoseconds |
188 | 195 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 #if !defined(OS_MACOSX) | 282 #if !defined(OS_MACOSX) |
276 // Mac OS X uses lower-level mach APIs. | 283 // Mac OS X uses lower-level mach APIs. |
277 | 284 |
278 // static | 285 // static |
279 void PlatformThread::SetThreadPriority(PlatformThreadHandle, ThreadPriority) { | 286 void PlatformThread::SetThreadPriority(PlatformThreadHandle, ThreadPriority) { |
280 // TODO(crogers): Implement, see http://crbug.com/116172 | 287 // TODO(crogers): Implement, see http://crbug.com/116172 |
281 } | 288 } |
282 #endif | 289 #endif |
283 | 290 |
284 } // namespace base | 291 } // namespace base |
OLD | NEW |