| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| |
| /*- |
| * Copyright (c) 1982, 1986, 1993 |
| * The Regents of the University of California. All rights reserved. |
| * |
| * Redistribution and use in source and binary forms, with or without |
| * modification, are permitted provided that the following conditions |
| * are met: |
| * 1. Redistributions of source code must retain the above copyright |
| * notice, this list of conditions and the following disclaimer. |
| * 2. Redistributions in binary form must reproduce the above copyright |
| * notice, this list of conditions and the following disclaimer in the |
| * documentation and/or other materials provided with the distribution. |
| * 4. Neither the name of the University nor the names of its contributors |
| * may be used to endorse or promote products derived from this software |
| * without specific prior written permission. |
| * |
| * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| * SUCH DAMAGE. |
| * |
| * @(#)time.h 8.5 (Berkeley) 5/4/95 |
| * $FreeBSD$ |
| */ |
| |
| #ifndef _OS_TIME_H |
| #define _OS_TIME_H |
| |
| #include <stdbool.h> |
| #include <stdint.h> |
| |
| #ifdef __cplusplus |
| extern "C" { |
| #endif |
| |
| #ifndef UINT32_MAX |
| #define UINT32_MAX 0xFFFFFFFFU |
| #endif |
| |
| typedef uint32_t os_time_t; |
| #define OS_TIME_MAX UINT32_MAX |
| |
| /* Used to wait forever for events and mutexs */ |
| #define OS_TIMEOUT_NEVER (UINT32_MAX) |
| |
| os_time_t os_time_get(void); |
| void os_time_advance(int ticks); |
| void os_time_delay(int32_t osticks); |
| |
| #define OS_TIME_TICK_LT(__t1, __t2) ((int32_t) ((__t1) - (__t2)) < 0) |
| #define OS_TIME_TICK_GT(__t1, __t2) ((int32_t) ((__t1) - (__t2)) > 0) |
| #define OS_TIME_TICK_GEQ(__t1, __t2) ((int32_t) ((__t1) - (__t2)) >= 0) |
| |
| struct os_timeval { |
| int64_t tv_sec; /* seconds since Jan 1 1970 */ |
| int32_t tv_usec; /* microseconds within the second */ |
| }; |
| |
| struct os_timezone { |
| int16_t tz_minuteswest; /* with respect to GMT */ |
| int16_t tz_dsttime; /* daylight savings time correction (if any) */ |
| }; |
| |
| #define os_timeradd(tvp, uvp, vvp) \ |
| do { \ |
| (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ |
| (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ |
| if ((vvp)->tv_usec >= 1000000) { \ |
| (vvp)->tv_sec++; \ |
| (vvp)->tv_usec -= 1000000; \ |
| } \ |
| } while (0) |
| |
| #define os_timersub(tvp, uvp, vvp) \ |
| do { \ |
| (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ |
| (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ |
| if ((vvp)->tv_usec < 0) { \ |
| (vvp)->tv_sec--; \ |
| (vvp)->tv_usec += 1000000; \ |
| } \ |
| } while (0) |
| |
| int os_settimeofday(struct os_timeval *utctime, struct os_timezone *tz); |
| int os_gettimeofday(struct os_timeval *utctime, struct os_timezone *tz); |
| int64_t os_get_uptime_usec(void); |
| int os_time_ms_to_ticks(uint32_t ms, uint32_t *out_ticks); |
| |
| #ifdef __cplusplus |
| } |
| #endif |
| |
| #endif /* _OS_TIME_H */ |