Mercurial > emacs
annotate src/atimer.c @ 79759:fc2bcd2a8aad
Add 2008 to copyright years.
| author | Glenn Morris <rgm@gnu.org> |
|---|---|
| date | Tue, 08 Jan 2008 04:30:25 +0000 |
| parents | 922696f363b0 |
| children | 606f2d163a64 065fbf6b6fd0 |
| rev | line source |
|---|---|
| 27433 | 1 /* Asynchronous timers. |
|
75227
e90d04cd455a
Update copyright for years from Emacs 21 to present (mainly adding
Glenn Morris <rgm@gnu.org>
parents:
68651
diff
changeset
|
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, |
| 79759 | 3 2006, 2007, 2008 Free Software Foundation, Inc. |
| 27433 | 4 |
| 5 This file is part of GNU Emacs. | |
| 6 | |
| 7 GNU Emacs is free software; you can redistribute it and/or modify | |
| 8 it under the terms of the GNU General Public License as published by | |
|
78260
922696f363b0
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75227
diff
changeset
|
9 the Free Software Foundation; either version 3, or (at your option) |
| 27433 | 10 any later version. |
| 11 | |
| 12 GNU Emacs is distributed in the hope that it will be useful, | |
| 13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 GNU General Public License for more details. | |
| 16 | |
| 17 You should have received a copy of the GNU General Public License | |
| 18 along with GNU Emacs; see the file COPYING. If not, write to | |
| 64084 | 19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 Boston, MA 02110-1301, USA. */ | |
| 27433 | 21 |
| 22 #include <config.h> | |
|
53901
d85f8f2e71f7
Move include stdio.h to same place as in other files.
Jan Dj?rv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
23 #include <signal.h> |
|
d85f8f2e71f7
Move include stdio.h to same place as in other files.
Jan Dj?rv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
24 #include <stdio.h> |
| 27433 | 25 #include <lisp.h> |
| 26 #include <syssignal.h> | |
| 27 #include <systime.h> | |
| 28 #include <blockinput.h> | |
| 29 #include <atimer.h> | |
| 30 | |
| 31 #ifdef HAVE_UNISTD_H | |
| 32 #include <unistd.h> | |
| 33 #endif | |
| 34 | |
| 35 #ifdef HAVE_SYS_TIME_H | |
| 36 #include <sys/time.h> | |
| 37 #endif | |
| 38 | |
| 39 /* Free-list of atimer structures. */ | |
| 40 | |
| 41 static struct atimer *free_atimers; | |
| 42 | |
|
27670
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
43 /* List of currently not running timers due to a call to |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
44 lock_atimer. */ |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
45 |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
46 static struct atimer *stopped_atimers; |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
47 |
| 27433 | 48 /* List of active atimers, sorted by expiration time. The timer that |
| 49 will become ripe next is always at the front of this list. */ | |
| 50 | |
| 51 static struct atimer *atimers; | |
| 52 | |
| 53 /* Non-zero means alarm_signal_handler has found ripe timers but | |
| 54 interrupt_input_blocked was non-zero. In this case, timer | |
| 55 functions are not called until the next UNBLOCK_INPUT because timer | |
| 56 functions are expected to call X, and X cannot be assumed to be | |
| 57 reentrant. */ | |
| 58 | |
| 59 int pending_atimers; | |
| 60 | |
| 39667 | 61 /* Block/unblock SIGALRM. */ |
| 27433 | 62 |
| 63 #define BLOCK_ATIMERS sigblock (sigmask (SIGALRM)) | |
| 64 #define UNBLOCK_ATIMERS sigunblock (sigmask (SIGALRM)) | |
| 65 | |
| 66 /* Function prototypes. */ | |
| 67 | |
| 68 static void set_alarm P_ ((void)); | |
| 69 static void schedule_atimer P_ ((struct atimer *)); | |
|
27913
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
70 static struct atimer *append_atimer_lists P_ ((struct atimer *, |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
71 struct atimer *)); |
|
29672
2722b6b5400d
(alarm_signal_handler): Add forward declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
28119
diff
changeset
|
72 SIGTYPE alarm_signal_handler (); |
| 27433 | 73 |
| 74 | |
| 75 /* Start a new atimer of type TYPE. TIME specifies when the timer is | |
| 76 ripe. FN is the function to call when the timer fires. | |
| 77 CLIENT_DATA is stored in the client_data member of the atimer | |
| 78 structure returned and so made available to FN when it is called. | |
| 79 | |
| 80 If TYPE is ATIMER_ABSOLUTE, TIME is the absolute time at which the | |
| 81 timer fires. | |
| 82 | |
| 83 If TYPE is ATIMER_RELATIVE, the timer is ripe TIME s/us in the | |
| 84 future. | |
| 85 | |
| 86 In both cases, the timer is automatically freed after it has fired. | |
| 87 | |
| 88 If TYPE is ATIMER_CONTINUOUS, the timer fires every TIME s/us. | |
| 89 | |
| 90 Value is a pointer to the atimer started. It can be used in calls | |
| 91 to cancel_atimer; don't free it yourself. */ | |
| 92 | |
| 93 struct atimer * | |
| 94 start_atimer (type, time, fn, client_data) | |
| 95 enum atimer_type type; | |
| 96 EMACS_TIME time; | |
| 97 atimer_callback fn; | |
| 98 void *client_data; | |
| 99 { | |
| 100 struct atimer *t; | |
| 101 | |
| 102 /* Round TIME up to the next full second if we don't have | |
| 103 itimers. */ | |
| 104 #ifndef HAVE_SETITIMER | |
| 105 if (EMACS_USECS (time) != 0) | |
| 106 { | |
|
27452
7580a16f676c
(start_atimer) [!HAVE_SETITIMER]: Use EMACS_SET_SECS
Eli Zaretskii <eliz@gnu.org>
parents:
27433
diff
changeset
|
107 EMACS_SET_USECS (time, 0); |
|
7580a16f676c
(start_atimer) [!HAVE_SETITIMER]: Use EMACS_SET_SECS
Eli Zaretskii <eliz@gnu.org>
parents:
27433
diff
changeset
|
108 EMACS_SET_SECS (time, EMACS_SECS (time) + 1); |
| 27433 | 109 } |
| 110 #endif /* not HAVE_SETITIMER */ | |
| 111 | |
| 112 /* Get an atimer structure from the free-list, or allocate | |
| 113 a new one. */ | |
| 114 if (free_atimers) | |
| 115 { | |
| 116 t = free_atimers; | |
| 117 free_atimers = t->next; | |
| 118 } | |
| 119 else | |
| 120 t = (struct atimer *) xmalloc (sizeof *t); | |
| 121 | |
| 122 /* Fill the atimer structure. */ | |
| 123 bzero (t, sizeof *t); | |
| 124 t->type = type; | |
| 125 t->fn = fn; | |
| 126 t->client_data = client_data; | |
| 127 | |
| 128 BLOCK_ATIMERS; | |
| 129 | |
| 130 /* Compute the timer's expiration time. */ | |
| 131 switch (type) | |
| 132 { | |
| 133 case ATIMER_ABSOLUTE: | |
| 134 t->expiration = time; | |
| 135 break; | |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
136 |
| 27433 | 137 case ATIMER_RELATIVE: |
| 138 EMACS_GET_TIME (t->expiration); | |
| 139 EMACS_ADD_TIME (t->expiration, t->expiration, time); | |
| 140 break; | |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
141 |
| 27433 | 142 case ATIMER_CONTINUOUS: |
| 143 EMACS_GET_TIME (t->expiration); | |
| 144 EMACS_ADD_TIME (t->expiration, t->expiration, time); | |
| 145 t->interval = time; | |
| 146 break; | |
| 147 } | |
| 148 | |
| 149 /* Insert the timer in the list of active atimers. */ | |
| 150 schedule_atimer (t); | |
| 151 UNBLOCK_ATIMERS; | |
| 152 | |
| 153 /* Arrange for a SIGALRM at the time the next atimer is ripe. */ | |
| 154 set_alarm (); | |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
155 |
| 27433 | 156 return t; |
| 157 } | |
| 158 | |
| 159 | |
| 160 /* Cancel and free atimer TIMER. */ | |
| 161 | |
| 162 void | |
| 163 cancel_atimer (timer) | |
| 164 struct atimer *timer; | |
| 165 { | |
|
27913
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
166 int i; |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
167 |
| 27433 | 168 BLOCK_ATIMERS; |
| 169 | |
|
27913
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
170 for (i = 0; i < 2; ++i) |
|
27903
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
171 { |
|
27913
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
172 struct atimer *t, *prev; |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
173 struct atimer **list = i ? &stopped_atimers : &atimers; |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
174 |
|
27903
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
175 /* See if TIMER is active or stopped. */ |
|
28119
98625ad8a015
(cancel_atimer): Break out of the loop as soon as timer
Gerd Moellmann <gerd@gnu.org>
parents:
27913
diff
changeset
|
176 for (t = *list, prev = NULL; t && t != timer; prev = t, t = t->next) |
|
27903
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
177 ; |
| 27433 | 178 |
|
27913
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
179 /* If it is, take it off the its list, and put in on the |
|
27903
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
180 free-list. We don't bother to arrange for setting a |
|
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
181 different alarm time, since a too early one doesn't hurt. */ |
|
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
182 if (t) |
|
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
183 { |
|
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
184 if (prev) |
|
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
185 prev->next = t->next; |
|
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
186 else |
|
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
187 *list = t->next; |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
188 |
|
27903
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
189 t->next = free_atimers; |
|
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
190 free_atimers = t; |
|
28119
98625ad8a015
(cancel_atimer): Break out of the loop as soon as timer
Gerd Moellmann <gerd@gnu.org>
parents:
27913
diff
changeset
|
191 break; |
|
27903
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
192 } |
| 27433 | 193 } |
| 194 | |
| 195 UNBLOCK_ATIMERS; | |
| 196 } | |
| 197 | |
| 198 | |
|
27913
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
199 /* Append two lists of atimers LIST1 and LIST2 and return the |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
200 result list. */ |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
201 |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
202 static struct atimer * |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
203 append_atimer_lists (list1, list2) |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
204 struct atimer *list1, *list2; |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
205 { |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
206 if (list1 == NULL) |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
207 return list2; |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
208 else if (list2 == NULL) |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
209 return list1; |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
210 else |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
211 { |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
212 struct atimer *p; |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
213 |
|
27913
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
214 for (p = list1; p->next; p = p->next) |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
215 ; |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
216 p->next = list2; |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
217 return list1; |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
218 } |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
219 } |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
220 |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
221 |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
222 /* Stop all timers except timer T. T null means stop all timers. */ |
|
27670
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
223 |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
224 void |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
225 stop_other_atimers (t) |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
226 struct atimer *t; |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
227 { |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
228 BLOCK_ATIMERS; |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
229 |
|
27670
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
230 if (t) |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
231 { |
|
27734
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
232 struct atimer *p, *prev; |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
233 |
|
27734
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
234 /* See if T is active. */ |
|
67209
a0e182783583
(stop_other_atimers): Fix loop to correctly compute `prev'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64770
diff
changeset
|
235 for (p = atimers, prev = NULL; p && p != t; prev = p, p = p->next) |
|
27734
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
236 ; |
|
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
237 |
|
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
238 if (p == t) |
|
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
239 { |
|
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
240 if (prev) |
|
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
241 prev->next = t->next; |
|
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
242 else |
|
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
243 atimers = t->next; |
|
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
244 t->next = NULL; |
|
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
245 } |
|
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
246 else |
|
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
247 /* T is not active. Let's handle this like T == 0. */ |
|
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
248 t = NULL; |
|
27670
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
249 } |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
250 |
|
27913
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
251 stopped_atimers = append_atimer_lists (atimers, stopped_atimers); |
|
27670
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
252 atimers = t; |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
253 UNBLOCK_ATIMERS; |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
254 } |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
255 |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
256 |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
257 /* Run all timers again, if some have been stopped with a call to |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
258 stop_other_atimers. */ |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
259 |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
260 void |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
261 run_all_atimers () |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
262 { |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
263 if (stopped_atimers) |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
264 { |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
265 struct atimer *t = atimers; |
|
27913
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
266 struct atimer *next; |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
267 |
|
27670
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
268 BLOCK_ATIMERS; |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
269 atimers = stopped_atimers; |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
270 stopped_atimers = NULL; |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
271 |
|
27913
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
272 while (t) |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
273 { |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
274 next = t->next; |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
275 schedule_atimer (t); |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
276 t = next; |
|
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
277 } |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
278 |
|
27670
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
279 UNBLOCK_ATIMERS; |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
280 } |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
281 } |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
282 |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
283 |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
284 /* A version of run_all_timers suitable for a record_unwind_protect. */ |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
285 |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
286 Lisp_Object |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
287 unwind_stop_other_atimers (dummy) |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
288 Lisp_Object dummy; |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
289 { |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
290 run_all_atimers (); |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
291 return Qnil; |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
292 } |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
293 |
|
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
294 |
| 27433 | 295 /* Arrange for a SIGALRM to arrive when the next timer is ripe. */ |
| 296 | |
| 297 static void | |
| 298 set_alarm () | |
| 299 { | |
| 300 #if defined (USG) && !defined (POSIX_SIGNALS) | |
| 301 /* USG systems forget handlers when they are used; | |
| 302 must reestablish each time. */ | |
| 303 signal (SIGALRM, alarm_signal_handler); | |
| 304 #endif /* USG */ | |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
305 |
| 27433 | 306 if (atimers) |
| 307 { | |
| 308 EMACS_TIME now, time; | |
| 309 #ifdef HAVE_SETITIMER | |
| 310 struct itimerval it; | |
| 311 #endif | |
| 312 | |
| 313 /* Determine s/us till the next timer is ripe. */ | |
| 314 EMACS_GET_TIME (now); | |
| 315 EMACS_SUB_TIME (time, atimers->expiration, now); | |
| 316 | |
| 317 #ifdef HAVE_SETITIMER | |
| 318 /* Don't set the interval to 0; this disables the timer. */ | |
| 319 if (EMACS_TIME_LE (atimers->expiration, now)) | |
| 320 { | |
| 321 EMACS_SET_SECS (time, 0); | |
| 322 EMACS_SET_USECS (time, 1000); | |
| 323 } | |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
324 |
| 27433 | 325 bzero (&it, sizeof it); |
| 326 it.it_value = time; | |
| 327 setitimer (ITIMER_REAL, &it, 0); | |
| 328 #else /* not HAVE_SETITIMER */ | |
| 329 alarm (max (EMACS_SECS (time), 1)); | |
| 330 #endif /* not HAVE_SETITIMER */ | |
| 331 } | |
| 332 } | |
| 333 | |
| 334 | |
| 335 /* Insert timer T into the list of active atimers `atimers', keeping | |
| 336 the list sorted by expiration time. T must not be in this list | |
| 337 already. */ | |
| 338 | |
| 339 static void | |
| 340 schedule_atimer (t) | |
| 341 struct atimer *t; | |
| 342 { | |
| 343 struct atimer *a = atimers, *prev = NULL; | |
| 344 | |
| 345 /* Look for the first atimer that is ripe after T. */ | |
| 346 while (a && EMACS_TIME_GT (t->expiration, a->expiration)) | |
| 347 prev = a, a = a->next; | |
| 348 | |
| 349 /* Insert T in front of the atimer found, if any. */ | |
| 350 if (prev) | |
| 351 prev->next = t; | |
| 352 else | |
| 353 atimers = t; | |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
354 |
| 27433 | 355 t->next = a; |
| 356 } | |
| 357 | |
| 358 | |
| 359 /* Signal handler for SIGALRM. SIGNO is the signal number, i.e. | |
| 360 SIGALRM. */ | |
| 361 | |
| 362 SIGTYPE | |
| 363 alarm_signal_handler (signo) | |
| 364 int signo; | |
| 365 { | |
| 366 EMACS_TIME now; | |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
367 |
|
58986
59945307b86b
* syssignal.h: Declare main_thread.
Jan Dj?rv <jan.h.d@swipnet.se>
parents:
57812
diff
changeset
|
368 SIGNAL_THREAD_CHECK (signo); |
|
59945307b86b
* syssignal.h: Declare main_thread.
Jan Dj?rv <jan.h.d@swipnet.se>
parents:
57812
diff
changeset
|
369 |
| 27433 | 370 EMACS_GET_TIME (now); |
| 371 pending_atimers = 0; | |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
372 |
| 27433 | 373 while (atimers |
| 374 && (pending_atimers = interrupt_input_blocked) == 0 | |
| 375 && EMACS_TIME_LE (atimers->expiration, now)) | |
| 376 { | |
| 377 struct atimer *t; | |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
378 |
| 27433 | 379 t = atimers; |
| 380 atimers = atimers->next; | |
|
56477
59a86f6ee1fb
Fixes for Ctrl-G support on carbon, replacing old timeout based polling
Steven Tamm <steventamm@mac.com>
parents:
56135
diff
changeset
|
381 #ifndef MAC_OSX |
| 27433 | 382 t->fn (t); |
|
56477
59a86f6ee1fb
Fixes for Ctrl-G support on carbon, replacing old timeout based polling
Steven Tamm <steventamm@mac.com>
parents:
56135
diff
changeset
|
383 #endif |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
384 |
| 27433 | 385 if (t->type == ATIMER_CONTINUOUS) |
| 386 { | |
| 387 EMACS_ADD_TIME (t->expiration, now, t->interval); | |
| 388 schedule_atimer (t); | |
| 389 } | |
| 390 else | |
| 391 { | |
| 392 t->next = free_atimers; | |
| 393 free_atimers = t; | |
| 394 } | |
|
56477
59a86f6ee1fb
Fixes for Ctrl-G support on carbon, replacing old timeout based polling
Steven Tamm <steventamm@mac.com>
parents:
56135
diff
changeset
|
395 #ifdef MAC_OSX |
|
59a86f6ee1fb
Fixes for Ctrl-G support on carbon, replacing old timeout based polling
Steven Tamm <steventamm@mac.com>
parents:
56135
diff
changeset
|
396 /* Fix for Ctrl-G. Perhaps this should apply to all platforms. */ |
|
59a86f6ee1fb
Fixes for Ctrl-G support on carbon, replacing old timeout based polling
Steven Tamm <steventamm@mac.com>
parents:
56135
diff
changeset
|
397 t->fn (t); |
|
59a86f6ee1fb
Fixes for Ctrl-G support on carbon, replacing old timeout based polling
Steven Tamm <steventamm@mac.com>
parents:
56135
diff
changeset
|
398 #endif |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
399 |
| 27433 | 400 EMACS_GET_TIME (now); |
| 401 } | |
|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
402 |
|
57812
938845bec845
* atimer.c (alarm_signal_handler): Do not call set_alarm if
Jan Dj?rv <jan.h.d@swipnet.se>
parents:
56477
diff
changeset
|
403 if (! pending_atimers) |
|
938845bec845
* atimer.c (alarm_signal_handler): Do not call set_alarm if
Jan Dj?rv <jan.h.d@swipnet.se>
parents:
56477
diff
changeset
|
404 set_alarm (); |
| 27433 | 405 } |
| 406 | |
| 407 | |
| 408 /* Call alarm_signal_handler for pending timers. */ | |
| 409 | |
| 410 void | |
| 411 do_pending_atimers () | |
| 412 { | |
| 413 if (pending_atimers) | |
| 414 { | |
| 415 BLOCK_ATIMERS; | |
| 416 alarm_signal_handler (SIGALRM); | |
| 417 UNBLOCK_ATIMERS; | |
| 418 } | |
| 419 } | |
| 420 | |
| 421 | |
| 422 /* Turn alarms on/off. This seems to be temporarily necessary on | |
| 423 some systems like HPUX (see process.c). */ | |
| 424 | |
| 425 void | |
| 426 turn_on_atimers (on) | |
| 427 int on; | |
| 428 { | |
| 429 if (on) | |
| 430 { | |
| 431 signal (SIGALRM, alarm_signal_handler); | |
| 432 set_alarm (); | |
| 433 } | |
| 434 else | |
| 435 alarm (0); | |
| 436 } | |
| 437 | |
| 438 | |
| 439 void | |
| 440 init_atimer () | |
| 441 { | |
| 442 free_atimers = atimers = NULL; | |
| 443 pending_atimers = 0; | |
| 444 signal (SIGALRM, alarm_signal_handler); | |
| 445 } | |
| 52401 | 446 |
| 447 /* arch-tag: e6308261-eec6-404b-89fb-6e5909518d70 | |
| 448 (do not change this comment) */ |
