1275970Scy/*
2275970Scy * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
3275970Scy * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4275970Scy *
5275970Scy * Redistribution and use in source and binary forms, with or without
6275970Scy * modification, are permitted provided that the following conditions
7275970Scy * are met:
8275970Scy * 1. Redistributions of source code must retain the above copyright
9275970Scy *    notice, this list of conditions and the following disclaimer.
10275970Scy * 2. Redistributions in binary form must reproduce the above copyright
11275970Scy *    notice, this list of conditions and the following disclaimer in the
12275970Scy *    documentation and/or other materials provided with the distribution.
13275970Scy * 3. The name of the author may not be used to endorse or promote products
14275970Scy *    derived from this software without specific prior written permission.
15275970Scy *
16275970Scy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17275970Scy * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18275970Scy * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19275970Scy * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20275970Scy * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21275970Scy * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22275970Scy * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23275970Scy * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24275970Scy * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25275970Scy * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26275970Scy */
27275970Scy#ifndef TIME_INTERNAL_H_INCLUDED_
28275970Scy#define TIME_INTERNAL_H_INCLUDED_
29275970Scy
30275970Scy#include "event2/event-config.h"
31275970Scy#include "evconfig-private.h"
32275970Scy
33275970Scy#ifdef EVENT__HAVE_MACH_MACH_TIME_H
34275970Scy/* For mach_timebase_info */
35275970Scy#include <mach/mach_time.h>
36275970Scy#endif
37275970Scy
38275970Scy#include <time.h>
39275970Scy
40275970Scy#include "event2/util.h"
41275970Scy
42275970Scy#ifdef __cplusplus
43275970Scyextern "C" {
44275970Scy#endif
45275970Scy
46275970Scy#if defined(EVENT__HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
47275970Scy#define HAVE_POSIX_MONOTONIC
48275970Scy#elif defined(EVENT__HAVE_MACH_ABSOLUTE_TIME)
49275970Scy#define HAVE_MACH_MONOTONIC
50275970Scy#elif defined(_WIN32)
51275970Scy#define HAVE_WIN32_MONOTONIC
52275970Scy#else
53275970Scy#define HAVE_FALLBACK_MONOTONIC
54275970Scy#endif
55275970Scy
56275970Scylong evutil_tv_to_msec_(const struct timeval *tv);
57275970Scyvoid evutil_usleep_(const struct timeval *tv);
58275970Scy
59275970Scy#ifdef _WIN32
60275970Scytypedef ULONGLONG (WINAPI *ev_GetTickCount_func)(void);
61275970Scy#endif
62275970Scy
63275970Scystruct evutil_monotonic_timer {
64275970Scy
65275970Scy#ifdef HAVE_MACH_MONOTONIC
66275970Scy	struct mach_timebase_info mach_timebase_units;
67275970Scy#endif
68275970Scy
69275970Scy#ifdef HAVE_POSIX_MONOTONIC
70275970Scy	int monotonic_clock;
71275970Scy#endif
72275970Scy
73275970Scy#ifdef HAVE_WIN32_MONOTONIC
74275970Scy	ev_GetTickCount_func GetTickCount64_fn;
75275970Scy	ev_GetTickCount_func GetTickCount_fn;
76275970Scy	ev_uint64_t last_tick_count;
77275970Scy	ev_uint64_t adjust_tick_count;
78275970Scy
79275970Scy	ev_uint64_t first_tick;
80275970Scy	ev_uint64_t first_counter;
81275970Scy	double usec_per_count;
82275970Scy	int use_performance_counter;
83275970Scy#endif
84275970Scy
85275970Scy	struct timeval adjust_monotonic_clock;
86275970Scy	struct timeval last_time;
87275970Scy};
88275970Scy
89275970Scyint evutil_configure_monotonic_time_(struct evutil_monotonic_timer *mt,
90275970Scy    int flags);
91275970Scyint evutil_gettime_monotonic_(struct evutil_monotonic_timer *mt, struct timeval *tv);
92275970Scy
93275970Scy
94275970Scy#ifdef __cplusplus
95275970Scy}
96275970Scy#endif
97275970Scy
98275970Scy#endif /* EVENT_INTERNAL_H_INCLUDED_ */
99