2 * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
3 * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
27 #ifndef TIME_INTERNAL_H_INCLUDED_
28 #define TIME_INTERNAL_H_INCLUDED_
30 #include "event2/event-config.h"
31 #include "evconfig-private.h"
33 #ifdef EVENT__HAVE_MACH_MACH_TIME_H
34 /* For mach_timebase_info */
35 #include <mach/mach_time.h>
40 #include "event2/util.h"
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
51 #define HAVE_WIN32_MONOTONIC
53 #define HAVE_FALLBACK_MONOTONIC
56 long evutil_tv_to_msec_(const struct timeval *tv);
57 void evutil_usleep_(const struct timeval *tv);
60 typedef ULONGLONG (WINAPI *ev_GetTickCount_func)(void);
63 struct evutil_monotonic_timer {
65 #ifdef HAVE_MACH_MONOTONIC
66 struct mach_timebase_info mach_timebase_units;
69 #ifdef HAVE_POSIX_MONOTONIC
73 #ifdef HAVE_WIN32_MONOTONIC
74 ev_GetTickCount_func GetTickCount64_fn;
75 ev_GetTickCount_func GetTickCount_fn;
76 ev_uint64_t last_tick_count;
77 ev_uint64_t adjust_tick_count;
79 ev_uint64_t first_tick;
80 ev_uint64_t first_counter;
81 double usec_per_count;
82 int use_performance_counter;
85 struct timeval adjust_monotonic_clock;
86 struct timeval last_time;
89 int evutil_configure_monotonic_time_(struct evutil_monotonic_timer *mt,
91 int evutil_gettime_monotonic_(struct evutil_monotonic_timer *mt, struct timeval *tv);
98 #endif /* EVENT_INTERNAL_H_INCLUDED_ */