• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2008 The WebRTC Project Authors. All rights reserved.
3  *
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
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef WEBRTC_BASE_TIMING_H_
12 #define WEBRTC_BASE_TIMING_H_
13 
14 #if defined(WEBRTC_WIN)
15 #include "webrtc/base/win32.h"
16 #endif
17 
18 namespace rtc {
19 
20 class Timing {
21  public:
22   Timing();
23   virtual ~Timing();
24 
25   // WallTimeNow() returns the current wall-clock time in seconds,
26   // within 10 milliseconds resolution.
27   // WallTimeNow is static and does not require a timer_handle_ on Windows.
28   static double WallTimeNow();
29 
30   // TimerNow() is like WallTimeNow(), but is monotonically
31   // increasing.  It returns seconds in resolution of 10 microseconds
32   // or better.  Although timer and wall-clock time have the same
33   // timing unit, they do not necessarily correlate because wall-clock
34   // time may be adjusted backwards, hence not monotonic.
35   // Made virtual so we can make a fake one.
36   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 };
57 
58 }  // namespace rtc
59 
60 #endif // WEBRTC_BASE_TIMING_H_
61