Commit | Line | Data |
---|---|---|
10a4cc63 | 1 | /* systime.h - System-dependent definitions for time manipulations. |
acaf905b | 2 | Copyright (C) 1993-1994, 2002-2012 Free Software Foundation, Inc. |
f469625a JB |
3 | |
4 | This file is part of GNU Emacs. | |
5 | ||
b9b1cc14 | 6 | GNU Emacs is free software: you can redistribute it and/or modify |
f469625a | 7 | it under the terms of the GNU General Public License as published by |
b9b1cc14 GM |
8 | the Free Software Foundation, either version 3 of the License, or |
9 | (at your option) any later version. | |
f469625a JB |
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 | |
b9b1cc14 | 17 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
f469625a | 18 | |
fb1b041d DL |
19 | #ifndef EMACS_SYSTIME_H |
20 | #define EMACS_SYSTIME_H | |
482fa053 | 21 | |
d35af63c | 22 | #include <timespec.h> |
7b89707c | 23 | |
89d1bd22 PE |
24 | #ifdef emacs |
25 | # ifdef HAVE_X_WINDOWS | |
26 | # include <X11/X.h> | |
27 | # else | |
08dc5ae6 | 28 | typedef unsigned long Time; |
89d1bd22 | 29 | # endif |
08dc5ae6 PE |
30 | #endif |
31 | ||
71068d78 KH |
32 | /* On some configurations (hpux8.0, X11R4), sys/time.h and X11/Xos.h |
33 | disagree about the name of the guard symbol. */ | |
c810639a | 34 | #ifdef HPUX |
71068d78 KH |
35 | #ifdef _STRUCT_TIMEVAL |
36 | #ifndef __TIMEVAL__ | |
37 | #define __TIMEVAL__ | |
38 | #endif | |
39 | #endif | |
c810639a | 40 | #endif |
10a4cc63 | 41 | \f |
d35af63c PE |
42 | /* The type to use to represent temporal intervals. It can be passed |
43 | as the timeout argument to the pselect system call. */ | |
44 | #define EMACS_TIME struct timespec | |
f469625a | 45 | |
d35af63c PE |
46 | /* Resolution of EMACS_TIME time stamps (in units per second), and log |
47 | base 10 of the resolution. The log must be a positive integer. */ | |
48 | #define EMACS_TIME_RESOLUTION 1000000000 | |
49 | #define LOG10_EMACS_TIME_RESOLUTION 9 | |
50 | ||
51 | /* EMACS_SECS (TIME) is an rvalue for the seconds component of TIME. | |
52 | EMACS_SECS_ADDR (time) is the address of the seconds component. | |
f469625a JB |
53 | EMACS_SET_SECS (TIME, SECONDS) sets that to SECONDS. |
54 | ||
d35af63c PE |
55 | EMACS_NSECS (TIME) is an rvalue for the nanoseconds component of TIME. |
56 | EMACS_SET_NSECS (TIME, NANOSECONDS) sets that to NANOSECONDS. | |
f469625a | 57 | |
d35af63c PE |
58 | EMACS_SET_SECS_NSECS (TIME, SECS, NSECS) sets both components of TIME. */ |
59 | #define EMACS_SECS(time) ((time).tv_sec + 0) | |
60 | #define EMACS_NSECS(time) ((time).tv_nsec + 0) | |
61 | #define EMACS_SECS_ADDR(time) (&(time).tv_sec) | |
62 | #define EMACS_SET_SECS(time, seconds) ((time).tv_sec = (seconds)) | |
63 | #define EMACS_SET_NSECS(time, ns) ((time).tv_nsec = (ns)) | |
64 | #define EMACS_SET_SECS_NSECS(time, s, ns) \ | |
65 | ((void) (EMACS_SET_SECS (time, s), EMACS_SET_NSECS (time, ns))) | |
f469625a | 66 | |
d35af63c PE |
67 | /* Convenience macros for older code that counts microseconds. */ |
68 | #define EMACS_SET_USECS(time, us) ((void) EMACS_SET_NSECS (time, (us) * 1000)) | |
69 | #define EMACS_SET_SECS_USECS(time, secs, usecs) \ | |
70 | (EMACS_SET_SECS (time, secs), EMACS_SET_USECS (time, usecs)) | |
f469625a | 71 | |
d35af63c PE |
72 | /* Set TIME to an invalid time stamp. */ |
73 | #define EMACS_SET_INVALID_TIME(time) EMACS_SET_SECS_NSECS(time, 0, -1) | |
f469625a | 74 | |
d35af63c PE |
75 | /* Set TIME to the current system time. */ |
76 | #define EMACS_GET_TIME(time) gettime (&(time)) | |
f469625a | 77 | |
d35af63c PE |
78 | /* Put into DEST the result of adding SRC1 to SRC2, or of subtracting |
79 | SRC2 from SRC1. On overflow, store an extremal value. */ | |
80 | #define EMACS_ADD_TIME(dest, src1, src2) ((dest) = timespec_add (src1, src2)) | |
81 | #define EMACS_SUB_TIME(dest, src1, src2) ((dest) = timespec_sub (src1, src2)) | |
f469625a | 82 | |
d35af63c PE |
83 | /* Return the sign of the valid time stamp TIME, either -1, 0, or 1. */ |
84 | #define EMACS_TIME_SIGN(time) timespec_sign (time) | |
f469625a | 85 | |
d35af63c PE |
86 | /* Return 1 if TIME is a valid time stamp. */ |
87 | #define EMACS_TIME_VALID_P(time) (0 <= (time).tv_nsec) | |
722687f5 | 88 | |
d35af63c PE |
89 | /* Convert the double D to the greatest EMACS_TIME not greater than D. |
90 | On overflow, return an extremal value. Return the minimum | |
91 | EMACS_TIME if D is not a number. */ | |
92 | #define EMACS_TIME_FROM_DOUBLE(d) dtotimespec (d) | |
f469625a | 93 | |
d35af63c PE |
94 | /* Convert the Emacs time T to an approximate double value D. */ |
95 | #define EMACS_TIME_TO_DOUBLE(t) timespectod (t) | |
f469625a | 96 | |
d35af63c PE |
97 | /* defined in sysdep.c */ |
98 | extern int set_file_times (int, const char *, EMACS_TIME, EMACS_TIME); | |
99 | extern struct timeval make_timeval (EMACS_TIME); | |
c53a6701 | 100 | |
43f15d4a | 101 | /* defined in keyboard.c */ |
383e0970 | 102 | extern void set_waiting_for_input (EMACS_TIME *); |
43f15d4a | 103 | |
fa8459a3 DN |
104 | /* When lisp.h is not included Lisp_Object is not defined (this can |
105 | happen when this files is used outside the src directory). | |
106 | Use GCPRO1 to determine if lisp.h was included. */ | |
107 | #ifdef GCPRO1 | |
d35af63c PE |
108 | /* defined in editfns.c */ |
109 | extern Lisp_Object make_lisp_time (EMACS_TIME); | |
110 | extern int decode_time_components (Lisp_Object, Lisp_Object, Lisp_Object, | |
111 | Lisp_Object, EMACS_TIME *, int *); | |
112 | extern EMACS_TIME lisp_time_argument (Lisp_Object, int *); | |
fa8459a3 DN |
113 | #endif |
114 | ||
c53a6701 GM |
115 | /* Compare times T1 and T2 for equality, inequality etc. */ |
116 | ||
d35af63c PE |
117 | #define EMACS_TIME_EQ(T1, T2) (timespec_cmp (T1, T2) == 0) |
118 | #define EMACS_TIME_NE(T1, T2) (timespec_cmp (T1, T2) != 0) | |
119 | #define EMACS_TIME_GT(T1, T2) (timespec_cmp (T1, T2) > 0) | |
120 | #define EMACS_TIME_GE(T1, T2) (timespec_cmp (T1, T2) >= 0) | |
121 | #define EMACS_TIME_LT(T1, T2) (timespec_cmp (T1, T2) < 0) | |
122 | #define EMACS_TIME_LE(T1, T2) (timespec_cmp (T1, T2) <= 0) | |
c53a6701 | 123 | |
fb1b041d | 124 | #endif /* EMACS_SYSTIME_H */ |