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