1 /* 2 * Copyright 2020-2022, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 /*- 6 * SPDX-License-Identifier: BSD-3-Clause 7 * 8 * Copyright (c) 1982, 1986, 1993 9 * The Regents of the University of California. All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * @(#)time.h 8.5 (Berkeley) 5/4/95 36 * $FreeBSD$ 37 */ 38 #ifndef _FBSD_COMPAT_SYS_TIME_H_ 39 #define _FBSD_COMPAT_SYS_TIME_H_ 40 41 42 #include <posix/sys/time.h> 43 44 #include <sys/_timeval.h> 45 #include <sys/types.h> 46 47 48 #define TICKS_2_USEC(t) ((1000000*(bigtime_t)t) / hz) 49 #define USEC_2_TICKS(t) (((bigtime_t)t*hz) / 1000000) 50 51 #define TICKS_2_MSEC(t) ((1000*(bigtime_t)t) / hz) 52 #define MSEC_2_TICKS(t) (((bigtime_t)t*hz) / 1000) 53 54 #define time_uptime (system_time()/(1000*1000)) 55 56 57 /* Operations on timevals. */ 58 #define timevalclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) 59 #define timevalisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) 60 #define timevalcmp(tvp, uvp, cmp) \ 61 (((tvp)->tv_sec == (uvp)->tv_sec) ? \ 62 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ 63 ((tvp)->tv_sec cmp (uvp)->tv_sec)) 64 65 66 void getmicrouptime(struct timeval *tvp); 67 68 int ppsratecheck(struct timeval *, int *, int); 69 int ratecheck(struct timeval *, const struct timeval *); 70 void timevaladd(struct timeval *t1, const struct timeval *t2); 71 void timevalsub(struct timeval *t1, const struct timeval *t2); 72 73 74 #endif /* _FBSD_COMPAT_SYS_TIME_H_ */ 75