diff options
| author | Paul Eggert | 2012-06-22 14:17:42 -0700 |
|---|---|---|
| committer | Paul Eggert | 2012-06-22 14:17:42 -0700 |
| commit | d35af63cd671563fd188c3b0a1ef30067027c7aa (patch) | |
| tree | c9e01847ccf788e23794684da9331c3e0defd0d3 /lisp | |
| parent | f143bfe38b43ad0a9d817f05c25e418982dca06f (diff) | |
| download | emacs-d35af63cd671563fd188c3b0a1ef30067027c7aa.tar.gz emacs-d35af63cd671563fd188c3b0a1ef30067027c7aa.zip | |
Support higher-resolution time stamps.
Fixes: debbugs:9000
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 23 | ||||
| -rw-r--r-- | lisp/calendar/time-date.el | 105 | ||||
| -rw-r--r-- | lisp/emacs-lisp/timer.el | 87 | ||||
| -rw-r--r-- | lisp/proced.el | 6 |
4 files changed, 153 insertions, 68 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 42342c60386..f99b3e4d32a 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,26 @@ | |||
| 1 | 2012-06-22 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | Support higher-resolution time stamps (Bug#9000). | ||
| 4 | |||
| 5 | * calendar/time-date.el (with-decoded-time-value): New arg | ||
| 6 | PICO-SYMBOL in VARLIST. It's optional, for backward compatibility. | ||
| 7 | (encode-time-value): New optional arg PICO. New type 3. | ||
| 8 | (time-to-seconds) [!float-time]: Support the new picoseconds | ||
| 9 | component if it's used. | ||
| 10 | (seconds-to-time, time-subtract, time-add): | ||
| 11 | Support ps-resolution time stamps as well. | ||
| 12 | |||
| 13 | * emacs-lisp/timer.el (timer): New component psecs. All uses changed. | ||
| 14 | (timerp): Timer vectors now have length 9, not 8. | ||
| 15 | (timer--time): Support new-style (4-part) time stamps. | ||
| 16 | (timer-next-integral-multiple-of-time): Time stamps now have | ||
| 17 | picosecond resolution, so take a bit more care about rounding. | ||
| 18 | (timer-relative-time, timer-inc-time): New optional arg psecs. | ||
| 19 | (timer-set-time-with-usecs): Set psecs to 0. | ||
| 20 | (timer--activate): Check psecs component, too. | ||
| 21 | |||
| 22 | * proced.el (proced-time-lessp): Support ps-resolution stamps. | ||
| 23 | |||
| 1 | 2012-06-22 Stefan Monnier <monnier@iro.umontreal.ca> | 24 | 2012-06-22 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 25 | ||
| 3 | * icomplete.el (icomplete-minibuffer-setup, icomplete-completions): | 26 | * icomplete.el (icomplete-minibuffer-setup, icomplete-completions): |
diff --git a/lisp/calendar/time-date.el b/lisp/calendar/time-date.el index 46e38ae46a8..38b766084c9 100644 --- a/lisp/calendar/time-date.el +++ b/lisp/calendar/time-date.el | |||
| @@ -23,15 +23,15 @@ | |||
| 23 | 23 | ||
| 24 | ;;; Commentary: | 24 | ;;; Commentary: |
| 25 | 25 | ||
| 26 | ;; Time values come in three formats. The oldest format is a cons | 26 | ;; Time values come in several formats. The oldest format is a cons |
| 27 | ;; cell of the form (HIGH . LOW). This format is obsolete, but still | 27 | ;; cell of the form (HIGH . LOW). This format is obsolete, but still |
| 28 | ;; supported. The two other formats are the lists (HIGH LOW) and | 28 | ;; supported. The other formats are the lists (HIGH LOW), (HIGH LOW |
| 29 | ;; (HIGH LOW MICRO). The first two formats specify HIGH * 2^16 + LOW | 29 | ;; USEC), and (HIGH LOW USEC PSEC). These formats specify the time |
| 30 | ;; seconds; the third format specifies HIGH * 2^16 + LOW + MICRO / | 30 | ;; value equal to HIGH * 2^16 + LOW + USEC * 10^-6 + PSEC * 10^-12 |
| 31 | ;; 1000000 seconds. We should have 0 <= MICRO < 1000000 and 0 <= LOW | 31 | ;; seconds, where missing components are treated as zero. HIGH can be |
| 32 | ;; < 2^16. If the time value represents a point in time, then HIGH is | 32 | ;; negative, either because the value is a time difference, or because |
| 33 | ;; nonnegative. If the time value is a time difference, then HIGH can | 33 | ;; the machine supports negative time stamps that fall before the |
| 34 | ;; be negative as well. The macro `with-decoded-time-value' and the | 34 | ;; epoch. The macro `with-decoded-time-value' and the |
| 35 | ;; function `encode-time-value' make it easier to deal with these | 35 | ;; function `encode-time-value' make it easier to deal with these |
| 36 | ;; three formats. See `time-subtract' for an example of how to use | 36 | ;; three formats. See `time-subtract' for an example of how to use |
| 37 | ;; them. | 37 | ;; them. |
| @@ -44,13 +44,15 @@ | |||
| 44 | The value of the last form in BODY is returned. | 44 | The value of the last form in BODY is returned. |
| 45 | 45 | ||
| 46 | Each element of the list VARLIST is a list of the form | 46 | Each element of the list VARLIST is a list of the form |
| 47 | \(HIGH-SYMBOL LOW-SYMBOL MICRO-SYMBOL [TYPE-SYMBOL] TIME-VALUE). | 47 | \(HIGH-SYMBOL LOW-SYMBOL MICRO-SYMBOL [PICO-SYMBOL [TYPE-SYMBOL]] TIME-VALUE). |
| 48 | The time value TIME-VALUE is decoded and the result it bound to | 48 | The time value TIME-VALUE is decoded and the result it bound to |
| 49 | the symbols HIGH-SYMBOL, LOW-SYMBOL and MICRO-SYMBOL. | 49 | the symbols HIGH-SYMBOL, LOW-SYMBOL and MICRO-SYMBOL. |
| 50 | The optional PICO-SYMBOL is bound to the picoseconds part. | ||
| 50 | 51 | ||
| 51 | The optional TYPE-SYMBOL is bound to the type of the time value. | 52 | The optional TYPE-SYMBOL is bound to the type of the time value. |
| 52 | Type 0 is the cons cell (HIGH . LOW), type 1 is the list (HIGH | 53 | Type 0 is the cons cell (HIGH . LOW), type 1 is the list (HIGH |
| 53 | LOW), and type 2 is the list (HIGH LOW MICRO)." | 54 | LOW), type 2 is the list (HIGH LOW MICRO), and type 3 is the |
| 55 | list (HIGH LOW MICRO PICO)." | ||
| 54 | (declare (indent 1) | 56 | (declare (indent 1) |
| 55 | (debug ((&rest (symbolp symbolp symbolp &or [symbolp form] form)) | 57 | (debug ((&rest (symbolp symbolp symbolp &or [symbolp form] form)) |
| 56 | body))) | 58 | body))) |
| @@ -59,6 +61,8 @@ LOW), and type 2 is the list (HIGH LOW MICRO)." | |||
| 59 | (high (pop elt)) | 61 | (high (pop elt)) |
| 60 | (low (pop elt)) | 62 | (low (pop elt)) |
| 61 | (micro (pop elt)) | 63 | (micro (pop elt)) |
| 64 | (pico (unless (<= (length elt) 2) | ||
| 65 | (pop elt))) | ||
| 62 | (type (unless (eq (length elt) 1) | 66 | (type (unless (eq (length elt) 1) |
| 63 | (pop elt))) | 67 | (pop elt))) |
| 64 | (time-value (car elt)) | 68 | (time-value (car elt)) |
| @@ -66,28 +70,44 @@ LOW), and type 2 is the list (HIGH LOW MICRO)." | |||
| 66 | `(let* ,(append `((,gensym ,time-value) | 70 | `(let* ,(append `((,gensym ,time-value) |
| 67 | (,high (pop ,gensym)) | 71 | (,high (pop ,gensym)) |
| 68 | ,low ,micro) | 72 | ,low ,micro) |
| 73 | (when pico `(,pico)) | ||
| 69 | (when type `(,type))) | 74 | (when type `(,type))) |
| 70 | (if (consp ,gensym) | 75 | (if (consp ,gensym) |
| 71 | (progn | 76 | (progn |
| 72 | (setq ,low (pop ,gensym)) | 77 | (setq ,low (pop ,gensym)) |
| 73 | (if ,gensym | 78 | (if ,gensym |
| 74 | ,(append `(setq ,micro (car ,gensym)) | 79 | (progn |
| 75 | (when type `(,type 2))) | 80 | (setq ,micro (car ,gensym)) |
| 81 | ,(cond (pico | ||
| 82 | `(if (cdr ,gensym) | ||
| 83 | ,(append `(setq ,pico (cadr ,gensym)) | ||
| 84 | (when type `(,type 3))) | ||
| 85 | ,(append `(setq ,pico 0) | ||
| 86 | (when type `(,type 2))))) | ||
| 87 | (type | ||
| 88 | `(setq type 2)))) | ||
| 76 | ,(append `(setq ,micro 0) | 89 | ,(append `(setq ,micro 0) |
| 90 | (when pico `(,pico 0)) | ||
| 77 | (when type `(,type 1))))) | 91 | (when type `(,type 1))))) |
| 78 | ,(append `(setq ,low ,gensym ,micro 0) | 92 | ,(append `(setq ,low ,gensym ,micro 0) |
| 93 | (when pico `(,pico 0)) | ||
| 79 | (when type `(,type 0)))) | 94 | (when type `(,type 0)))) |
| 80 | (with-decoded-time-value ,varlist ,@body))) | 95 | (with-decoded-time-value ,varlist ,@body))) |
| 81 | `(progn ,@body))) | 96 | `(progn ,@body))) |
| 82 | 97 | ||
| 83 | (defun encode-time-value (high low micro type) | 98 | (defun encode-time-value (high low micro pico &optional type) |
| 84 | "Encode HIGH, LOW, and MICRO into a time value of type TYPE. | 99 | "Encode HIGH, LOW, MICRO, and PICO into a time value of type TYPE. |
| 85 | Type 0 is the cons cell (HIGH . LOW), type 1 is the list (HIGH LOW), | 100 | Type 0 is the cons cell (HIGH . LOW), type 1 is the list (HIGH LOW), |
| 86 | and type 2 is the list (HIGH LOW MICRO)." | 101 | type 2 is (HIGH LOW MICRO), and type 3 is (HIGH LOW MICRO PICO). |
| 102 | |||
| 103 | For backward compatibility, if only four arguments are given, | ||
| 104 | it is assumed that PICO was omitted and should be treated as zero." | ||
| 87 | (cond | 105 | (cond |
| 88 | ((eq type 0) (cons high low)) | 106 | ((eq type 0) (cons high low)) |
| 89 | ((eq type 1) (list high low)) | 107 | ((eq type 1) (list high low)) |
| 90 | ((eq type 2) (list high low micro)))) | 108 | ((eq type 2) (list high low micro)) |
| 109 | ((eq type 3) (list high low micro pico)) | ||
| 110 | ((null type) (encode-time-value high low micro 0 pico)))) | ||
| 91 | 111 | ||
| 92 | (autoload 'parse-time-string "parse-time") | 112 | (autoload 'parse-time-string "parse-time") |
| 93 | (autoload 'timezone-make-date-arpa-standard "timezone") | 113 | (autoload 'timezone-make-date-arpa-standard "timezone") |
| @@ -125,28 +145,45 @@ If DATE lacks timezone information, GMT is assumed." | |||
| 125 | (subrp (symbol-function 'float-time))) | 145 | (subrp (symbol-function 'float-time))) |
| 126 | (defun time-to-seconds (time) | 146 | (defun time-to-seconds (time) |
| 127 | "Convert time value TIME to a floating point number." | 147 | "Convert time value TIME to a floating point number." |
| 128 | (with-decoded-time-value ((high low micro time)) | 148 | (with-decoded-time-value ((high low micro pico type time)) |
| 129 | (+ (* 1.0 high 65536) | 149 | (+ (* 1.0 high 65536) |
| 130 | low | 150 | low |
| 131 | (/ micro 1000000.0)))))) | 151 | (/ (+ (* micro 1e6) pico) 1e12)))))) |
| 132 | 152 | ||
| 133 | ;;;###autoload | 153 | ;;;###autoload |
| 134 | (defun seconds-to-time (seconds) | 154 | (defun seconds-to-time (seconds) |
| 135 | "Convert SECONDS (a floating point number) to a time value." | 155 | "Convert SECONDS (a floating point number) to a time value." |
| 136 | (list (floor seconds 65536) | 156 | (let* ((usec (* 1000000 (mod seconds 1))) |
| 137 | (floor (mod seconds 65536)) | 157 | (ps (round (* 1000000 (mod usec 1)))) |
| 138 | (floor (* (- seconds (ffloor seconds)) 1000000)))) | 158 | (us (floor usec)) |
| 159 | (lo (floor (mod seconds 65536))) | ||
| 160 | (hi (floor seconds 65536))) | ||
| 161 | (if (eq ps 1000000) | ||
| 162 | (progn | ||
| 163 | (setq ps 0) | ||
| 164 | (setq us (1+ us)) | ||
| 165 | (if (eq us 1000000) | ||
| 166 | (progn | ||
| 167 | (setq us 0) | ||
| 168 | (setq lo (1+ lo)) | ||
| 169 | (if (eq lo 65536) | ||
| 170 | (progn | ||
| 171 | (setq lo 0) | ||
| 172 | (setq hi (1+ hi)))))))) | ||
| 173 | (list hi lo us ps))) | ||
| 139 | 174 | ||
| 140 | ;;;###autoload | 175 | ;;;###autoload |
| 141 | (defun time-less-p (t1 t2) | 176 | (defun time-less-p (t1 t2) |
| 142 | "Return non-nil if time value T1 is earlier than time value T2." | 177 | "Return non-nil if time value T1 is earlier than time value T2." |
| 143 | (with-decoded-time-value ((high1 low1 micro1 t1) | 178 | (with-decoded-time-value ((high1 low1 micro1 pico1 type1 t1) |
| 144 | (high2 low2 micro2 t2)) | 179 | (high2 low2 micro2 pico2 type2 t2)) |
| 145 | (or (< high1 high2) | 180 | (or (< high1 high2) |
| 146 | (and (= high1 high2) | 181 | (and (= high1 high2) |
| 147 | (or (< low1 low2) | 182 | (or (< low1 low2) |
| 148 | (and (= low1 low2) | 183 | (and (= low1 low2) |
| 149 | (< micro1 micro2))))))) | 184 | (or (< micro1 micro2) |
| 185 | (and (= micro1 micro2) | ||
| 186 | (< pico1 pico2))))))))) | ||
| 150 | 187 | ||
| 151 | ;;;###autoload | 188 | ;;;###autoload |
| 152 | (defun days-to-time (days) | 189 | (defun days-to-time (days) |
| @@ -173,36 +210,44 @@ TIME should be either a time value or a date-time string." | |||
| 173 | (defun time-subtract (t1 t2) | 210 | (defun time-subtract (t1 t2) |
| 174 | "Subtract two time values, T1 minus T2. | 211 | "Subtract two time values, T1 minus T2. |
| 175 | Return the difference in the format of a time value." | 212 | Return the difference in the format of a time value." |
| 176 | (with-decoded-time-value ((high low micro type t1) | 213 | (with-decoded-time-value ((high low micro pico type t1) |
| 177 | (high2 low2 micro2 type2 t2)) | 214 | (high2 low2 micro2 pico2 type2 t2)) |
| 178 | (setq high (- high high2) | 215 | (setq high (- high high2) |
| 179 | low (- low low2) | 216 | low (- low low2) |
| 180 | micro (- micro micro2) | 217 | micro (- micro micro2) |
| 218 | pico (- pico pico2) | ||
| 181 | type (max type type2)) | 219 | type (max type type2)) |
| 220 | (when (< pico 0) | ||
| 221 | (setq micro (1- micro) | ||
| 222 | pico (+ pico 1000000))) | ||
| 182 | (when (< micro 0) | 223 | (when (< micro 0) |
| 183 | (setq low (1- low) | 224 | (setq low (1- low) |
| 184 | micro (+ micro 1000000))) | 225 | micro (+ micro 1000000))) |
| 185 | (when (< low 0) | 226 | (when (< low 0) |
| 186 | (setq high (1- high) | 227 | (setq high (1- high) |
| 187 | low (+ low 65536))) | 228 | low (+ low 65536))) |
| 188 | (encode-time-value high low micro type))) | 229 | (encode-time-value high low micro pico type))) |
| 189 | 230 | ||
| 190 | ;;;###autoload | 231 | ;;;###autoload |
| 191 | (defun time-add (t1 t2) | 232 | (defun time-add (t1 t2) |
| 192 | "Add two time values T1 and T2. One should represent a time difference." | 233 | "Add two time values T1 and T2. One should represent a time difference." |
| 193 | (with-decoded-time-value ((high low micro type t1) | 234 | (with-decoded-time-value ((high low micro pico type t1) |
| 194 | (high2 low2 micro2 type2 t2)) | 235 | (high2 low2 micro2 pico2 type2 t2)) |
| 195 | (setq high (+ high high2) | 236 | (setq high (+ high high2) |
| 196 | low (+ low low2) | 237 | low (+ low low2) |
| 197 | micro (+ micro micro2) | 238 | micro (+ micro micro2) |
| 239 | pico (+ pico pico2) | ||
| 198 | type (max type type2)) | 240 | type (max type type2)) |
| 241 | (when (>= pico 1000000) | ||
| 242 | (setq micro (1+ micro) | ||
| 243 | pico (- pico 1000000))) | ||
| 199 | (when (>= micro 1000000) | 244 | (when (>= micro 1000000) |
| 200 | (setq low (1+ low) | 245 | (setq low (1+ low) |
| 201 | micro (- micro 1000000))) | 246 | micro (- micro 1000000))) |
| 202 | (when (>= low 65536) | 247 | (when (>= low 65536) |
| 203 | (setq high (1+ high) | 248 | (setq high (1+ high) |
| 204 | low (- low 65536))) | 249 | low (- low 65536))) |
| 205 | (encode-time-value high low micro type))) | 250 | (encode-time-value high low micro pico type))) |
| 206 | 251 | ||
| 207 | ;;;###autoload | 252 | ;;;###autoload |
| 208 | (defun date-to-day (date) | 253 | (defun date-to-day (date) |
diff --git a/lisp/emacs-lisp/timer.el b/lisp/emacs-lisp/timer.el index 0b8480441c3..eab96fe202a 100644 --- a/lisp/emacs-lisp/timer.el +++ b/lisp/emacs-lisp/timer.el | |||
| @@ -28,7 +28,7 @@ | |||
| 28 | ;;; Code: | 28 | ;;; Code: |
| 29 | 29 | ||
| 30 | ;; Layout of a timer vector: | 30 | ;; Layout of a timer vector: |
| 31 | ;; [triggered-p high-seconds low-seconds usecs repeat-delay | 31 | ;; [triggered-p high-seconds low-seconds usecs psecs repeat-delay |
| 32 | ;; function args idle-delay] | 32 | ;; function args idle-delay] |
| 33 | ;; triggered-p is nil if the timer is active (waiting to be triggered), | 33 | ;; triggered-p is nil if the timer is active (waiting to be triggered), |
| 34 | ;; t if it is inactive ("already triggered", in theory) | 34 | ;; t if it is inactive ("already triggered", in theory) |
| @@ -42,27 +42,35 @@ | |||
| 42 | (:type vector) | 42 | (:type vector) |
| 43 | (:conc-name timer--)) | 43 | (:conc-name timer--)) |
| 44 | (triggered t) | 44 | (triggered t) |
| 45 | high-seconds low-seconds usecs repeat-delay function args idle-delay) | 45 | high-seconds low-seconds usecs psecs repeat-delay function args idle-delay) |
| 46 | 46 | ||
| 47 | (defun timerp (object) | 47 | (defun timerp (object) |
| 48 | "Return t if OBJECT is a timer." | 48 | "Return t if OBJECT is a timer." |
| 49 | (and (vectorp object) (= (length object) 8))) | 49 | (and (vectorp object) (= (length object) 9))) |
| 50 | 50 | ||
| 51 | ;; Pseudo field `time'. | 51 | ;; Pseudo field `time'. |
| 52 | (defun timer--time (timer) | 52 | (defun timer--time (timer) |
| 53 | (list (timer--high-seconds timer) | 53 | (list (timer--high-seconds timer) |
| 54 | (timer--low-seconds timer) | 54 | (timer--low-seconds timer) |
| 55 | (timer--usecs timer))) | 55 | (timer--usecs timer) |
| 56 | (timer--psecs timer))) | ||
| 56 | 57 | ||
| 57 | (gv-define-simple-setter timer--time | 58 | (gv-define-simple-setter timer--time |
| 58 | (lambda (timer time) | 59 | (lambda (timer time) |
| 59 | (or (timerp timer) (error "Invalid timer")) | 60 | (or (timerp timer) (error "Invalid timer")) |
| 60 | (setf (timer--high-seconds timer) (pop time)) | 61 | (setf (timer--high-seconds timer) (pop time)) |
| 61 | (setf (timer--low-seconds timer) | 62 | (let ((low time) (usecs 0) (psecs 0)) |
| 62 | (if (consp time) (car time) time)) | 63 | (if (consp time) |
| 63 | (setf (timer--usecs timer) (or (and (consp time) (consp (cdr time)) | 64 | (progn |
| 64 | (cadr time)) | 65 | (setq low (pop time)) |
| 65 | 0)))) | 66 | (if time |
| 67 | (progn | ||
| 68 | (setq usecs (pop time)) | ||
| 69 | (if time | ||
| 70 | (setq psecs (car time))))))) | ||
| 71 | (setf (timer--low-seconds timer) low) | ||
| 72 | (setf (timer--usecs timer) usecs) | ||
| 73 | (setf (timer--psecs timer) psecs)))) | ||
| 66 | 74 | ||
| 67 | 75 | ||
| 68 | (defun timer-set-time (timer time &optional delta) | 76 | (defun timer-set-time (timer time &optional delta) |
| @@ -77,7 +85,7 @@ fire repeatedly that many seconds apart." | |||
| 77 | (defun timer-set-idle-time (timer secs &optional repeat) | 85 | (defun timer-set-idle-time (timer secs &optional repeat) |
| 78 | "Set the trigger idle time of TIMER to SECS. | 86 | "Set the trigger idle time of TIMER to SECS. |
| 79 | SECS may be an integer, floating point number, or the internal | 87 | SECS may be an integer, floating point number, or the internal |
| 80 | time format (HIGH LOW USECS) returned by, e.g., `current-idle-time'. | 88 | time format returned by, e.g., `current-idle-time'. |
| 81 | If optional third argument REPEAT is non-nil, make the timer | 89 | If optional third argument REPEAT is non-nil, make the timer |
| 82 | fire each time Emacs is idle for that many seconds." | 90 | fire each time Emacs is idle for that many seconds." |
| 83 | (if (consp secs) | 91 | (if (consp secs) |
| @@ -91,41 +99,46 @@ fire each time Emacs is idle for that many seconds." | |||
| 91 | "Yield the next value after TIME that is an integral multiple of SECS. | 99 | "Yield the next value after TIME that is an integral multiple of SECS. |
| 92 | More precisely, the next value, after TIME, that is an integral multiple | 100 | More precisely, the next value, after TIME, that is an integral multiple |
| 93 | of SECS seconds since the epoch. SECS may be a fraction." | 101 | of SECS seconds since the epoch. SECS may be a fraction." |
| 94 | (let ((time-base (ash 1 16))) | 102 | (let* ((trillion 1e12) |
| 95 | ;; Use floating point, taking care to not lose precision. | 103 | (time-sec (+ (nth 1 time) |
| 96 | (let* ((float-time-base (float time-base)) | 104 | (* 65536.0 (nth 0 time)))) |
| 97 | (million 1000000.0) | 105 | (delta-sec (mod (- time-sec) secs)) |
| 98 | (time-usec (+ (* million | 106 | (next-sec (+ time-sec (ffloor delta-sec))) |
| 99 | (+ (* float-time-base (nth 0 time)) | 107 | (next-sec-psec (ffloor (* trillion (mod delta-sec 1)))) |
| 100 | (nth 1 time))) | 108 | (sub-time-psec (+ (or (nth 3 time) 0) |
| 101 | (nth 2 time))) | 109 | (* 1e6 (nth 2 time)))) |
| 102 | (secs-usec (* million secs)) | 110 | (psec-diff (- sub-time-psec next-sec-psec))) |
| 103 | (mod-usec (mod time-usec secs-usec)) | 111 | (if (and (<= next-sec time-sec) (< 0 psec-diff)) |
| 104 | (next-usec (+ (- time-usec mod-usec) secs-usec)) | 112 | (setq next-sec-psec (+ sub-time-psec |
| 105 | (time-base-million (* float-time-base million))) | 113 | (mod (- psec-diff) (* trillion secs))))) |
| 106 | (list (floor next-usec time-base-million) | 114 | (setq next-sec (+ next-sec (floor next-sec-psec trillion))) |
| 107 | (floor (mod next-usec time-base-million) million) | 115 | (setq next-sec-psec (mod next-sec-psec trillion)) |
| 108 | (floor (mod next-usec million)))))) | 116 | (list (floor next-sec 65536) |
| 109 | 117 | (floor (mod next-sec 65536)) | |
| 110 | (defun timer-relative-time (time secs &optional usecs) | 118 | (floor next-sec-psec 1000000) |
| 111 | "Advance TIME by SECS seconds and optionally USECS microseconds. | 119 | (floor (mod next-sec-psec 1000000))))) |
| 112 | SECS may be either an integer or a floating point number." | 120 | |
| 121 | (defun timer-relative-time (time secs &optional usecs psecs) | ||
| 122 | "Advance TIME by SECS seconds and optionally USECS nanoseconds | ||
| 123 | and PSECS picoseconds. SECS may be either an integer or a | ||
| 124 | floating point number." | ||
| 113 | (let ((delta (if (floatp secs) | 125 | (let ((delta (if (floatp secs) |
| 114 | (seconds-to-time secs) | 126 | (seconds-to-time secs) |
| 115 | (list (floor secs 65536) (mod secs 65536))))) | 127 | (list (floor secs 65536) (mod secs 65536))))) |
| 116 | (if usecs | 128 | (if (or usecs psecs) |
| 117 | (setq delta (time-add delta (list 0 0 usecs)))) | 129 | (setq delta (time-add delta (list 0 0 (or usecs 0) (or psecs 0))))) |
| 118 | (time-add time delta))) | 130 | (time-add time delta))) |
| 119 | 131 | ||
| 120 | (defun timer--time-less-p (t1 t2) | 132 | (defun timer--time-less-p (t1 t2) |
| 121 | "Say whether time value T1 is less than time value T2." | 133 | "Say whether time value T1 is less than time value T2." |
| 122 | (time-less-p (timer--time t1) (timer--time t2))) | 134 | (time-less-p (timer--time t1) (timer--time t2))) |
| 123 | 135 | ||
| 124 | (defun timer-inc-time (timer secs &optional usecs) | 136 | (defun timer-inc-time (timer secs &optional usecs psecs) |
| 125 | "Increment the time set in TIMER by SECS seconds and USECS microseconds. | 137 | "Increment the time set in TIMER by SECS seconds, USECS nanoseconds, |
| 126 | SECS may be a fraction. If USECS is omitted, that means it is zero." | 138 | and PSECS picoseconds. SECS may be a fraction. If USECS or PSECS are |
| 139 | omitted, they are treated as zero." | ||
| 127 | (setf (timer--time timer) | 140 | (setf (timer--time timer) |
| 128 | (timer-relative-time (timer--time timer) secs usecs))) | 141 | (timer-relative-time (timer--time timer) secs usecs psecs))) |
| 129 | 142 | ||
| 130 | (defun timer-set-time-with-usecs (timer time usecs &optional delta) | 143 | (defun timer-set-time-with-usecs (timer time usecs &optional delta) |
| 131 | "Set the trigger time of TIMER to TIME plus USECS. | 144 | "Set the trigger time of TIMER to TIME plus USECS. |
| @@ -135,6 +148,7 @@ If optional fourth argument DELTA is a positive number, make the timer | |||
| 135 | fire repeatedly that many seconds apart." | 148 | fire repeatedly that many seconds apart." |
| 136 | (setf (timer--time timer) time) | 149 | (setf (timer--time timer) time) |
| 137 | (setf (timer--usecs timer) usecs) | 150 | (setf (timer--usecs timer) usecs) |
| 151 | (setf (timer--psecs timer) 0) | ||
| 138 | (setf (timer--repeat-delay timer) (and (numberp delta) (> delta 0) delta)) | 152 | (setf (timer--repeat-delay timer) (and (numberp delta) (> delta 0) delta)) |
| 139 | timer) | 153 | timer) |
| 140 | (make-obsolete 'timer-set-time-with-usecs | 154 | (make-obsolete 'timer-set-time-with-usecs |
| @@ -154,6 +168,7 @@ fire repeatedly that many seconds apart." | |||
| 154 | (integerp (timer--high-seconds timer)) | 168 | (integerp (timer--high-seconds timer)) |
| 155 | (integerp (timer--low-seconds timer)) | 169 | (integerp (timer--low-seconds timer)) |
| 156 | (integerp (timer--usecs timer)) | 170 | (integerp (timer--usecs timer)) |
| 171 | (integerp (timer--psecs timer)) | ||
| 157 | (timer--function timer)) | 172 | (timer--function timer)) |
| 158 | (let ((timers (if idle timer-idle-list timer-list)) | 173 | (let ((timers (if idle timer-idle-list timer-list)) |
| 159 | last) | 174 | last) |
| @@ -386,7 +401,7 @@ This function is for compatibility; see also `run-with-timer'." | |||
| 386 | "Perform an action the next time Emacs is idle for SECS seconds. | 401 | "Perform an action the next time Emacs is idle for SECS seconds. |
| 387 | The action is to call FUNCTION with arguments ARGS. | 402 | The action is to call FUNCTION with arguments ARGS. |
| 388 | SECS may be an integer, a floating point number, or the internal | 403 | SECS may be an integer, a floating point number, or the internal |
| 389 | time format (HIGH LOW USECS) returned by, e.g., `current-idle-time'. | 404 | time format returned by, e.g., `current-idle-time'. |
| 390 | If Emacs is currently idle, and has been idle for N seconds (N < SECS), | 405 | If Emacs is currently idle, and has been idle for N seconds (N < SECS), |
| 391 | then it will call FUNCTION in SECS - N seconds from now. | 406 | then it will call FUNCTION in SECS - N seconds from now. |
| 392 | 407 | ||
diff --git a/lisp/proced.el b/lisp/proced.el index 930f7d99f9e..78afcac9f50 100644 --- a/lisp/proced.el +++ b/lisp/proced.el | |||
| @@ -1170,14 +1170,16 @@ Return nil otherwise." | |||
| 1170 | (defun proced-time-lessp (t1 t2) | 1170 | (defun proced-time-lessp (t1 t2) |
| 1171 | "Return t if time value T1 is less than time value T2. | 1171 | "Return t if time value T1 is less than time value T2. |
| 1172 | Return `equal' if T1 equals T2. Return nil otherwise." | 1172 | Return `equal' if T1 equals T2. Return nil otherwise." |
| 1173 | (with-decoded-time-value ((high1 low1 micro1 t1) | 1173 | (with-decoded-time-value ((high1 low1 micro1 pico1 type1 t1) |
| 1174 | (high2 low2 micro2 t2)) | 1174 | (high2 low2 micro2 pico2 type2 t2)) |
| 1175 | (cond ((< high1 high2)) | 1175 | (cond ((< high1 high2)) |
| 1176 | ((< high2 high1) nil) | 1176 | ((< high2 high1) nil) |
| 1177 | ((< low1 low2)) | 1177 | ((< low1 low2)) |
| 1178 | ((< low2 low1) nil) | 1178 | ((< low2 low1) nil) |
| 1179 | ((< micro1 micro2)) | 1179 | ((< micro1 micro2)) |
| 1180 | ((< micro2 micro1) nil) | 1180 | ((< micro2 micro1) nil) |
| 1181 | ((< pico1 pico2)) | ||
| 1182 | ((< pico2 pico1) nil) | ||
| 1181 | (t 'equal)))) | 1183 | (t 'equal)))) |
| 1182 | 1184 | ||
| 1183 | ;;; Sorting | 1185 | ;;; Sorting |