Path: blob/main/contrib/llvm-project/libc/include/llvm-libc-macros/linux/sys-time-macros.h
213799 views
//===-- Definition of macros from sys/time.h ------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLVM_LIBC_MACROS_LINUX_SYS_TIME_MACROS_H9#define LLVM_LIBC_MACROS_LINUX_SYS_TIME_MACROS_H1011// Add two timevals and put the result in timeval_ptr_result. If the resulting12// usec value is greater than 999,999 then the microseconds are turned into full13// seconds (1,000,000 is subtracted from usec and 1 is added to sec).14#define timeradd(timeval_ptr_a, timeval_ptr_b, timeval_ptr_result) \15(timeval_ptr_result)->tv_sec = \16(timeval_ptr_a)->tv_sec + (timeval_ptr_b)->tv_sec + \17(((timeval_ptr_a)->tv_usec + (timeval_ptr_b)->tv_usec) >= 1000000 ? 1 \18: 0); \19(timeval_ptr_result)->tv_usec = \20(timeval_ptr_a)->tv_usec + (timeval_ptr_b)->tv_usec - \21(((timeval_ptr_a)->tv_usec + (timeval_ptr_b)->tv_usec) >= 1000000 \22? 1000000 \23: 0);2425// Subtract two timevals and put the result in timeval_ptr_result. If the26// resulting usec value is less than 0 then 1,000,000 is added to usec and 1 is27// subtracted from sec.28#define timersub(timeval_ptr_a, timeval_ptr_b, timeval_ptr_result) \29(timeval_ptr_result)->tv_sec = \30(timeval_ptr_a)->tv_sec - (timeval_ptr_b)->tv_sec - \31(((timeval_ptr_a)->tv_usec - (timeval_ptr_b)->tv_usec) < 0 ? 1 : 0); \32(timeval_ptr_result)->tv_usec = \33(timeval_ptr_a)->tv_usec - (timeval_ptr_b)->tv_usec + \34(((timeval_ptr_a)->tv_usec - (timeval_ptr_b)->tv_usec) < 0 ? 1000000 \35: 0);3637// Reset a timeval to the epoch.38#define timerclear(timeval_ptr) \39(timeval_ptr)->tv_sec = 0; \40(timeval_ptr)->tv_usec = 0;4142// Determine if a timeval is set to the epoch.43#define timerisset(timeval_ptr) \44(timeval_ptr)->tv_sec != 0 || (timeval_ptr)->tv_usec != 0;4546// Compare two timevals using CMP.47#define timercmp(timeval_ptr_a, timeval_ptr_b, CMP) \48(((timeval_ptr_a)->tv_sec == (timeval_ptr_b)->tv_sec) \49? ((timeval_ptr_a)->tv_usec CMP(timeval_ptr_b)->tv_usec) \50: ((timeval_ptr_a)->tv_sec CMP(timeval_ptr_b)->tv_sec))5152#endif // LLVM_LIBC_MACROS_LINUX_SYS_TIME_MACROS_H535455