12b15cb3dSCy Schubert /* 22b15cb3dSCy Schubert * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> 32b15cb3dSCy Schubert * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 42b15cb3dSCy Schubert * 52b15cb3dSCy Schubert * Redistribution and use in source and binary forms, with or without 62b15cb3dSCy Schubert * modification, are permitted provided that the following conditions 72b15cb3dSCy Schubert * are met: 82b15cb3dSCy Schubert * 1. Redistributions of source code must retain the above copyright 92b15cb3dSCy Schubert * notice, this list of conditions and the following disclaimer. 102b15cb3dSCy Schubert * 2. Redistributions in binary form must reproduce the above copyright 112b15cb3dSCy Schubert * notice, this list of conditions and the following disclaimer in the 122b15cb3dSCy Schubert * documentation and/or other materials provided with the distribution. 132b15cb3dSCy Schubert * 3. The name of the author may not be used to endorse or promote products 142b15cb3dSCy Schubert * derived from this software without specific prior written permission. 152b15cb3dSCy Schubert * 162b15cb3dSCy Schubert * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 172b15cb3dSCy Schubert * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 182b15cb3dSCy Schubert * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 192b15cb3dSCy Schubert * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 202b15cb3dSCy Schubert * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 212b15cb3dSCy Schubert * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 222b15cb3dSCy Schubert * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 232b15cb3dSCy Schubert * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 242b15cb3dSCy Schubert * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 252b15cb3dSCy Schubert * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 262b15cb3dSCy Schubert */ 272b15cb3dSCy Schubert #ifndef TIME_INTERNAL_H_INCLUDED_ 282b15cb3dSCy Schubert #define TIME_INTERNAL_H_INCLUDED_ 292b15cb3dSCy Schubert 302b15cb3dSCy Schubert #include "event2/event-config.h" 312b15cb3dSCy Schubert #include "evconfig-private.h" 322b15cb3dSCy Schubert 332b15cb3dSCy Schubert #ifdef EVENT__HAVE_MACH_MACH_TIME_H 342b15cb3dSCy Schubert /* For mach_timebase_info */ 352b15cb3dSCy Schubert #include <mach/mach_time.h> 362b15cb3dSCy Schubert #endif 372b15cb3dSCy Schubert 382b15cb3dSCy Schubert #include <time.h> 392b15cb3dSCy Schubert 402b15cb3dSCy Schubert #include "event2/util.h" 412b15cb3dSCy Schubert 422b15cb3dSCy Schubert #ifdef __cplusplus 432b15cb3dSCy Schubert extern "C" { 442b15cb3dSCy Schubert #endif 452b15cb3dSCy Schubert 462b15cb3dSCy Schubert #if defined(EVENT__HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) 472b15cb3dSCy Schubert #define HAVE_POSIX_MONOTONIC 482b15cb3dSCy Schubert #elif defined(EVENT__HAVE_MACH_ABSOLUTE_TIME) 492b15cb3dSCy Schubert #define HAVE_MACH_MONOTONIC 502b15cb3dSCy Schubert #elif defined(_WIN32) 512b15cb3dSCy Schubert #define HAVE_WIN32_MONOTONIC 522b15cb3dSCy Schubert #else 532b15cb3dSCy Schubert #define HAVE_FALLBACK_MONOTONIC 542b15cb3dSCy Schubert #endif 552b15cb3dSCy Schubert 562b15cb3dSCy Schubert long evutil_tv_to_msec_(const struct timeval *tv); 57*a466cc55SCy Schubert EVENT2_EXPORT_SYMBOL 582b15cb3dSCy Schubert void evutil_usleep_(const struct timeval *tv); 592b15cb3dSCy Schubert 602b15cb3dSCy Schubert #ifdef _WIN32 612b15cb3dSCy Schubert typedef ULONGLONG (WINAPI *ev_GetTickCount_func)(void); 622b15cb3dSCy Schubert #endif 632b15cb3dSCy Schubert 642b15cb3dSCy Schubert struct evutil_monotonic_timer { 652b15cb3dSCy Schubert 662b15cb3dSCy Schubert #ifdef HAVE_MACH_MONOTONIC 672b15cb3dSCy Schubert struct mach_timebase_info mach_timebase_units; 682b15cb3dSCy Schubert #endif 692b15cb3dSCy Schubert 702b15cb3dSCy Schubert #ifdef HAVE_POSIX_MONOTONIC 712b15cb3dSCy Schubert int monotonic_clock; 722b15cb3dSCy Schubert #endif 732b15cb3dSCy Schubert 742b15cb3dSCy Schubert #ifdef HAVE_WIN32_MONOTONIC 752b15cb3dSCy Schubert ev_GetTickCount_func GetTickCount64_fn; 762b15cb3dSCy Schubert ev_GetTickCount_func GetTickCount_fn; 772b15cb3dSCy Schubert ev_uint64_t last_tick_count; 782b15cb3dSCy Schubert ev_uint64_t adjust_tick_count; 792b15cb3dSCy Schubert 802b15cb3dSCy Schubert ev_uint64_t first_tick; 812b15cb3dSCy Schubert ev_uint64_t first_counter; 822b15cb3dSCy Schubert double usec_per_count; 832b15cb3dSCy Schubert int use_performance_counter; 842b15cb3dSCy Schubert #endif 852b15cb3dSCy Schubert 862b15cb3dSCy Schubert struct timeval adjust_monotonic_clock; 872b15cb3dSCy Schubert struct timeval last_time; 882b15cb3dSCy Schubert }; 892b15cb3dSCy Schubert 90*a466cc55SCy Schubert EVENT2_EXPORT_SYMBOL 912b15cb3dSCy Schubert int evutil_configure_monotonic_time_(struct evutil_monotonic_timer *mt, 922b15cb3dSCy Schubert int flags); 93*a466cc55SCy Schubert EVENT2_EXPORT_SYMBOL 942b15cb3dSCy Schubert int evutil_gettime_monotonic_(struct evutil_monotonic_timer *mt, struct timeval *tv); 952b15cb3dSCy Schubert 962b15cb3dSCy Schubert 972b15cb3dSCy Schubert #ifdef __cplusplus 982b15cb3dSCy Schubert } 992b15cb3dSCy Schubert #endif 1002b15cb3dSCy Schubert 1012b15cb3dSCy Schubert #endif /* EVENT_INTERNAL_H_INCLUDED_ */ 102