]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ntp/sntp/libevent/time-internal.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / ntp / sntp / libevent / time-internal.h
1 /*
2  * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
3  * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
15  *
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.
26  */
27 #ifndef TIME_INTERNAL_H_INCLUDED_
28 #define TIME_INTERNAL_H_INCLUDED_
29
30 #include "event2/event-config.h"
31 #include "evconfig-private.h"
32
33 #ifdef EVENT__HAVE_MACH_MACH_TIME_H
34 /* For mach_timebase_info */
35 #include <mach/mach_time.h>
36 #endif
37
38 #include <time.h>
39
40 #include "event2/util.h"
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
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
50 #elif defined(_WIN32)
51 #define HAVE_WIN32_MONOTONIC
52 #else
53 #define HAVE_FALLBACK_MONOTONIC
54 #endif
55
56 long evutil_tv_to_msec_(const struct timeval *tv);
57 void evutil_usleep_(const struct timeval *tv);
58
59 #ifdef _WIN32
60 typedef ULONGLONG (WINAPI *ev_GetTickCount_func)(void);
61 #endif
62
63 struct evutil_monotonic_timer {
64
65 #ifdef HAVE_MACH_MONOTONIC
66         struct mach_timebase_info mach_timebase_units;
67 #endif
68
69 #ifdef HAVE_POSIX_MONOTONIC
70         int monotonic_clock;
71 #endif
72
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;
78
79         ev_uint64_t first_tick;
80         ev_uint64_t first_counter;
81         double usec_per_count;
82         int use_performance_counter;
83 #endif
84
85         struct timeval adjust_monotonic_clock;
86         struct timeval last_time;
87 };
88
89 int evutil_configure_monotonic_time_(struct evutil_monotonic_timer *mt,
90     int flags);
91 int evutil_gettime_monotonic_(struct evutil_monotonic_timer *mt, struct timeval *tv);
92
93
94 #ifdef __cplusplus
95 }
96 #endif
97
98 #endif /* EVENT_INTERNAL_H_INCLUDED_ */