media/libvpx/vpx_ports/vpx_timer.h

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /*
     2  *  Copyright (c) 2010 The WebM 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  */
    12 #ifndef VPX_TIMER_H
    13 #define VPX_TIMER_H
    14 #include "vpx/vpx_integer.h"
    16 #if CONFIG_OS_SUPPORT
    18 #if defined(_WIN32)
    19 /*
    20  * Win32 specific includes
    21  */
    22 #ifndef WIN32_LEAN_AND_MEAN
    23 #define WIN32_LEAN_AND_MEAN
    24 #endif
    25 #include <windows.h>
    26 #else
    27 /*
    28  * POSIX specific includes
    29  */
    30 #include <sys/time.h>
    32 /* timersub is not provided by msys at this time. */
    33 #ifndef timersub
    34 #define timersub(a, b, result) \
    35   do { \
    36     (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
    37     (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
    38     if ((result)->tv_usec < 0) { \
    39       --(result)->tv_sec; \
    40       (result)->tv_usec += 1000000; \
    41     } \
    42   } while (0)
    43 #endif
    44 #endif
    47 struct vpx_usec_timer {
    48 #if defined(_WIN32)
    49   LARGE_INTEGER  begin, end;
    50 #else
    51   struct timeval begin, end;
    52 #endif
    53 };
    56 static void
    57 vpx_usec_timer_start(struct vpx_usec_timer *t) {
    58 #if defined(_WIN32)
    59   QueryPerformanceCounter(&t->begin);
    60 #else
    61   gettimeofday(&t->begin, NULL);
    62 #endif
    63 }
    66 static void
    67 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
    73 }
    76 static int64_t
    77 vpx_usec_timer_elapsed(struct vpx_usec_timer *t) {
    78 #if defined(_WIN32)
    79   LARGE_INTEGER freq, diff;
    81   diff.QuadPart = t->end.QuadPart - t->begin.QuadPart;
    83   QueryPerformanceFrequency(&freq);
    84   return diff.QuadPart * 1000000 / freq.QuadPart;
    85 #else
    86   struct timeval diff;
    88   timersub(&t->end, &t->begin, &diff);
    89   return diff.tv_sec * 1000000 + diff.tv_usec;
    90 #endif
    91 }
    93 #else /* CONFIG_OS_SUPPORT = 0*/
    95 /* Empty timer functions if CONFIG_OS_SUPPORT = 0 */
    96 #ifndef timersub
    97 #define timersub(a, b, result)
    98 #endif
   100 struct vpx_usec_timer {
   101   void *dummy;
   102 };
   104 static void
   105 vpx_usec_timer_start(struct vpx_usec_timer *t) { }
   107 static void
   108 vpx_usec_timer_mark(struct vpx_usec_timer *t) { }
   110 static long
   111 vpx_usec_timer_elapsed(struct vpx_usec_timer *t) {
   112   return 0;
   113 }
   115 #endif /* CONFIG_OS_SUPPORT */
   117 #endif

mercurial