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

Side by Side Diff: base/time/time_posix.cc

Issue 600013003: Avoid 64-bit divide when sampling timestamp (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: formatting Created 6 years, 2 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 | « no previous file | no next file » | 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/time/time.h" 5 #include "base/time/time.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <sys/time.h> 8 #include <sys/time.h>
9 #include <time.h> 9 #include <time.h>
10 #if defined(OS_ANDROID) && !defined(__LP64__) 10 #if defined(OS_ANDROID) && !defined(__LP64__)
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 uint64_t absolute_micro; 91 uint64_t absolute_micro;
92 92
93 struct timespec ts; 93 struct timespec ts;
94 if (clock_gettime(clk_id, &ts) != 0) { 94 if (clock_gettime(clk_id, &ts) != 0) {
95 NOTREACHED() << "clock_gettime(" << clk_id << ") failed."; 95 NOTREACHED() << "clock_gettime(" << clk_id << ") failed.";
96 return base::TimeTicks(); 96 return base::TimeTicks();
97 } 97 }
98 98
99 absolute_micro = 99 absolute_micro =
100 (static_cast<int64>(ts.tv_sec) * base::Time::kMicrosecondsPerSecond) + 100 (static_cast<int64>(ts.tv_sec) * base::Time::kMicrosecondsPerSecond) +
101 (static_cast<int64>(ts.tv_nsec) / base::Time::kNanosecondsPerMicrosecond); 101 (static_cast<int64>(ts.tv_nsec / base::Time::kNanosecondsPerMicrosecond));
jamesr 2014/09/29 23:37:31 i'm pretty sure this doesn't actually help, since
Peter Kasting 2014/09/30 00:22:15 This. I'm in the process of cleaning up our 64-bi
102 102
103 return base::TimeTicks::FromInternalValue(absolute_micro); 103 return base::TimeTicks::FromInternalValue(absolute_micro);
104 } 104 }
105 #else // _POSIX_MONOTONIC_CLOCK 105 #else // _POSIX_MONOTONIC_CLOCK
106 #error No usable tick clock function on this platform. 106 #error No usable tick clock function on this platform.
107 #endif // _POSIX_MONOTONIC_CLOCK 107 #endif // _POSIX_MONOTONIC_CLOCK
108 #endif // !defined(OS_MACOSX) 108 #endif // !defined(OS_MACOSX)
109 109
110 } // namespace 110 } // namespace
111 111
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 result.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1; 391 result.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1;
392 return result; 392 return result;
393 } 393 }
394 int64 us = us_ - kTimeTToMicrosecondsOffset; 394 int64 us = us_ - kTimeTToMicrosecondsOffset;
395 result.tv_sec = us / Time::kMicrosecondsPerSecond; 395 result.tv_sec = us / Time::kMicrosecondsPerSecond;
396 result.tv_usec = us % Time::kMicrosecondsPerSecond; 396 result.tv_usec = us % Time::kMicrosecondsPerSecond;
397 return result; 397 return result;
398 } 398 }
399 399
400 } // namespace base 400 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698