xref: /netbsd-src/external/bsd/libevent/dist/time-internal.h (revision 657871a79c9a2060a6255a242fa1a1ef76b56ec6)
1*657871a7Schristos /*	$NetBSD: time-internal.h,v 1.1.1.2 2021/04/07 02:43:13 christos Exp $	*/
2805a1ce9Schristos /*
3805a1ce9Schristos  * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
4805a1ce9Schristos  * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
5805a1ce9Schristos  *
6805a1ce9Schristos  * Redistribution and use in source and binary forms, with or without
7805a1ce9Schristos  * modification, are permitted provided that the following conditions
8805a1ce9Schristos  * are met:
9805a1ce9Schristos  * 1. Redistributions of source code must retain the above copyright
10805a1ce9Schristos  *    notice, this list of conditions and the following disclaimer.
11805a1ce9Schristos  * 2. Redistributions in binary form must reproduce the above copyright
12805a1ce9Schristos  *    notice, this list of conditions and the following disclaimer in the
13805a1ce9Schristos  *    documentation and/or other materials provided with the distribution.
14805a1ce9Schristos  * 3. The name of the author may not be used to endorse or promote products
15805a1ce9Schristos  *    derived from this software without specific prior written permission.
16805a1ce9Schristos  *
17805a1ce9Schristos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18805a1ce9Schristos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19805a1ce9Schristos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20805a1ce9Schristos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21805a1ce9Schristos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22805a1ce9Schristos  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23805a1ce9Schristos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24805a1ce9Schristos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25805a1ce9Schristos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26805a1ce9Schristos  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27805a1ce9Schristos  */
28805a1ce9Schristos #ifndef TIME_INTERNAL_H_INCLUDED_
29805a1ce9Schristos #define TIME_INTERNAL_H_INCLUDED_
30805a1ce9Schristos 
31805a1ce9Schristos #include "event2/event-config.h"
32805a1ce9Schristos #include "evconfig-private.h"
33805a1ce9Schristos 
34805a1ce9Schristos #ifdef EVENT__HAVE_MACH_MACH_TIME_H
35805a1ce9Schristos /* For mach_timebase_info */
36805a1ce9Schristos #include <mach/mach_time.h>
37805a1ce9Schristos #endif
38805a1ce9Schristos 
39805a1ce9Schristos #include <time.h>
40805a1ce9Schristos 
41805a1ce9Schristos #include "event2/util.h"
42805a1ce9Schristos 
43805a1ce9Schristos #ifdef __cplusplus
44805a1ce9Schristos extern "C" {
45805a1ce9Schristos #endif
46805a1ce9Schristos 
47805a1ce9Schristos #if defined(EVENT__HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
48805a1ce9Schristos #define HAVE_POSIX_MONOTONIC
49805a1ce9Schristos #elif defined(EVENT__HAVE_MACH_ABSOLUTE_TIME)
50805a1ce9Schristos #define HAVE_MACH_MONOTONIC
51805a1ce9Schristos #elif defined(_WIN32)
52805a1ce9Schristos #define HAVE_WIN32_MONOTONIC
53805a1ce9Schristos #else
54805a1ce9Schristos #define HAVE_FALLBACK_MONOTONIC
55805a1ce9Schristos #endif
56805a1ce9Schristos 
57805a1ce9Schristos long evutil_tv_to_msec_(const struct timeval *tv);
58*657871a7Schristos EVENT2_EXPORT_SYMBOL
59805a1ce9Schristos void evutil_usleep_(const struct timeval *tv);
60805a1ce9Schristos 
61805a1ce9Schristos #ifdef _WIN32
62805a1ce9Schristos typedef ULONGLONG (WINAPI *ev_GetTickCount_func)(void);
63805a1ce9Schristos #endif
64805a1ce9Schristos 
65805a1ce9Schristos struct evutil_monotonic_timer {
66805a1ce9Schristos 
67805a1ce9Schristos #ifdef HAVE_MACH_MONOTONIC
68805a1ce9Schristos 	struct mach_timebase_info mach_timebase_units;
69805a1ce9Schristos #endif
70805a1ce9Schristos 
71805a1ce9Schristos #ifdef HAVE_POSIX_MONOTONIC
72805a1ce9Schristos 	int monotonic_clock;
73805a1ce9Schristos #endif
74805a1ce9Schristos 
75805a1ce9Schristos #ifdef HAVE_WIN32_MONOTONIC
76805a1ce9Schristos 	ev_GetTickCount_func GetTickCount64_fn;
77805a1ce9Schristos 	ev_GetTickCount_func GetTickCount_fn;
78805a1ce9Schristos 	ev_uint64_t last_tick_count;
79805a1ce9Schristos 	ev_uint64_t adjust_tick_count;
80805a1ce9Schristos 
81805a1ce9Schristos 	ev_uint64_t first_tick;
82805a1ce9Schristos 	ev_uint64_t first_counter;
83805a1ce9Schristos 	double usec_per_count;
84805a1ce9Schristos 	int use_performance_counter;
85805a1ce9Schristos #endif
86805a1ce9Schristos 
87805a1ce9Schristos 	struct timeval adjust_monotonic_clock;
88805a1ce9Schristos 	struct timeval last_time;
89805a1ce9Schristos };
90805a1ce9Schristos 
91*657871a7Schristos EVENT2_EXPORT_SYMBOL
92805a1ce9Schristos int evutil_configure_monotonic_time_(struct evutil_monotonic_timer *mt,
93805a1ce9Schristos     int flags);
94*657871a7Schristos EVENT2_EXPORT_SYMBOL
95805a1ce9Schristos int evutil_gettime_monotonic_(struct evutil_monotonic_timer *mt, struct timeval *tv);
96805a1ce9Schristos 
97805a1ce9Schristos 
98805a1ce9Schristos #ifdef __cplusplus
99805a1ce9Schristos }
100805a1ce9Schristos #endif
101805a1ce9Schristos 
102805a1ce9Schristos #endif /* EVENT_INTERNAL_H_INCLUDED_ */
103