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 #ifndef V8_BASE_PLATFORM_ELAPSED_TIMER_H_ | 5 #ifndef V8_BASE_PLATFORM_ELAPSED_TIMER_H_ |
6 #define V8_BASE_PLATFORM_ELAPSED_TIMER_H_ | 6 #define V8_BASE_PLATFORM_ELAPSED_TIMER_H_ |
7 | 7 |
8 #include "src/base/logging.h" | 8 #include "src/base/logging.h" |
9 #include "src/base/platform/time.h" | 9 #include "src/base/platform/time.h" |
10 | 10 |
(...skipping 53 matching lines...) Loading... | |
64 | 64 |
65 // Returns the time elapsed since the previous start. This method may only | 65 // Returns the time elapsed since the previous start. This method may only |
66 // be called on a previously started timer. | 66 // be called on a previously started timer. |
67 TimeDelta Elapsed() const { | 67 TimeDelta Elapsed() const { |
68 DCHECK(IsStarted()); | 68 DCHECK(IsStarted()); |
69 TimeDelta elapsed = Now() - start_ticks_; | 69 TimeDelta elapsed = Now() - start_ticks_; |
70 DCHECK(elapsed.InMicroseconds() >= 0); | 70 DCHECK(elapsed.InMicroseconds() >= 0); |
71 return elapsed; | 71 return elapsed; |
72 } | 72 } |
73 | 73 |
74 // Move the start_ticks_ to adjust the current timer. | |
75 void AdjustBy(TimeDelta delta) { | |
76 DCHECK(IsStarted()); | |
77 // If the delta is negative we want to make the elapsed time smaller, hence | |
78 // we have to move the start_ticks_ in the opposite direction. | |
79 start_ticks_ -= delta; | |
Igor Sheludko
2016/11/18 09:55:45
Maybe call it Subtract(delta) expecting non-negati
Camillo Bruni
2016/11/18 16:36:48
What's not wrong with double double negation negat
| |
80 } | |
81 | |
74 // Returns |true| if the specified |time_delta| has elapsed since the | 82 // Returns |true| if the specified |time_delta| has elapsed since the |
75 // previous start, or |false| if not. This method may only be called on | 83 // previous start, or |false| if not. This method may only be called on |
76 // a previously started timer. | 84 // a previously started timer. |
77 bool HasExpired(TimeDelta time_delta) const { | 85 bool HasExpired(TimeDelta time_delta) const { |
78 DCHECK(IsStarted()); | 86 DCHECK(IsStarted()); |
79 return Elapsed() >= time_delta; | 87 return Elapsed() >= time_delta; |
80 } | 88 } |
81 | 89 |
82 private: | 90 private: |
83 static V8_INLINE TimeTicks Now() { | 91 static V8_INLINE TimeTicks Now() { |
84 TimeTicks now = TimeTicks::HighResolutionNow(); | 92 TimeTicks now = TimeTicks::HighResolutionNow(); |
85 DCHECK(!now.IsNull()); | 93 DCHECK(!now.IsNull()); |
86 return now; | 94 return now; |
87 } | 95 } |
88 | 96 |
89 TimeTicks start_ticks_; | 97 TimeTicks start_ticks_; |
90 #ifdef DEBUG | 98 #ifdef DEBUG |
91 bool started_; | 99 bool started_; |
92 #endif | 100 #endif |
93 }; | 101 }; |
94 | 102 |
95 } // namespace base | 103 } // namespace base |
96 } // namespace v8 | 104 } // namespace v8 |
97 | 105 |
98 #endif // V8_BASE_PLATFORM_ELAPSED_TIMER_H_ | 106 #endif // V8_BASE_PLATFORM_ELAPSED_TIMER_H_ |
OLD | NEW |