2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
12 #ifndef AOM_PORTS_AOM_TIMER_H_
13 #define AOM_PORTS_AOM_TIMER_H_
15 #include "./aom_config.h"
17 #include "aom/aom_integer.h"
23 * Win32 specific includes
25 #ifndef WIN32_LEAN_AND_MEAN
26 #define WIN32_LEAN_AND_MEAN
31 * POSIX specific includes
35 /* timersub is not provided by msys at this time. */
37 #define timersub(a, b, result) \
39 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
40 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
41 if ((result)->tv_usec < 0) { \
43 (result)->tv_usec += 1000000; \
49 struct aom_usec_timer
{
51 LARGE_INTEGER begin
, end
;
53 struct timeval begin
, end
;
57 static INLINE
void aom_usec_timer_start(struct aom_usec_timer
*t
) {
59 QueryPerformanceCounter(&t
->begin
);
61 gettimeofday(&t
->begin
, NULL
);
65 static INLINE
void aom_usec_timer_mark(struct aom_usec_timer
*t
) {
67 QueryPerformanceCounter(&t
->end
);
69 gettimeofday(&t
->end
, NULL
);
73 static INLINE
int64_t aom_usec_timer_elapsed(struct aom_usec_timer
*t
) {
75 LARGE_INTEGER freq
, diff
;
77 diff
.QuadPart
= t
->end
.QuadPart
- t
->begin
.QuadPart
;
79 QueryPerformanceFrequency(&freq
);
80 return diff
.QuadPart
* 1000000 / freq
.QuadPart
;
84 timersub(&t
->end
, &t
->begin
, &diff
);
85 return ((int64_t)diff
.tv_sec
) * 1000000 + diff
.tv_usec
;
89 #else /* CONFIG_OS_SUPPORT = 0*/
91 /* Empty timer functions if CONFIG_OS_SUPPORT = 0 */
93 #define timersub(a, b, result)
96 struct aom_usec_timer
{
100 static INLINE
void aom_usec_timer_start(struct aom_usec_timer
*t
) { (void)t
; }
102 static INLINE
void aom_usec_timer_mark(struct aom_usec_timer
*t
) { (void)t
; }
104 static INLINE
int aom_usec_timer_elapsed(struct aom_usec_timer
*t
) {
109 #endif /* CONFIG_OS_SUPPORT */
111 #endif // AOM_PORTS_AOM_TIMER_H_