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 EZ |
41 | |
42 | #ifdef WINDOWSNT | |
43 | #include <sys/time.h> /* for 'struct timeval' */ | |
44 | #endif | |
10a4cc63 | 45 | \f |
d35af63c PE |
46 | /* The type to use to represent temporal intervals. It can be passed |
47 | as the timeout argument to the pselect system call. */ | |
48 | #define EMACS_TIME struct timespec | |
f469625a | 49 | |
d35af63c PE |
50 | /* Resolution of EMACS_TIME time stamps (in units per second), and log |
51 | base 10 of the resolution. The log must be a positive integer. */ | |
52 | #define EMACS_TIME_RESOLUTION 1000000000 | |
53 | #define LOG10_EMACS_TIME_RESOLUTION 9 | |
54 | ||
55 | /* EMACS_SECS (TIME) is an rvalue for the seconds component of TIME. | |
56 | EMACS_SECS_ADDR (time) is the address of the seconds component. | |
f469625a JB |
57 | EMACS_SET_SECS (TIME, SECONDS) sets that to SECONDS. |
58 | ||
d35af63c PE |
59 | EMACS_NSECS (TIME) is an rvalue for the nanoseconds component of TIME. |
60 | EMACS_SET_NSECS (TIME, NANOSECONDS) sets that to NANOSECONDS. | |
f469625a | 61 | |
d35af63c PE |
62 | EMACS_SET_SECS_NSECS (TIME, SECS, NSECS) sets both components of TIME. */ |
63 | #define EMACS_SECS(time) ((time).tv_sec + 0) | |
64 | #define EMACS_NSECS(time) ((time).tv_nsec + 0) | |
65 | #define EMACS_SECS_ADDR(time) (&(time).tv_sec) | |
66 | #define EMACS_SET_SECS(time, seconds) ((time).tv_sec = (seconds)) | |
67 | #define EMACS_SET_NSECS(time, ns) ((time).tv_nsec = (ns)) | |
68 | #define EMACS_SET_SECS_NSECS(time, s, ns) \ | |
69 | ((void) (EMACS_SET_SECS (time, s), EMACS_SET_NSECS (time, ns))) | |
f469625a | 70 | |
d35af63c PE |
71 | /* Convenience macros for older code that counts microseconds. */ |
72 | #define EMACS_SET_USECS(time, us) ((void) EMACS_SET_NSECS (time, (us) * 1000)) | |
73 | #define EMACS_SET_SECS_USECS(time, secs, usecs) \ | |
74 | (EMACS_SET_SECS (time, secs), EMACS_SET_USECS (time, usecs)) | |
f469625a | 75 | |
d35af63c PE |
76 | /* Set TIME to an invalid time stamp. */ |
77 | #define EMACS_SET_INVALID_TIME(time) EMACS_SET_SECS_NSECS(time, 0, -1) | |
f469625a | 78 | |
d35af63c PE |
79 | /* Set TIME to the current system time. */ |
80 | #define EMACS_GET_TIME(time) gettime (&(time)) | |
f469625a | 81 | |
d35af63c PE |
82 | /* Put into DEST the result of adding SRC1 to SRC2, or of subtracting |
83 | SRC2 from SRC1. On overflow, store an extremal value. */ | |
84 | #define EMACS_ADD_TIME(dest, src1, src2) ((dest) = timespec_add (src1, src2)) | |
85 | #define EMACS_SUB_TIME(dest, src1, src2) ((dest) = timespec_sub (src1, src2)) | |
f469625a | 86 | |
d35af63c PE |
87 | /* Return the sign of the valid time stamp TIME, either -1, 0, or 1. */ |
88 | #define EMACS_TIME_SIGN(time) timespec_sign (time) | |
f469625a | 89 | |
d35af63c PE |
90 | /* Return 1 if TIME is a valid time stamp. */ |
91 | #define EMACS_TIME_VALID_P(time) (0 <= (time).tv_nsec) | |
722687f5 | 92 | |
d35af63c PE |
93 | /* Convert the double D to the greatest EMACS_TIME not greater than D. |
94 | On overflow, return an extremal value. Return the minimum | |
95 | EMACS_TIME if D is not a number. */ | |
96 | #define EMACS_TIME_FROM_DOUBLE(d) dtotimespec (d) | |
f469625a | 97 | |
d35af63c PE |
98 | /* Convert the Emacs time T to an approximate double value D. */ |
99 | #define EMACS_TIME_TO_DOUBLE(t) timespectod (t) | |
f469625a | 100 | |
d35af63c PE |
101 | /* defined in sysdep.c */ |
102 | extern int set_file_times (int, const char *, EMACS_TIME, EMACS_TIME); | |
103 | extern struct timeval make_timeval (EMACS_TIME); | |
c53a6701 | 104 | |
43f15d4a | 105 | /* defined in keyboard.c */ |
383e0970 | 106 | extern void set_waiting_for_input (EMACS_TIME *); |
43f15d4a | 107 | |
fa8459a3 DN |
108 | /* When lisp.h is not included Lisp_Object is not defined (this can |
109 | happen when this files is used outside the src directory). | |
110 | Use GCPRO1 to determine if lisp.h was included. */ | |
111 | #ifdef GCPRO1 | |
d35af63c PE |
112 | /* defined in editfns.c */ |
113 | extern Lisp_Object make_lisp_time (EMACS_TIME); | |
114 | extern int decode_time_components (Lisp_Object, Lisp_Object, Lisp_Object, | |
115 | Lisp_Object, EMACS_TIME *, int *); | |
116 | extern EMACS_TIME lisp_time_argument (Lisp_Object, int *); | |
fa8459a3 DN |
117 | #endif |
118 | ||
c53a6701 GM |
119 | /* Compare times T1 and T2 for equality, inequality etc. */ |
120 | ||
d35af63c PE |
121 | #define EMACS_TIME_EQ(T1, T2) (timespec_cmp (T1, T2) == 0) |
122 | #define EMACS_TIME_NE(T1, T2) (timespec_cmp (T1, T2) != 0) | |
123 | #define EMACS_TIME_GT(T1, T2) (timespec_cmp (T1, T2) > 0) | |
124 | #define EMACS_TIME_GE(T1, T2) (timespec_cmp (T1, T2) >= 0) | |
125 | #define EMACS_TIME_LT(T1, T2) (timespec_cmp (T1, T2) < 0) | |
126 | #define EMACS_TIME_LE(T1, T2) (timespec_cmp (T1, T2) <= 0) | |
c53a6701 | 127 | |
fb1b041d | 128 | #endif /* EMACS_SYSTIME_H */ |