xref: /libevent-2.1.12/time-internal.h (revision 9806b126)
171bca50fSNick Mathewson /*
271bca50fSNick Mathewson  * Copyright (c) 2000-2007 Niels Provos <[email protected]>
371bca50fSNick Mathewson  * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
471bca50fSNick Mathewson  *
571bca50fSNick Mathewson  * Redistribution and use in source and binary forms, with or without
671bca50fSNick Mathewson  * modification, are permitted provided that the following conditions
771bca50fSNick Mathewson  * are met:
871bca50fSNick Mathewson  * 1. Redistributions of source code must retain the above copyright
971bca50fSNick Mathewson  *    notice, this list of conditions and the following disclaimer.
1071bca50fSNick Mathewson  * 2. Redistributions in binary form must reproduce the above copyright
1171bca50fSNick Mathewson  *    notice, this list of conditions and the following disclaimer in the
1271bca50fSNick Mathewson  *    documentation and/or other materials provided with the distribution.
1371bca50fSNick Mathewson  * 3. The name of the author may not be used to endorse or promote products
1471bca50fSNick Mathewson  *    derived from this software without specific prior written permission.
1571bca50fSNick Mathewson  *
1671bca50fSNick Mathewson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1771bca50fSNick Mathewson  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1871bca50fSNick Mathewson  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1971bca50fSNick Mathewson  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2071bca50fSNick Mathewson  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2171bca50fSNick Mathewson  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2271bca50fSNick Mathewson  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2371bca50fSNick Mathewson  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2471bca50fSNick Mathewson  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2571bca50fSNick Mathewson  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2671bca50fSNick Mathewson  */
2771bca50fSNick Mathewson #ifndef TIME_INTERNAL_H_INCLUDED_
2871bca50fSNick Mathewson #define TIME_INTERNAL_H_INCLUDED_
2971bca50fSNick Mathewson 
3071bca50fSNick Mathewson #include "event2/event-config.h"
3171bca50fSNick Mathewson #include "evconfig-private.h"
32f5e4eb05SNick Mathewson 
33f5e4eb05SNick Mathewson #ifdef EVENT__HAVE_MACH_MACH_TIME_H
34f5e4eb05SNick Mathewson /* For mach_timebase_info */
35f5e4eb05SNick Mathewson #include <mach/mach_time.h>
36f5e4eb05SNick Mathewson #endif
37f5e4eb05SNick Mathewson 
38f5e4eb05SNick Mathewson #include <time.h>
39f5e4eb05SNick Mathewson 
4071bca50fSNick Mathewson #include "event2/util.h"
4171bca50fSNick Mathewson 
4271bca50fSNick Mathewson #ifdef __cplusplus
4371bca50fSNick Mathewson extern "C" {
4471bca50fSNick Mathewson #endif
4571bca50fSNick Mathewson 
46f5e4eb05SNick Mathewson #if defined(EVENT__HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
47f5e4eb05SNick Mathewson #define HAVE_POSIX_MONOTONIC
48f5e4eb05SNick Mathewson #elif defined(EVENT__HAVE_MACH_ABSOLUTE_TIME)
49f5e4eb05SNick Mathewson #define HAVE_MACH_MONOTONIC
50f5e4eb05SNick Mathewson #elif defined(_WIN32)
51f5e4eb05SNick Mathewson #define HAVE_WIN32_MONOTONIC
52f5e4eb05SNick Mathewson #else
53f5e4eb05SNick Mathewson #define HAVE_FALLBACK_MONOTONIC
54f5e4eb05SNick Mathewson #endif
55f5e4eb05SNick Mathewson 
5671bca50fSNick Mathewson long evutil_tv_to_msec_(const struct timeval *tv);
57*9806b126SAzat Khuzhin EVENT2_EXPORT_SYMBOL
5871bca50fSNick Mathewson void evutil_usleep_(const struct timeval *tv);
5971bca50fSNick Mathewson 
602c470452SNick Mathewson #ifdef _WIN32
612c470452SNick Mathewson typedef ULONGLONG (WINAPI *ev_GetTickCount_func)(void);
622c470452SNick Mathewson #endif
632c470452SNick Mathewson 
64f5e4eb05SNick Mathewson struct evutil_monotonic_timer {
65f5e4eb05SNick Mathewson 
66f5e4eb05SNick Mathewson #ifdef HAVE_MACH_MONOTONIC
67f5e4eb05SNick Mathewson 	struct mach_timebase_info mach_timebase_units;
68f5e4eb05SNick Mathewson #endif
69f5e4eb05SNick Mathewson 
70f5e4eb05SNick Mathewson #ifdef HAVE_POSIX_MONOTONIC
71f5e4eb05SNick Mathewson 	int monotonic_clock;
72f5e4eb05SNick Mathewson #endif
73f5e4eb05SNick Mathewson 
74f5e4eb05SNick Mathewson #ifdef HAVE_WIN32_MONOTONIC
752c470452SNick Mathewson 	ev_GetTickCount_func GetTickCount64_fn;
762c470452SNick Mathewson 	ev_GetTickCount_func GetTickCount_fn;
772c470452SNick Mathewson 	ev_uint64_t last_tick_count;
782c470452SNick Mathewson 	ev_uint64_t adjust_tick_count;
792c470452SNick Mathewson 
802c470452SNick Mathewson 	ev_uint64_t first_tick;
812c470452SNick Mathewson 	ev_uint64_t first_counter;
822c470452SNick Mathewson 	double usec_per_count;
832c470452SNick Mathewson 	int use_performance_counter;
84f5e4eb05SNick Mathewson #endif
85f5e4eb05SNick Mathewson 
86f5e4eb05SNick Mathewson 	struct timeval adjust_monotonic_clock;
87f5e4eb05SNick Mathewson 	struct timeval last_time;
88f5e4eb05SNick Mathewson };
89f5e4eb05SNick Mathewson 
90*9806b126SAzat Khuzhin EVENT2_EXPORT_SYMBOL
91f5e4eb05SNick Mathewson int evutil_configure_monotonic_time_(struct evutil_monotonic_timer *mt,
92630f077cSNick Mathewson     int flags);
93*9806b126SAzat Khuzhin EVENT2_EXPORT_SYMBOL
94f5e4eb05SNick Mathewson int evutil_gettime_monotonic_(struct evutil_monotonic_timer *mt, struct timeval *tv);
95f5e4eb05SNick Mathewson 
96f5e4eb05SNick Mathewson 
9771bca50fSNick Mathewson #ifdef __cplusplus
9871bca50fSNick Mathewson }
9971bca50fSNick Mathewson #endif
10071bca50fSNick Mathewson 
10171bca50fSNick Mathewson #endif /* EVENT_INTERNAL_H_INCLUDED_ */
102