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

Side by Side Diff: webrtc/base/timeutils.h

Issue 2514553003: Change rtc::TimeNanos and rtc::TimeMicros return value from uint64_t to int64_t. (Closed)
Patch Set: Rebased, on top of fixed BoringSSL TimeCallback.' Created 4 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 unified diff | Download patch
« no previous file with comments | « webrtc/base/socket_unittest.cc ('k') | webrtc/base/timeutils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2005 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2005 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 16 matching lines...) Expand all
27 static const int64_t kNumNanosecsPerMillisec = 27 static const int64_t kNumNanosecsPerMillisec =
28 kNumNanosecsPerSec / kNumMillisecsPerSec; 28 kNumNanosecsPerSec / kNumMillisecsPerSec;
29 static const int64_t kNumNanosecsPerMicrosec = 29 static const int64_t kNumNanosecsPerMicrosec =
30 kNumNanosecsPerSec / kNumMicrosecsPerSec; 30 kNumNanosecsPerSec / kNumMicrosecsPerSec;
31 31
32 // TODO(honghaiz): Define a type for the time value specifically. 32 // TODO(honghaiz): Define a type for the time value specifically.
33 33
34 class ClockInterface { 34 class ClockInterface {
35 public: 35 public:
36 virtual ~ClockInterface() {} 36 virtual ~ClockInterface() {}
37 virtual uint64_t TimeNanos() const = 0; 37 virtual int64_t TimeNanos() const = 0;
38 }; 38 };
39 39
40 // Sets the global source of time. This is useful mainly for unit tests. 40 // Sets the global source of time. This is useful mainly for unit tests.
41 // 41 //
42 // Returns the previously set ClockInterface, or nullptr if none is set. 42 // Returns the previously set ClockInterface, or nullptr if none is set.
43 // 43 //
44 // Does not transfer ownership of the clock. SetClockForTesting(nullptr) 44 // Does not transfer ownership of the clock. SetClockForTesting(nullptr)
45 // should be called before the ClockInterface is deleted. 45 // should be called before the ClockInterface is deleted.
46 // 46 //
47 // This method is not thread-safe; it should only be used when no other thread 47 // This method is not thread-safe; it should only be used when no other thread
48 // is running (for example, at the start/end of a unit test, or start/end of 48 // is running (for example, at the start/end of a unit test, or start/end of
49 // main()). 49 // main()).
50 // 50 //
51 // TODO(deadbeef): Instead of having functions that access this global 51 // TODO(deadbeef): Instead of having functions that access this global
52 // ClockInterface, we may want to pass the ClockInterface into everything 52 // ClockInterface, we may want to pass the ClockInterface into everything
53 // that uses it, eliminating the need for a global variable and this function. 53 // that uses it, eliminating the need for a global variable and this function.
54 ClockInterface* SetClockForTesting(ClockInterface* clock); 54 ClockInterface* SetClockForTesting(ClockInterface* clock);
55 55
56 // Returns the actual system time, even if a clock is set for testing. 56 // Returns the actual system time, even if a clock is set for testing.
57 // Useful for timeouts while using a test clock, or for logging. 57 // Useful for timeouts while using a test clock, or for logging.
58 uint64_t SystemTimeNanos(); 58 int64_t SystemTimeNanos();
59 int64_t SystemTimeMillis(); 59 int64_t SystemTimeMillis();
60 60
61 // Returns the current time in milliseconds in 32 bits. 61 // Returns the current time in milliseconds in 32 bits.
62 uint32_t Time32(); 62 uint32_t Time32();
63 63
64 // Returns the current time in milliseconds in 64 bits. 64 // Returns the current time in milliseconds in 64 bits.
65 int64_t TimeMillis(); 65 int64_t TimeMillis();
66 // Deprecated. Do not use this in any new code. 66 // Deprecated. Do not use this in any new code.
67 inline int64_t Time() { 67 inline int64_t Time() {
68 return TimeMillis(); 68 return TimeMillis();
69 } 69 }
70 70
71 // Returns the current time in microseconds. 71 // Returns the current time in microseconds.
72 uint64_t TimeMicros(); 72 int64_t TimeMicros();
73 73
74 // Returns the current time in nanoseconds. 74 // Returns the current time in nanoseconds.
75 uint64_t TimeNanos(); 75 int64_t TimeNanos();
76
76 77
77 // Returns a future timestamp, 'elapsed' milliseconds from now. 78 // Returns a future timestamp, 'elapsed' milliseconds from now.
78 int64_t TimeAfter(int64_t elapsed); 79 int64_t TimeAfter(int64_t elapsed);
79 80
80 // Number of milliseconds that would elapse between 'earlier' and 'later' 81 // Number of milliseconds that would elapse between 'earlier' and 'later'
81 // timestamps. The value is negative if 'later' occurs before 'earlier'. 82 // timestamps. The value is negative if 'later' occurs before 'earlier'.
82 int64_t TimeDiff(int64_t later, int64_t earlier); 83 int64_t TimeDiff(int64_t later, int64_t earlier);
83 int32_t TimeDiff32(uint32_t later, uint32_t earlier); 84 int32_t TimeDiff32(uint32_t later, uint32_t earlier);
84 85
85 // The number of milliseconds that have elapsed since 'earlier'. 86 // The number of milliseconds that have elapsed since 'earlier'.
86 inline int64_t TimeSince(int64_t earlier) { 87 inline int64_t TimeSince(int64_t earlier) {
87 return TimeMillis() - earlier; 88 return TimeMillis() - earlier;
88 } 89 }
89 90
90 // The number of milliseconds that will elapse between now and 'later'. 91 // The number of milliseconds that will elapse between now and 'later'.
91 inline int64_t TimeUntil(uint64_t later) { 92 inline int64_t TimeUntil(int64_t later) {
92 return later - TimeMillis(); 93 return later - TimeMillis();
93 } 94 }
94 95
95 class TimestampWrapAroundHandler { 96 class TimestampWrapAroundHandler {
96 public: 97 public:
97 TimestampWrapAroundHandler(); 98 TimestampWrapAroundHandler();
98 99
99 int64_t Unwrap(uint32_t ts); 100 int64_t Unwrap(uint32_t ts);
100 101
101 private: 102 private:
(...skipping 14 matching lines...) Expand all
116 // Note that this function obeys the system's idea about what the time 117 // Note that this function obeys the system's idea about what the time
117 // is. It is not guaranteed to be monotonic; it will jump in case the 118 // is. It is not guaranteed to be monotonic; it will jump in case the
118 // system time is changed, e.g., by some other process calling 119 // system time is changed, e.g., by some other process calling
119 // settimeofday. Always use rtc::TimeMicros(), not this function, for 120 // settimeofday. Always use rtc::TimeMicros(), not this function, for
120 // measuring time intervals and timeouts. 121 // measuring time intervals and timeouts.
121 int64_t TimeUTCMicros(); 122 int64_t TimeUTCMicros();
122 123
123 } // namespace rtc 124 } // namespace rtc
124 125
125 #endif // WEBRTC_BASE_TIMEUTILS_H_ 126 #endif // WEBRTC_BASE_TIMEUTILS_H_
OLDNEW
« no previous file with comments | « webrtc/base/socket_unittest.cc ('k') | webrtc/base/timeutils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698