Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license |
michael@0 | 5 | * that can be found in the LICENSE file in the root of the source |
michael@0 | 6 | * tree. An additional intellectual property rights grant can be found |
michael@0 | 7 | * in the file PATENTS. All contributing project authors may |
michael@0 | 8 | * be found in the AUTHORS file in the root of the source tree. |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | |
michael@0 | 12 | #ifndef VPX_TIMER_H |
michael@0 | 13 | #define VPX_TIMER_H |
michael@0 | 14 | #include "vpx/vpx_integer.h" |
michael@0 | 15 | |
michael@0 | 16 | #if CONFIG_OS_SUPPORT |
michael@0 | 17 | |
michael@0 | 18 | #if defined(_WIN32) |
michael@0 | 19 | /* |
michael@0 | 20 | * Win32 specific includes |
michael@0 | 21 | */ |
michael@0 | 22 | #ifndef WIN32_LEAN_AND_MEAN |
michael@0 | 23 | #define WIN32_LEAN_AND_MEAN |
michael@0 | 24 | #endif |
michael@0 | 25 | #include <windows.h> |
michael@0 | 26 | #else |
michael@0 | 27 | /* |
michael@0 | 28 | * POSIX specific includes |
michael@0 | 29 | */ |
michael@0 | 30 | #include <sys/time.h> |
michael@0 | 31 | |
michael@0 | 32 | /* timersub is not provided by msys at this time. */ |
michael@0 | 33 | #ifndef timersub |
michael@0 | 34 | #define timersub(a, b, result) \ |
michael@0 | 35 | do { \ |
michael@0 | 36 | (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ |
michael@0 | 37 | (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ |
michael@0 | 38 | if ((result)->tv_usec < 0) { \ |
michael@0 | 39 | --(result)->tv_sec; \ |
michael@0 | 40 | (result)->tv_usec += 1000000; \ |
michael@0 | 41 | } \ |
michael@0 | 42 | } while (0) |
michael@0 | 43 | #endif |
michael@0 | 44 | #endif |
michael@0 | 45 | |
michael@0 | 46 | |
michael@0 | 47 | struct vpx_usec_timer { |
michael@0 | 48 | #if defined(_WIN32) |
michael@0 | 49 | LARGE_INTEGER begin, end; |
michael@0 | 50 | #else |
michael@0 | 51 | struct timeval begin, end; |
michael@0 | 52 | #endif |
michael@0 | 53 | }; |
michael@0 | 54 | |
michael@0 | 55 | |
michael@0 | 56 | static void |
michael@0 | 57 | vpx_usec_timer_start(struct vpx_usec_timer *t) { |
michael@0 | 58 | #if defined(_WIN32) |
michael@0 | 59 | QueryPerformanceCounter(&t->begin); |
michael@0 | 60 | #else |
michael@0 | 61 | gettimeofday(&t->begin, NULL); |
michael@0 | 62 | #endif |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | |
michael@0 | 66 | static void |
michael@0 | 67 | vpx_usec_timer_mark(struct vpx_usec_timer *t) { |
michael@0 | 68 | #if defined(_WIN32) |
michael@0 | 69 | QueryPerformanceCounter(&t->end); |
michael@0 | 70 | #else |
michael@0 | 71 | gettimeofday(&t->end, NULL); |
michael@0 | 72 | #endif |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | |
michael@0 | 76 | static int64_t |
michael@0 | 77 | vpx_usec_timer_elapsed(struct vpx_usec_timer *t) { |
michael@0 | 78 | #if defined(_WIN32) |
michael@0 | 79 | LARGE_INTEGER freq, diff; |
michael@0 | 80 | |
michael@0 | 81 | diff.QuadPart = t->end.QuadPart - t->begin.QuadPart; |
michael@0 | 82 | |
michael@0 | 83 | QueryPerformanceFrequency(&freq); |
michael@0 | 84 | return diff.QuadPart * 1000000 / freq.QuadPart; |
michael@0 | 85 | #else |
michael@0 | 86 | struct timeval diff; |
michael@0 | 87 | |
michael@0 | 88 | timersub(&t->end, &t->begin, &diff); |
michael@0 | 89 | return diff.tv_sec * 1000000 + diff.tv_usec; |
michael@0 | 90 | #endif |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | #else /* CONFIG_OS_SUPPORT = 0*/ |
michael@0 | 94 | |
michael@0 | 95 | /* Empty timer functions if CONFIG_OS_SUPPORT = 0 */ |
michael@0 | 96 | #ifndef timersub |
michael@0 | 97 | #define timersub(a, b, result) |
michael@0 | 98 | #endif |
michael@0 | 99 | |
michael@0 | 100 | struct vpx_usec_timer { |
michael@0 | 101 | void *dummy; |
michael@0 | 102 | }; |
michael@0 | 103 | |
michael@0 | 104 | static void |
michael@0 | 105 | vpx_usec_timer_start(struct vpx_usec_timer *t) { } |
michael@0 | 106 | |
michael@0 | 107 | static void |
michael@0 | 108 | vpx_usec_timer_mark(struct vpx_usec_timer *t) { } |
michael@0 | 109 | |
michael@0 | 110 | static long |
michael@0 | 111 | vpx_usec_timer_elapsed(struct vpx_usec_timer *t) { |
michael@0 | 112 | return 0; |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | #endif /* CONFIG_OS_SUPPORT */ |
michael@0 | 116 | |
michael@0 | 117 | #endif |