| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2008 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2008 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 |
| 11 #ifndef WEBRTC_BASE_TIMING_H_ | 11 #ifndef WEBRTC_BASE_TIMING_H_ |
| 12 #define WEBRTC_BASE_TIMING_H_ | 12 #define WEBRTC_BASE_TIMING_H_ |
| 13 | 13 |
| 14 #if defined(WEBRTC_WIN) | |
| 15 #include "webrtc/base/win32.h" | |
| 16 #endif | |
| 17 | |
| 18 namespace rtc { | 14 namespace rtc { |
| 19 | 15 |
| 20 class Timing { | 16 class Timing { |
| 21 public: | 17 public: |
| 22 Timing(); | 18 Timing(); |
| 23 virtual ~Timing(); | 19 virtual ~Timing(); |
| 24 | 20 |
| 25 // WallTimeNow() returns the current wall-clock time in seconds, | 21 // WallTimeNow() returns the current wall-clock time in seconds, |
| 26 // within 10 milliseconds resolution. | 22 // within 10 milliseconds resolution. |
| 27 // WallTimeNow is static and does not require a timer_handle_ on Windows. | 23 // WallTimeNow is static and does not require a timer_handle_ on Windows. |
| 28 static double WallTimeNow(); | 24 static double WallTimeNow(); |
| 29 | 25 |
| 30 // TimerNow() is like WallTimeNow(), but is monotonically | 26 // TimerNow() is like WallTimeNow(), but is monotonically |
| 31 // increasing. It returns seconds in resolution of 10 microseconds | 27 // increasing. It returns seconds in resolution of 10 microseconds |
| 32 // or better. Although timer and wall-clock time have the same | 28 // or better. Although timer and wall-clock time have the same |
| 33 // timing unit, they do not necessarily correlate because wall-clock | 29 // timing unit, they do not necessarily correlate because wall-clock |
| 34 // time may be adjusted backwards, hence not monotonic. | 30 // time may be adjusted backwards, hence not monotonic. |
| 35 // Made virtual so we can make a fake one. | 31 // Made virtual so we can make a fake one. |
| 32 // TODO(tommi): The only place we use this (virtual) is in |
| 33 // rtpdata_engine_unittest.cc. See if it doesn't make more sense to change |
| 34 // that contract or test than to modify this generic class. |
| 36 virtual double TimerNow(); | 35 virtual double TimerNow(); |
| 37 | |
| 38 // BusyWait() exhausts CPU as long as the time elapsed is less than | |
| 39 // the specified interval in seconds. Returns the actual waiting | |
| 40 // time based on TimerNow() measurement. | |
| 41 double BusyWait(double period); | |
| 42 | |
| 43 // IdleWait() relinquishes control of CPU for specified period in | |
| 44 // seconds. It uses highest resolution sleep mechanism as possible, | |
| 45 // but does not otherwise guarantee the accuracy. Returns the | |
| 46 // actual waiting time based on TimerNow() measurement. | |
| 47 // | |
| 48 // This function is not re-entrant for an object. Create a fresh | |
| 49 // Timing object for each thread. | |
| 50 double IdleWait(double period); | |
| 51 | |
| 52 private: | |
| 53 #if defined(WEBRTC_WIN) | |
| 54 HANDLE timer_handle_; | |
| 55 #endif | |
| 56 }; | 36 }; |
| 57 | 37 |
| 58 } // namespace rtc | 38 } // namespace rtc |
| 59 | 39 |
| 60 #endif // WEBRTC_BASE_TIMING_H_ | 40 #endif // WEBRTC_BASE_TIMING_H_ |
| OLD | NEW |