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

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

Issue 2024813004: Improving the fake clock and using it to fix a flaky STUN timeout test. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing another TSan warning. WebRtcSession wasn't completely shut down. Created 4 years, 6 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
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 21 matching lines...) Expand all
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 uint64_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 // Does not transfer ownership of the clock. 42 // Returns the previously set ClockInterface, or nullptr if none is set.
43 // SetClock(nullptr) should be called before the ClockInterface is deleted. 43 //
44 // Does not transfer ownership of the clock. SetClockForTesting(nullptr)
45 // should be called before the ClockInterface is deleted.
44 // 46 //
45 // 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
46 // 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
47 // main()). 49 // main()).
48 // 50 //
49 // TODO(deadbeef): Instead of having functions that access this global 51 // TODO(deadbeef): Instead of having functions that access this global
nisse-webrtc 2016/06/08 09:47:30 I don't think it's a good idea to pass around the
50 // ClockInterface, we may want to pass the ClockInterface into everything 52 // ClockInterface, we may want to pass the ClockInterface into everything
51 // 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.
52 void SetClock(ClockInterface* clock); 54 ClockInterface* SetClockForTesting(ClockInterface* clock);
53 55
54 // Returns the current time in milliseconds in 32 bits. 56 // Returns the current time in milliseconds in 32 bits.
55 uint32_t Time32(); 57 uint32_t Time32();
56 58
57 // Returns the current time in milliseconds in 64 bits. 59 // Returns the current time in milliseconds in 64 bits.
58 int64_t TimeMillis(); 60 int64_t TimeMillis();
59 // Deprecated. Do not use this in any new code. 61 // Deprecated. Do not use this in any new code.
60 inline int64_t Time() { 62 inline int64_t Time() {
61 return TimeMillis(); 63 return TimeMillis();
62 } 64 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 }; 99 };
98 100
99 // Convert from std::tm, which is relative to 1900-01-01 00:00 to number of 101 // Convert from std::tm, which is relative to 1900-01-01 00:00 to number of
100 // seconds from 1970-01-01 00:00 ("epoch"). Don't return time_t since that 102 // seconds from 1970-01-01 00:00 ("epoch"). Don't return time_t since that
101 // is still 32 bits on many systems. 103 // is still 32 bits on many systems.
102 int64_t TmToSeconds(const std::tm& tm); 104 int64_t TmToSeconds(const std::tm& tm);
103 105
104 } // namespace rtc 106 } // namespace rtc
105 107
106 #endif // WEBRTC_BASE_TIMEUTILS_H_ 108 #endif // WEBRTC_BASE_TIMEUTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698