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

Unified Diff: base/threading/platform_thread_posix.cc

Issue 8965072: Add function support for Sleep and MessageLoop with TimeDelta input. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix comment spacing. Created 9 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/threading/platform_thread.h ('k') | base/threading/platform_thread_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..1d72f07fc645b3b7e087c751b148f2a3833ea0d0 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
while (nanosleep(&sleep_time, &remaining) == -1 && errno == EINTR)
sleep_time = remaining;
« no previous file with comments | « base/threading/platform_thread.h ('k') | base/threading/platform_thread_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698