1 ;;; run-at-time.el --- A non-buggy version of the run-at-time function
3 ;; Copyright (C) 1999, 2000, 2003 Free Software Foundation, Inc.
5 ;; Author: Katsumi Yamaoka <yamaoka@jpl.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 ;; XEmacs has a buggy version of run-at-time. This file defines a
27 ;; non-buggy version of the same.
32 (when (featurep 'xemacs)
35 (if (condition-case nil
37 (unless (or itimer-process itimer-timer)
38 (itimer-driver-start))
39 ;; Check whether there is a bug to which the difference of
40 ;; the present time and the time when the itimer driver was
41 ;; woken up is subtracted from the initial itimer value.
42 (let* ((inhibit-quit t)
43 (ctime (current-time))
44 (itimer-timer-last-wakeup
47 (setcar ctime (1- (car ctime)))))
49 (itimer (start-itimer "run-at-time" 'ignore 5)))
50 (sleep-for 0.1) ;; Accept the timeout interrupt.
52 (> (itimer-value itimer) 0)
53 (delete-itimer itimer))))
55 (lambda (time repeat function &rest args)
56 "Function emulating the function of the same name of Emacs.
57 TIME should be nil meaning now, or a number of seconds from now.
58 Return an itimer object which can be used in either `delete-itimer'
60 (apply #'start-itimer "run-at-time"
61 function (if time (max time 1e-9) 1e-9)
63 (lambda (time repeat function &rest args)
64 "Function emulating the function of the same name of Emacs.
65 It works correctly for TIME even if there is a bug in the XEmacs core.
66 TIME should be nil meaning now, or a number of seconds from now.
67 Return an itimer object which can be used in either `delete-itimer'
69 (let ((itimers (list nil)))
72 (apply #'start-itimer "fixed-run-at-time"
73 (lambda (itimers repeat function &rest args)
74 (let ((itimer (car itimers)))
79 (lambda (itimer repeat function &rest args)
80 (set-itimer-restart itimer repeat)
81 (set-itimer-function itimer function)
82 (set-itimer-function-arguments itimer args)
83 (apply function args)))
84 (set-itimer-function-arguments
86 (append (list itimer repeat function) args)))
89 (lambda (itimer function &rest args)
90 (delete-itimer itimer)
91 (apply function args)))
92 (set-itimer-function-arguments
94 (append (list itimer function) args)))))
95 1e-9 (if time (max time 1e-9) 1e-9)
96 nil t itimers repeat function args))))))))
98 (provide 'run-at-time)
100 ;;; run-at-time.el ends here