michael@0: /* michael@0: * Copyright (c) 2010 The WebM project authors. All Rights Reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: michael@0: michael@0: #ifndef VPX_TIMER_H michael@0: #define VPX_TIMER_H michael@0: #include "vpx/vpx_integer.h" michael@0: michael@0: #if CONFIG_OS_SUPPORT michael@0: michael@0: #if defined(_WIN32) michael@0: /* michael@0: * Win32 specific includes michael@0: */ michael@0: #ifndef WIN32_LEAN_AND_MEAN michael@0: #define WIN32_LEAN_AND_MEAN michael@0: #endif michael@0: #include michael@0: #else michael@0: /* michael@0: * POSIX specific includes michael@0: */ michael@0: #include michael@0: michael@0: /* timersub is not provided by msys at this time. */ michael@0: #ifndef timersub michael@0: #define timersub(a, b, result) \ michael@0: do { \ michael@0: (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ michael@0: (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ michael@0: if ((result)->tv_usec < 0) { \ michael@0: --(result)->tv_sec; \ michael@0: (result)->tv_usec += 1000000; \ michael@0: } \ michael@0: } while (0) michael@0: #endif michael@0: #endif michael@0: michael@0: michael@0: struct vpx_usec_timer { michael@0: #if defined(_WIN32) michael@0: LARGE_INTEGER begin, end; michael@0: #else michael@0: struct timeval begin, end; michael@0: #endif michael@0: }; michael@0: michael@0: michael@0: static void michael@0: vpx_usec_timer_start(struct vpx_usec_timer *t) { michael@0: #if defined(_WIN32) michael@0: QueryPerformanceCounter(&t->begin); michael@0: #else michael@0: gettimeofday(&t->begin, NULL); michael@0: #endif michael@0: } michael@0: michael@0: michael@0: static void michael@0: vpx_usec_timer_mark(struct vpx_usec_timer *t) { michael@0: #if defined(_WIN32) michael@0: QueryPerformanceCounter(&t->end); michael@0: #else michael@0: gettimeofday(&t->end, NULL); michael@0: #endif michael@0: } michael@0: michael@0: michael@0: static int64_t michael@0: vpx_usec_timer_elapsed(struct vpx_usec_timer *t) { michael@0: #if defined(_WIN32) michael@0: LARGE_INTEGER freq, diff; michael@0: michael@0: diff.QuadPart = t->end.QuadPart - t->begin.QuadPart; michael@0: michael@0: QueryPerformanceFrequency(&freq); michael@0: return diff.QuadPart * 1000000 / freq.QuadPart; michael@0: #else michael@0: struct timeval diff; michael@0: michael@0: timersub(&t->end, &t->begin, &diff); michael@0: return diff.tv_sec * 1000000 + diff.tv_usec; michael@0: #endif michael@0: } michael@0: michael@0: #else /* CONFIG_OS_SUPPORT = 0*/ michael@0: michael@0: /* Empty timer functions if CONFIG_OS_SUPPORT = 0 */ michael@0: #ifndef timersub michael@0: #define timersub(a, b, result) michael@0: #endif michael@0: michael@0: struct vpx_usec_timer { michael@0: void *dummy; michael@0: }; michael@0: michael@0: static void michael@0: vpx_usec_timer_start(struct vpx_usec_timer *t) { } michael@0: michael@0: static void michael@0: vpx_usec_timer_mark(struct vpx_usec_timer *t) { } michael@0: michael@0: static long michael@0: vpx_usec_timer_elapsed(struct vpx_usec_timer *t) { michael@0: return 0; michael@0: } michael@0: michael@0: #endif /* CONFIG_OS_SUPPORT */ michael@0: michael@0: #endif