Chromium Code Reviews| Index: base/threading/platform_thread_posix.cc |
| diff --git a/base/threading/platform_thread_posix.cc b/base/threading/platform_thread_posix.cc |
| index ea1f037725259ea890d88ea24c7b8ec0ab340628..497192e731ba37065068ccf2dd21a2c2fdc2df52 100644 |
| --- a/base/threading/platform_thread_posix.cc |
| +++ b/base/threading/platform_thread_posix.cc |
| @@ -152,14 +152,21 @@ void PlatformThread::YieldCurrentThread() { |
| // static |
| void PlatformThread::Sleep(int duration_ms) { |
| - struct timespec sleep_time, remaining; |
| + // NOTE: This function will be supplanted by the other version of Sleep |
| + // in the future. See issue 108171 for more information. |
| + Sleep(TimeDelta::FromMilliseconds(duration_ms)); |
| +} |
| - // Contains the portion of duration_ms >= 1 sec. |
| - sleep_time.tv_sec = duration_ms / 1000; |
| - duration_ms -= sleep_time.tv_sec * 1000; |
| +// static |
| +void PlatformThread::Sleep(TimeDelta duration) { |
| + struct timespec sleep_time, remaining; |
| - // Contains the portion of duration_ms < 1 sec. |
| - sleep_time.tv_nsec = duration_ms * 1000 * 1000; // nanoseconds. |
| + // Break the duration into seconds and nanoseconds. |
| + // NOTE: TimeDelta's microseconds are int64s while timespec's |
| + // nanoseconds are longs, so this unpacking must prevent overflow. |
| + sleep_time.tv_sec = duration.InSeconds(); |
| + duration -= TimeDelta::FromSeconds(sleep_time.tv_sec); |
| + sleep_time.tv_nsec = duration.InMicroseconds() * 1000; // nanoseconds |
|
brettw
2011/12/29 23:16:45
Two spaces before end of line comments.
|
| while (nanosleep(&sleep_time, &remaining) == -1 && errno == EINTR) |
| sleep_time = remaining; |