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