1 /* 2 * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> 3 * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 #ifndef TIME_INTERNAL_H_INCLUDED_ 28 #define TIME_INTERNAL_H_INCLUDED_ 29 30 #include "event2/event-config.h" 31 #include "evconfig-private.h" 32 33 #ifdef EVENT__HAVE_MACH_MACH_TIME_H 34 /* For mach_timebase_info */ 35 #include <mach/mach_time.h> 36 #endif 37 38 #include <time.h> 39 40 #include "event2/util.h" 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 #if defined(EVENT__HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) 47 #define HAVE_POSIX_MONOTONIC 48 #elif defined(EVENT__HAVE_MACH_ABSOLUTE_TIME) 49 #define HAVE_MACH_MONOTONIC 50 #elif defined(_WIN32) 51 #define HAVE_WIN32_MONOTONIC 52 #else 53 #define HAVE_FALLBACK_MONOTONIC 54 #endif 55 56 long evutil_tv_to_msec_(const struct timeval *tv); 57 EVENT2_EXPORT_SYMBOL 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 EVENT2_EXPORT_SYMBOL 91 int evutil_configure_monotonic_time_(struct evutil_monotonic_timer *mt, 92 int flags); 93 EVENT2_EXPORT_SYMBOL 94 int evutil_gettime_monotonic_(struct evutil_monotonic_timer *mt, struct timeval *tv); 95 96 97 #ifdef __cplusplus 98 } 99 #endif 100 101 #endif /* EVENT_INTERNAL_H_INCLUDED_ */ 102