Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project 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 "src/base/platform/time.h" | 5 #include "src/base/platform/time.h" |
| 6 | 6 |
| 7 #if V8_OS_POSIX | 7 #if V8_OS_POSIX |
| 8 #include <fcntl.h> // for O_RDONLY | 8 #include <fcntl.h> // for O_RDONLY |
| 9 #include <sys/time.h> | 9 #include <sys/time.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "src/base/lazy-instance.h" | 21 #include "src/base/lazy-instance.h" |
| 22 #include "src/base/win32-headers.h" | 22 #include "src/base/win32-headers.h" |
| 23 #endif | 23 #endif |
| 24 #include "src/base/cpu.h" | 24 #include "src/base/cpu.h" |
| 25 #include "src/base/logging.h" | 25 #include "src/base/logging.h" |
| 26 #include "src/base/platform/platform.h" | 26 #include "src/base/platform/platform.h" |
| 27 | 27 |
| 28 namespace v8 { | 28 namespace v8 { |
| 29 namespace base { | 29 namespace base { |
| 30 | 30 |
| 31 namespace time_internal { | |
| 32 | |
| 33 int64_t SaturatedAdd(TimeDelta delta, int64_t value) { | |
|
fmeawad
2016/05/04 23:34:21
The Saturated methods does change the functionalit
| |
| 34 CheckedNumeric<int64_t> rv(delta.delta_); | |
| 35 rv += value; | |
| 36 return FromCheckedNumeric(rv); | |
| 37 } | |
| 38 | |
| 39 int64_t SaturatedSub(TimeDelta delta, int64_t value) { | |
| 40 CheckedNumeric<int64_t> rv(delta.delta_); | |
| 41 rv -= value; | |
| 42 return FromCheckedNumeric(rv); | |
| 43 } | |
| 44 | |
| 45 int64_t FromCheckedNumeric(const CheckedNumeric<int64_t> value) { | |
| 46 if (value.IsValid()) | |
| 47 return value.ValueUnsafe(); | |
| 48 | |
| 49 // We could return max/min but we don't really expose what the maximum delta | |
| 50 // is. Instead, return max/(-max), which is something that clients can reason | |
| 51 // about. | |
| 52 // TODO(rvargas) crbug.com/332611: don't use internal values. | |
| 53 int64_t limit = std::numeric_limits<int64_t>::max(); | |
| 54 if (value.validity() == internal::RANGE_UNDERFLOW) | |
| 55 limit = -limit; | |
| 56 return value.ValueOrDefault(limit); | |
| 57 } | |
| 58 | |
| 59 } // namespace time_internal | |
| 60 | |
| 61 | |
| 31 TimeDelta TimeDelta::FromDays(int days) { | 62 TimeDelta TimeDelta::FromDays(int days) { |
| 32 return TimeDelta(days * Time::kMicrosecondsPerDay); | 63 return TimeDelta(days * Time::kMicrosecondsPerDay); |
| 33 } | 64 } |
| 34 | 65 |
| 35 | 66 |
| 36 TimeDelta TimeDelta::FromHours(int hours) { | 67 TimeDelta TimeDelta::FromHours(int hours) { |
| 37 return TimeDelta(hours * Time::kMicrosecondsPerHour); | 68 return TimeDelta(hours * Time::kMicrosecondsPerHour); |
| 38 } | 69 } |
| 39 | 70 |
| 40 | 71 |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 | 586 |
| 556 // static | 587 // static |
| 557 bool TimeTicks::IsHighResolutionClockWorking() { | 588 bool TimeTicks::IsHighResolutionClockWorking() { |
| 558 return true; | 589 return true; |
| 559 } | 590 } |
| 560 | 591 |
| 561 #endif // V8_OS_WIN | 592 #endif // V8_OS_WIN |
| 562 | 593 |
| 563 } // namespace base | 594 } // namespace base |
| 564 } // namespace v8 | 595 } // namespace v8 |
| OLD | NEW |