Whitespace: nuke CRLFs
[libvpx.git] / vpx_ports / vpx_timer.h
blobf2a5a7ec1d67ca9c1df97365624215ddc5e6160f
1 /*
2 * Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
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 */
12 #ifndef VPX_TIMER_H
13 #define VPX_TIMER_H
15 #if defined(_WIN32)
17 * Win32 specific includes
19 #ifndef WIN32_LEAN_AND_MEAN
20 #define WIN32_LEAN_AND_MEAN
21 #endif
22 #include <windows.h>
23 #else
25 * POSIX specific includes
27 #include <sys/time.h>
29 /* timersub is not provided by msys at this time. */
30 #ifndef timersub
31 #define timersub(a, b, result) \
32 do { \
33 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
34 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
35 if ((result)->tv_usec < 0) { \
36 --(result)->tv_sec; \
37 (result)->tv_usec += 1000000; \
38 } \
39 } while (0)
40 #endif
41 #endif
44 struct vpx_usec_timer
46 #if defined(_WIN32)
47 LARGE_INTEGER begin, end;
48 #else
49 struct timeval begin, end;
50 #endif
54 static void
55 vpx_usec_timer_start(struct vpx_usec_timer *t)
57 #if defined(_WIN32)
58 QueryPerformanceCounter(&t->begin);
59 #else
60 gettimeofday(&t->begin, NULL);
61 #endif
65 static void
66 vpx_usec_timer_mark(struct vpx_usec_timer *t)
68 #if defined(_WIN32)
69 QueryPerformanceCounter(&t->end);
70 #else
71 gettimeofday(&t->end, NULL);
72 #endif
76 static long
77 vpx_usec_timer_elapsed(struct vpx_usec_timer *t)
79 #if defined(_WIN32)
80 LARGE_INTEGER freq, diff;
82 diff.QuadPart = t->end.QuadPart - t->begin.QuadPart;
84 if (QueryPerformanceFrequency(&freq) && diff.QuadPart < freq.QuadPart)
85 return (long)(diff.QuadPart * 1000000 / freq.QuadPart);
87 return 1000000;
88 #else
89 struct timeval diff;
91 timersub(&t->end, &t->begin, &diff);
92 return diff.tv_sec ? 1000000 : diff.tv_usec;
93 #endif
97 #endif