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 |
696056c2 | 41 | |
696056c2 | 42 | #include <sys/time.h> /* for 'struct timeval' */ |
10a4cc63 | 43 | \f |
e9a9ae03 | 44 | /* The type to use to represent temporal intervals. Its address can be passed |
d35af63c | 45 | as the timeout argument to the pselect system call. */ |
e9a9ae03 | 46 | typedef struct timespec EMACS_TIME; |
f469625a | 47 | |
d35af63c PE |
48 | /* Resolution of EMACS_TIME time stamps (in units per second), and log |
49 | base 10 of the resolution. The log must be a positive integer. */ | |
e9a9ae03 PE |
50 | enum { EMACS_TIME_RESOLUTION = 1000000000 }; |
51 | enum { LOG10_EMACS_TIME_RESOLUTION = 9 }; | |
52 | ||
53 | /* EMACS_SECS (TIME) is the seconds component of TIME. | |
54 | EMACS_NSECS (TIME) is the nanoseconds component of TIME. | |
55 | emacs_secs_addr (PTIME) is the address of *PTIME's seconds component. */ | |
56 | static inline time_t EMACS_SECS (EMACS_TIME t) { return t.tv_sec; } | |
57 | static inline int EMACS_NSECS (EMACS_TIME t) { return t.tv_nsec; } | |
58 | static inline time_t *emacs_secs_addr (EMACS_TIME *t) { return &t->tv_sec; } | |
59 | ||
60 | /* Return an Emacs time with seconds S and nanoseconds NS. */ | |
61 | static inline EMACS_TIME | |
62 | make_emacs_time (time_t s, int ns) | |
63 | { | |
64 | EMACS_TIME r = { s, ns }; | |
65 | return r; | |
66 | } | |
67 | ||
68 | /* Return an invalid Emacs time. */ | |
69 | static inline EMACS_TIME | |
70 | invalid_emacs_time (void) | |
71 | { | |
72 | EMACS_TIME r = { 0, -1 }; | |
73 | return r; | |
74 | } | |
75 | ||
76 | /* Return current system time. */ | |
77 | static inline EMACS_TIME | |
78 | current_emacs_time (void) | |
79 | { | |
80 | EMACS_TIME r; | |
81 | gettime (&r); | |
82 | return r; | |
83 | } | |
84 | ||
85 | /* Return the result of adding A to B, or of subtracting B from A. | |
86 | On overflow, store an extremal value: ergo, if time_t is unsigned, | |
87 | return 0 if the true answer would be negative. */ | |
88 | static inline EMACS_TIME | |
89 | add_emacs_time (EMACS_TIME a, EMACS_TIME b) | |
90 | { | |
91 | return timespec_add (a, b); | |
92 | } | |
93 | static inline EMACS_TIME | |
94 | sub_emacs_time (EMACS_TIME a, EMACS_TIME b) | |
95 | { | |
96 | return timespec_sub (a, b); | |
97 | } | |
f469625a | 98 | |
d35af63c | 99 | /* Return the sign of the valid time stamp TIME, either -1, 0, or 1. */ |
e9a9ae03 PE |
100 | static inline int |
101 | EMACS_TIME_SIGN (EMACS_TIME t) | |
102 | { | |
103 | return timespec_sign (t); | |
104 | } | |
f469625a | 105 | |
d35af63c | 106 | /* Return 1 if TIME is a valid time stamp. */ |
e9a9ae03 PE |
107 | static inline int |
108 | EMACS_TIME_VALID_P (EMACS_TIME t) | |
109 | { | |
110 | return 0 <= t.tv_nsec; | |
111 | } | |
722687f5 | 112 | |
d35af63c PE |
113 | /* Convert the double D to the greatest EMACS_TIME not greater than D. |
114 | On overflow, return an extremal value. Return the minimum | |
115 | EMACS_TIME if D is not a number. */ | |
e9a9ae03 PE |
116 | static inline EMACS_TIME |
117 | EMACS_TIME_FROM_DOUBLE (double d) | |
118 | { | |
119 | return dtotimespec (d); | |
120 | } | |
f469625a | 121 | |
d35af63c | 122 | /* Convert the Emacs time T to an approximate double value D. */ |
e9a9ae03 PE |
123 | static inline double |
124 | EMACS_TIME_TO_DOUBLE (EMACS_TIME t) | |
125 | { | |
126 | return timespectod (t); | |
127 | } | |
f469625a | 128 | |
d35af63c PE |
129 | /* defined in sysdep.c */ |
130 | extern int set_file_times (int, const char *, EMACS_TIME, EMACS_TIME); | |
131 | extern struct timeval make_timeval (EMACS_TIME); | |
c53a6701 | 132 | |
43f15d4a | 133 | /* defined in keyboard.c */ |
383e0970 | 134 | extern void set_waiting_for_input (EMACS_TIME *); |
43f15d4a | 135 | |
fa8459a3 DN |
136 | /* When lisp.h is not included Lisp_Object is not defined (this can |
137 | happen when this files is used outside the src directory). | |
138 | Use GCPRO1 to determine if lisp.h was included. */ | |
139 | #ifdef GCPRO1 | |
d35af63c PE |
140 | /* defined in editfns.c */ |
141 | extern Lisp_Object make_lisp_time (EMACS_TIME); | |
142 | extern int decode_time_components (Lisp_Object, Lisp_Object, Lisp_Object, | |
31571fd7 PE |
143 | Lisp_Object, EMACS_TIME *, double *); |
144 | extern EMACS_TIME lisp_time_argument (Lisp_Object); | |
fa8459a3 DN |
145 | #endif |
146 | ||
c53a6701 | 147 | /* Compare times T1 and T2 for equality, inequality etc. */ |
e9a9ae03 PE |
148 | static inline int |
149 | EMACS_TIME_EQ (EMACS_TIME t1, EMACS_TIME t2) | |
150 | { | |
151 | return timespec_cmp (t1, t2) == 0; | |
152 | } | |
153 | static inline int | |
154 | EMACS_TIME_NE (EMACS_TIME t1, EMACS_TIME t2) | |
155 | { | |
156 | return timespec_cmp (t1, t2) != 0; | |
157 | } | |
158 | static inline int | |
159 | EMACS_TIME_GT (EMACS_TIME t1, EMACS_TIME t2) | |
160 | { | |
161 | return timespec_cmp (t1, t2) > 0; | |
162 | } | |
163 | static inline int | |
164 | EMACS_TIME_GE (EMACS_TIME t1, EMACS_TIME t2) | |
165 | { | |
166 | return timespec_cmp (t1, t2) >= 0; | |
167 | } | |
168 | static inline int | |
169 | EMACS_TIME_LT (EMACS_TIME t1, EMACS_TIME t2) | |
170 | { | |
171 | return timespec_cmp (t1, t2) < 0; | |
172 | } | |
173 | static inline int | |
174 | EMACS_TIME_LE (EMACS_TIME t1, EMACS_TIME t2) | |
175 | { | |
176 | return timespec_cmp (t1, t2) <= 0; | |
177 | } | |
c53a6701 | 178 | |
fb1b041d | 179 | #endif /* EMACS_SYSTIME_H */ |