xref: /netbsd-src/external/bsd/ntp/dist/sntp/libevent/time-internal.h (revision eabc0478de71e4e011a5b4e0392741e01d491794)
1*eabc0478Schristos /*	$NetBSD: time-internal.h,v 1.7 2024/08/18 20:47:21 christos Exp $	*/
28585484eSchristos 
38585484eSchristos /*
48585484eSchristos  * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
58585484eSchristos  * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
68585484eSchristos  *
78585484eSchristos  * Redistribution and use in source and binary forms, with or without
88585484eSchristos  * modification, are permitted provided that the following conditions
98585484eSchristos  * are met:
108585484eSchristos  * 1. Redistributions of source code must retain the above copyright
118585484eSchristos  *    notice, this list of conditions and the following disclaimer.
128585484eSchristos  * 2. Redistributions in binary form must reproduce the above copyright
138585484eSchristos  *    notice, this list of conditions and the following disclaimer in the
148585484eSchristos  *    documentation and/or other materials provided with the distribution.
158585484eSchristos  * 3. The name of the author may not be used to endorse or promote products
168585484eSchristos  *    derived from this software without specific prior written permission.
178585484eSchristos  *
188585484eSchristos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
198585484eSchristos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
208585484eSchristos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
218585484eSchristos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
228585484eSchristos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
238585484eSchristos  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
248585484eSchristos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
258585484eSchristos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
268585484eSchristos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
278585484eSchristos  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
288585484eSchristos  */
298585484eSchristos #ifndef TIME_INTERNAL_H_INCLUDED_
308585484eSchristos #define TIME_INTERNAL_H_INCLUDED_
318585484eSchristos 
328585484eSchristos #include "event2/event-config.h"
338585484eSchristos #include "evconfig-private.h"
348585484eSchristos 
358585484eSchristos #ifdef EVENT__HAVE_MACH_MACH_TIME_H
368585484eSchristos /* For mach_timebase_info */
378585484eSchristos #include <mach/mach_time.h>
388585484eSchristos #endif
398585484eSchristos 
408585484eSchristos #include <time.h>
418585484eSchristos 
428585484eSchristos #include "event2/util.h"
438585484eSchristos 
448585484eSchristos #ifdef __cplusplus
458585484eSchristos extern "C" {
468585484eSchristos #endif
478585484eSchristos 
488585484eSchristos #if defined(EVENT__HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
498585484eSchristos #define HAVE_POSIX_MONOTONIC
508585484eSchristos #elif defined(EVENT__HAVE_MACH_ABSOLUTE_TIME)
518585484eSchristos #define HAVE_MACH_MONOTONIC
528585484eSchristos #elif defined(_WIN32)
538585484eSchristos #define HAVE_WIN32_MONOTONIC
548585484eSchristos #else
558585484eSchristos #define HAVE_FALLBACK_MONOTONIC
568585484eSchristos #endif
578585484eSchristos 
588585484eSchristos long evutil_tv_to_msec_(const struct timeval *tv);
59*eabc0478Schristos EVENT2_EXPORT_SYMBOL
608585484eSchristos void evutil_usleep_(const struct timeval *tv);
618585484eSchristos 
628585484eSchristos #ifdef _WIN32
638585484eSchristos typedef ULONGLONG (WINAPI *ev_GetTickCount_func)(void);
648585484eSchristos #endif
658585484eSchristos 
668585484eSchristos struct evutil_monotonic_timer {
678585484eSchristos 
688585484eSchristos #ifdef HAVE_MACH_MONOTONIC
698585484eSchristos 	struct mach_timebase_info mach_timebase_units;
708585484eSchristos #endif
718585484eSchristos 
728585484eSchristos #ifdef HAVE_POSIX_MONOTONIC
738585484eSchristos 	int monotonic_clock;
748585484eSchristos #endif
758585484eSchristos 
768585484eSchristos #ifdef HAVE_WIN32_MONOTONIC
778585484eSchristos 	ev_GetTickCount_func GetTickCount64_fn;
788585484eSchristos 	ev_GetTickCount_func GetTickCount_fn;
798585484eSchristos 	ev_uint64_t last_tick_count;
808585484eSchristos 	ev_uint64_t adjust_tick_count;
818585484eSchristos 
828585484eSchristos 	ev_uint64_t first_tick;
838585484eSchristos 	ev_uint64_t first_counter;
848585484eSchristos 	double usec_per_count;
858585484eSchristos 	int use_performance_counter;
868585484eSchristos #endif
878585484eSchristos 
888585484eSchristos 	struct timeval adjust_monotonic_clock;
898585484eSchristos 	struct timeval last_time;
908585484eSchristos };
918585484eSchristos 
92*eabc0478Schristos EVENT2_EXPORT_SYMBOL
938585484eSchristos int evutil_configure_monotonic_time_(struct evutil_monotonic_timer *mt,
948585484eSchristos     int flags);
95*eabc0478Schristos EVENT2_EXPORT_SYMBOL
968585484eSchristos int evutil_gettime_monotonic_(struct evutil_monotonic_timer *mt, struct timeval *tv);
978585484eSchristos 
988585484eSchristos 
998585484eSchristos #ifdef __cplusplus
1008585484eSchristos }
1018585484eSchristos #endif
1028585484eSchristos 
1038585484eSchristos #endif /* EVENT_INTERNAL_H_INCLUDED_ */
104