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