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