changeset 17452:40ddfad0bbd5

New function. (timer-max-repeats): New variable. (timer-event-handler): Avoid rerunning a timer many times if real time has "jumped" forward.
author Richard M. Stallman <rms@gnu.org>
date Mon, 14 Apr 1997 11:09:20 +0000
parents 0902196df62a
children 42bddf2eebad
files lisp/timer.el
diffstat 1 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/timer.el	Mon Apr 14 10:59:48 1997 +0000
+++ b/lisp/timer.el	Mon Apr 14 11:09:20 1997 +0000
@@ -248,6 +248,17 @@
 (defvar timer-event-last-1 nil)
 (defvar timer-event-last nil)
 
+(defvar timer-max-repeats 10
+  "*Maximum number of times to repeat a timer, if real time jumps.")
+
+(defun timer-until (timer time)
+  "Calculate number of seconds from when TIMER will run, until TIME.
+TIMER is a timer, and stands for the time when its next repeat is scheduled.
+TIME is a time-list.
+  (let ((high (- (car time) (aref timer 1)))
+	(low (- (nth 1 time) (aref timer 2))))
+    (+ low (* high 65536))))
+  
 (defun timer-event-handler (event)
   "Call the handler for the timer in the event EVENT."
   (interactive "e")
@@ -269,6 +280,15 @@
 	      (if (aref timer 7)
 		  (timer-activate-when-idle timer)
 		(timer-inc-time timer (aref timer 4) 0)
+		;; If real time has jumped forward,
+		;; perhaps because Emacs was suspended for a long time,
+		;; limit how many times things get repeated.
+		(if (and (numberp timer-max-repeats)
+			 (< 0 (timer-until timer (current-time))))
+		    (let ((repeats (/ (timer-until timer (current-time))
+				      (aref timer 4))))
+		      (if (> repeats timer-max-repeats)
+			  (timer-inc-time timer (* (aref timer 4) repeats)))))
 		(timer-activate timer))))
       (error "Bogus timer event"))))