1*663afb9bSAndroid Build Coastguard Worker /* 2*663afb9bSAndroid Build Coastguard Worker * Copyright (c) 2000-2007 Niels Provos <[email protected]> 3*663afb9bSAndroid Build Coastguard Worker * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4*663afb9bSAndroid Build Coastguard Worker * 5*663afb9bSAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without 6*663afb9bSAndroid Build Coastguard Worker * modification, are permitted provided that the following conditions 7*663afb9bSAndroid Build Coastguard Worker * are met: 8*663afb9bSAndroid Build Coastguard Worker * 1. Redistributions of source code must retain the above copyright 9*663afb9bSAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer. 10*663afb9bSAndroid Build Coastguard Worker * 2. Redistributions in binary form must reproduce the above copyright 11*663afb9bSAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer in the 12*663afb9bSAndroid Build Coastguard Worker * documentation and/or other materials provided with the distribution. 13*663afb9bSAndroid Build Coastguard Worker * 3. The name of the author may not be used to endorse or promote products 14*663afb9bSAndroid Build Coastguard Worker * derived from this software without specific prior written permission. 15*663afb9bSAndroid Build Coastguard Worker * 16*663afb9bSAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17*663afb9bSAndroid Build Coastguard Worker * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18*663afb9bSAndroid Build Coastguard Worker * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19*663afb9bSAndroid Build Coastguard Worker * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20*663afb9bSAndroid Build Coastguard Worker * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21*663afb9bSAndroid Build Coastguard Worker * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22*663afb9bSAndroid Build Coastguard Worker * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23*663afb9bSAndroid Build Coastguard Worker * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24*663afb9bSAndroid Build Coastguard Worker * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25*663afb9bSAndroid Build Coastguard Worker * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26*663afb9bSAndroid Build Coastguard Worker */ 27*663afb9bSAndroid Build Coastguard Worker #ifndef TIME_INTERNAL_H_INCLUDED_ 28*663afb9bSAndroid Build Coastguard Worker #define TIME_INTERNAL_H_INCLUDED_ 29*663afb9bSAndroid Build Coastguard Worker 30*663afb9bSAndroid Build Coastguard Worker #include "event2/event-config.h" 31*663afb9bSAndroid Build Coastguard Worker #include "evconfig-private.h" 32*663afb9bSAndroid Build Coastguard Worker 33*663afb9bSAndroid Build Coastguard Worker #ifdef EVENT__HAVE_MACH_MACH_TIME_H 34*663afb9bSAndroid Build Coastguard Worker /* For mach_timebase_info */ 35*663afb9bSAndroid Build Coastguard Worker #include <mach/mach_time.h> 36*663afb9bSAndroid Build Coastguard Worker #endif 37*663afb9bSAndroid Build Coastguard Worker 38*663afb9bSAndroid Build Coastguard Worker #include <time.h> 39*663afb9bSAndroid Build Coastguard Worker 40*663afb9bSAndroid Build Coastguard Worker #include "event2/util.h" 41*663afb9bSAndroid Build Coastguard Worker 42*663afb9bSAndroid Build Coastguard Worker #ifdef __cplusplus 43*663afb9bSAndroid Build Coastguard Worker extern "C" { 44*663afb9bSAndroid Build Coastguard Worker #endif 45*663afb9bSAndroid Build Coastguard Worker 46*663afb9bSAndroid Build Coastguard Worker #if defined(EVENT__HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) 47*663afb9bSAndroid Build Coastguard Worker #define HAVE_POSIX_MONOTONIC 48*663afb9bSAndroid Build Coastguard Worker #elif defined(EVENT__HAVE_MACH_ABSOLUTE_TIME) 49*663afb9bSAndroid Build Coastguard Worker #define HAVE_MACH_MONOTONIC 50*663afb9bSAndroid Build Coastguard Worker #elif defined(_WIN32) 51*663afb9bSAndroid Build Coastguard Worker #define HAVE_WIN32_MONOTONIC 52*663afb9bSAndroid Build Coastguard Worker #else 53*663afb9bSAndroid Build Coastguard Worker #define HAVE_FALLBACK_MONOTONIC 54*663afb9bSAndroid Build Coastguard Worker #endif 55*663afb9bSAndroid Build Coastguard Worker 56*663afb9bSAndroid Build Coastguard Worker long evutil_tv_to_msec_(const struct timeval *tv); 57*663afb9bSAndroid Build Coastguard Worker EVENT2_EXPORT_SYMBOL 58*663afb9bSAndroid Build Coastguard Worker void evutil_usleep_(const struct timeval *tv); 59*663afb9bSAndroid Build Coastguard Worker 60*663afb9bSAndroid Build Coastguard Worker #ifdef _WIN32 61*663afb9bSAndroid Build Coastguard Worker typedef ULONGLONG (WINAPI *ev_GetTickCount_func)(void); 62*663afb9bSAndroid Build Coastguard Worker #endif 63*663afb9bSAndroid Build Coastguard Worker 64*663afb9bSAndroid Build Coastguard Worker struct evutil_monotonic_timer { 65*663afb9bSAndroid Build Coastguard Worker 66*663afb9bSAndroid Build Coastguard Worker #ifdef HAVE_MACH_MONOTONIC 67*663afb9bSAndroid Build Coastguard Worker struct mach_timebase_info mach_timebase_units; 68*663afb9bSAndroid Build Coastguard Worker #endif 69*663afb9bSAndroid Build Coastguard Worker 70*663afb9bSAndroid Build Coastguard Worker #ifdef HAVE_POSIX_MONOTONIC 71*663afb9bSAndroid Build Coastguard Worker int monotonic_clock; 72*663afb9bSAndroid Build Coastguard Worker #endif 73*663afb9bSAndroid Build Coastguard Worker 74*663afb9bSAndroid Build Coastguard Worker #ifdef HAVE_WIN32_MONOTONIC 75*663afb9bSAndroid Build Coastguard Worker ev_GetTickCount_func GetTickCount64_fn; 76*663afb9bSAndroid Build Coastguard Worker ev_GetTickCount_func GetTickCount_fn; 77*663afb9bSAndroid Build Coastguard Worker ev_uint64_t last_tick_count; 78*663afb9bSAndroid Build Coastguard Worker ev_uint64_t adjust_tick_count; 79*663afb9bSAndroid Build Coastguard Worker 80*663afb9bSAndroid Build Coastguard Worker ev_uint64_t first_tick; 81*663afb9bSAndroid Build Coastguard Worker ev_uint64_t first_counter; 82*663afb9bSAndroid Build Coastguard Worker double usec_per_count; 83*663afb9bSAndroid Build Coastguard Worker int use_performance_counter; 84*663afb9bSAndroid Build Coastguard Worker #endif 85*663afb9bSAndroid Build Coastguard Worker 86*663afb9bSAndroid Build Coastguard Worker struct timeval adjust_monotonic_clock; 87*663afb9bSAndroid Build Coastguard Worker struct timeval last_time; 88*663afb9bSAndroid Build Coastguard Worker }; 89*663afb9bSAndroid Build Coastguard Worker 90*663afb9bSAndroid Build Coastguard Worker EVENT2_EXPORT_SYMBOL 91*663afb9bSAndroid Build Coastguard Worker int evutil_configure_monotonic_time_(struct evutil_monotonic_timer *mt, 92*663afb9bSAndroid Build Coastguard Worker int flags); 93*663afb9bSAndroid Build Coastguard Worker EVENT2_EXPORT_SYMBOL 94*663afb9bSAndroid Build Coastguard Worker int evutil_gettime_monotonic_(struct evutil_monotonic_timer *mt, struct timeval *tv); 95*663afb9bSAndroid Build Coastguard Worker 96*663afb9bSAndroid Build Coastguard Worker 97*663afb9bSAndroid Build Coastguard Worker #ifdef __cplusplus 98*663afb9bSAndroid Build Coastguard Worker } 99*663afb9bSAndroid Build Coastguard Worker #endif 100*663afb9bSAndroid Build Coastguard Worker 101*663afb9bSAndroid Build Coastguard Worker #endif /* EVENT_INTERNAL_H_INCLUDED_ */ 102