blob: 58b17a9fb7eeb2b84e1d1243416626e03d4843df [file] [log] [blame]
henrike@webrtc.orgf7795df2014-05-13 18:00:26 +00001/*
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
18namespace rtc {
19
20class 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 virtual double WallTimeNow();
28
29 // TimerNow() is like WallTimeNow(), but is monotonically
30 // increasing. It returns seconds in resolution of 10 microseconds
31 // or better. Although timer and wall-clock time have the same
32 // timing unit, they do not necessarily correlate because wall-clock
33 // time may be adjusted backwards, hence not monotonic.
34 // Made virtual so we can make a fake one.
35 virtual double TimerNow();
36
37 // BusyWait() exhausts CPU as long as the time elapsed is less than
38 // the specified interval in seconds. Returns the actual waiting
39 // time based on TimerNow() measurement.
40 double BusyWait(double period);
41
42 // IdleWait() relinquishes control of CPU for specified period in
43 // seconds. It uses highest resolution sleep mechanism as possible,
44 // but does not otherwise guarantee the accuracy. Returns the
45 // actual waiting time based on TimerNow() measurement.
46 //
47 // This function is not re-entrant for an object. Create a fresh
48 // Timing object for each thread.
49 double IdleWait(double period);
50
51 private:
52#if defined(WEBRTC_WIN)
53 HANDLE timer_handle_;
54#endif
55};
56
57} // namespace rtc
58
59#endif // WEBRTC_BASE_TIMING_H_