1 /* systime.h - System-dependent definitions for time manipulations. 2 Copyright (C) 1993-1994, 2002-2023 Free Software Foundation, Inc. 3 4 This file is part of GNU Emacs. 5 6 GNU Emacs is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or (at 9 your option) any later version. 10 11 GNU Emacs is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ 18 19 #ifndef EMACS_SYSTIME_H 20 #define EMACS_SYSTIME_H 21 22 #include "lisp.h" 23 #include <timespec.h> 24 25 INLINE_HEADER_BEGIN 26 27 #ifdef HAVE_X_WINDOWS 28 # include <X11/X.h> 29 #elif defined HAVE_HAIKU 30 # include <support/SupportDefs.h> 31 typedef int64 Time; 32 #else 33 typedef unsigned long Time; 34 #endif 35 36 /* On some configurations (hpux8.0, X11R4), sys/time.h and X11/Xos.h 37 disagree about the name of the guard symbol. */ 38 #ifdef HPUX 39 #ifdef _STRUCT_TIMEVAL 40 #ifndef __TIMEVAL__ 41 #define __TIMEVAL__ 42 #endif 43 #endif 44 #endif 45 46 #include <sys/time.h> /* for 'struct timeval' */ 47 48 #undef hz /* AIX <sys/param.h> #defines this. */ 49 50 /* Emacs uses struct timespec to represent nonnegative temporal intervals. 51 52 WARNING: Since tv_sec might be an unsigned value, do not use struct 53 timespec as a general-purpose data type for adding or subtracting 54 arbitrary time values! When computing A + B or A - B, typically A 55 should be an absolute time since the epoch and B a nonnegative offset. */ 56 57 /* Return an invalid timespec. */ 58 INLINE struct timespec 59 invalid_timespec (void) 60 { 61 return make_timespec (0, -1); 62 } 63 64 /* Return true if TIME is a valid timespec. This currently doesn't worry 65 about whether tv_nsec is less than TIMESPEC_HZ; leap seconds might 66 cause a problem if it did. */ 67 INLINE bool 68 timespec_valid_p (struct timespec t) 69 { 70 return t.tv_nsec >= 0; 71 } 72 73 /* defined in keyboard.c */ 74 extern void set_waiting_for_input (struct timespec *); 75 76 /* Emacs uses the integer list (HI LO US PS) to represent the time 77 (HI << LO_TIME_BITS) + LO + US / 1e6 + PS / 1e12. */ 78 enum { LO_TIME_BITS = 16 }; 79 80 /* Components of a new-format Lisp timestamp. */ 81 struct lisp_time 82 { 83 /* Clock count as a Lisp integer. */ 84 Lisp_Object ticks; 85 86 /* Clock frequency (ticks per second) as a positive Lisp integer. */ 87 Lisp_Object hz; 88 }; 89 90 /* defined in timefns.c */ 91 extern struct timeval make_timeval (struct timespec) ATTRIBUTE_CONST; 92 extern Lisp_Object make_lisp_time (struct timespec); 93 extern Lisp_Object timespec_to_lisp (struct timespec); 94 extern bool list4_to_timespec (Lisp_Object, Lisp_Object, Lisp_Object, 95 Lisp_Object, struct timespec *); 96 extern struct timespec lisp_time_argument (Lisp_Object); 97 extern double float_time (Lisp_Object); 98 extern void init_timefns (void); 99 extern void syms_of_timefns (void); 100 101 INLINE_HEADER_END 102 103 #endif /* EMACS_SYSTIME_H */