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

Side by Side Diff: net/quic/core/quic_time.h

Issue 2871573009: Use clock_gettime instead of base::TimeTicks::Now() in QUIC (Closed)
Patch Set: Fallback Created 3 years, 7 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 | net/quic/platform/api/quic_clock.h » ('j') | 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 // QuicTime represents one point in time, stored in microsecond resolution. 5 // QuicTime represents one point in time, stored in microsecond resolution.
6 // QuicTime is monotonically increasing, even across system clock adjustments. 6 // QuicTime is monotonically increasing, even across system clock adjustments.
7 // The epoch (time 0) of QuicTime is unspecified. 7 // The epoch (time 0) of QuicTime is unspecified.
8 // 8 //
9 // This implementation wraps the classes base::TimeTicks and base::TimeDelta. 9 // This implementation wraps the classes base::TimeTicks and base::TimeDelta.
10 10
11 #ifndef NET_QUIC_CORE_QUIC_TIME_H_ 11 #ifndef NET_QUIC_CORE_QUIC_TIME_H_
12 #define NET_QUIC_CORE_QUIC_TIME_H_ 12 #define NET_QUIC_CORE_QUIC_TIME_H_
13 13
14 #include <cmath> 14 #include <cmath>
15 #include <cstdint> 15 #include <cstdint>
16 #include <limits> 16 #include <limits>
17 #include <ostream> 17 #include <ostream>
18 18
19 #include "base/compiler_specific.h" 19 #include "base/compiler_specific.h"
20 #include "base/time/time.h" 20 #include "base/time/time.h"
21 #include "net/quic/platform/api/quic_export.h" 21 #include "net/quic/platform/api/quic_export.h"
22 22
23 #define QUICTIME_CONSTEXPR inline 23 #define QUICTIME_CONSTEXPR inline
24 24
25 namespace net { 25 namespace net {
26 26
27 class QuicClock;
28
27 // A QuicTime is a purely relative time. QuicTime values from different clocks 29 // A QuicTime is a purely relative time. QuicTime values from different clocks
28 // cannot be compared to each other. If you need an absolute time, see 30 // cannot be compared to each other. If you need an absolute time, see
29 // QuicWallTime, below. 31 // QuicWallTime, below.
30 class QUIC_EXPORT_PRIVATE QuicTime { 32 class QUIC_EXPORT_PRIVATE QuicTime {
31 public: 33 public:
32 // A QuicTime::Delta represents the signed difference between two points in 34 // A QuicTime::Delta represents the signed difference between two points in
33 // time, stored in microsecond resolution. 35 // time, stored in microsecond resolution.
34 class QUIC_EXPORT_PRIVATE Delta { 36 class QUIC_EXPORT_PRIVATE Delta {
35 public: 37 public:
36 explicit Delta(base::TimeDelta delta); 38 explicit Delta(base::TimeDelta delta);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 std::numeric_limits<int64_t>::max(); 99 std::numeric_limits<int64_t>::max();
98 100
99 explicit QUICTIME_CONSTEXPR Delta(int64_t time_offset) 101 explicit QUICTIME_CONSTEXPR Delta(int64_t time_offset)
100 : time_offset_(time_offset) {} 102 : time_offset_(time_offset) {}
101 103
102 int64_t time_offset_; 104 int64_t time_offset_;
103 friend class QuicTime; 105 friend class QuicTime;
104 friend class QuicClock; 106 friend class QuicClock;
105 }; 107 };
106 108
107 explicit QuicTime(base::TimeTicks ticks) : time_(ticks.ToInternalValue()) {}
108
109 // Creates a new QuicTime with an internal value of 0. IsInitialized() 109 // Creates a new QuicTime with an internal value of 0. IsInitialized()
110 // will return false for these times. 110 // will return false for these times.
111 static QUICTIME_CONSTEXPR QuicTime Zero() { return QuicTime(0); } 111 static QUICTIME_CONSTEXPR QuicTime Zero() { return QuicTime(0); }
112 112
113 // Creates a new QuicTime with an infinite time. 113 // Creates a new QuicTime with an infinite time.
114 static QUICTIME_CONSTEXPR QuicTime Infinite() { 114 static QUICTIME_CONSTEXPR QuicTime Infinite() {
115 return QuicTime(Delta::kQuicInfiniteTimeUs); 115 return QuicTime(Delta::kQuicInfiniteTimeUs);
116 } 116 }
117 117
118 // Produce the internal value to be used when logging. This value 118 // Produce the internal value to be used when logging. This value
119 // represents the number of microseconds since some epoch. It may 119 // represents the number of microseconds since some epoch. It may
120 // be the UNIX epoch on some platforms. On others, it may 120 // be the UNIX epoch on some platforms. On others, it may
121 // be a CPU ticks based value. 121 // be a CPU ticks based value.
122 inline int64_t ToDebuggingValue() const { return time_; } 122 inline int64_t ToDebuggingValue() const { return time_; }
123 123
124 inline bool IsInitialized() const { return 0 != time_; } 124 inline bool IsInitialized() const { return 0 != time_; }
125 125
126 private: 126 private:
127 friend class QuicClock;
128
127 friend inline bool operator==(QuicTime lhs, QuicTime rhs); 129 friend inline bool operator==(QuicTime lhs, QuicTime rhs);
128 friend inline bool operator<(QuicTime lhs, QuicTime rhs); 130 friend inline bool operator<(QuicTime lhs, QuicTime rhs);
129 friend inline QuicTime operator+(QuicTime lhs, QuicTime::Delta rhs); 131 friend inline QuicTime operator+(QuicTime lhs, QuicTime::Delta rhs);
130 friend inline QuicTime operator-(QuicTime lhs, QuicTime::Delta rhs); 132 friend inline QuicTime operator-(QuicTime lhs, QuicTime::Delta rhs);
131 friend inline QuicTime::Delta operator-(QuicTime lhs, QuicTime rhs); 133 friend inline QuicTime::Delta operator-(QuicTime lhs, QuicTime rhs);
132 134
133 explicit QUICTIME_CONSTEXPR QuicTime(int64_t time) : time_(time) {} 135 explicit QUICTIME_CONSTEXPR QuicTime(int64_t time) : time_(time) {}
134 136
135 int64_t time_; 137 int64_t time_;
136 }; 138 };
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 267
266 // Override stream output operator for gtest. 268 // Override stream output operator for gtest.
267 inline std::ostream& operator<<(std::ostream& output, 269 inline std::ostream& operator<<(std::ostream& output,
268 const QuicTime::Delta delta) { 270 const QuicTime::Delta delta) {
269 output << delta.ToDebugValue(); 271 output << delta.ToDebugValue();
270 return output; 272 return output;
271 } 273 }
272 } // namespace net 274 } // namespace net
273 275
274 #endif // NET_QUIC_CORE_QUIC_TIME_H_ 276 #endif // NET_QUIC_CORE_QUIC_TIME_H_
OLDNEW
« no previous file with comments | « no previous file | net/quic/platform/api/quic_clock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698