Mercurial > emacs
annotate src/atimer.c @ 104881:98356e8ba345
(smerge-remove-props, smerge-refine):
Use with-silent-modifications (bug#4342).
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Tue, 08 Sep 2009 19:47:07 +0000 |
parents | 2380af35be5c |
children | 68dd71358159 |
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, |
100951 | 3 2006, 2007, 2008, 2009 Free Software Foundation, Inc. |
27433 | 4 |
5 This file is part of GNU Emacs. | |
6 | |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93894
diff
changeset
|
7 GNU Emacs is free software: you can redistribute it and/or modify |
27433 | 8 it under the terms of the GNU General Public License as published by |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93894
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93894
diff
changeset
|
10 (at your option) any later version. |
27433 | 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 | |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93894
diff
changeset
|
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
27433 | 19 |
20 #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
|
21 #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
|
22 #include <stdio.h> |
27433 | 23 #include <lisp.h> |
24 #include <syssignal.h> | |
25 #include <systime.h> | |
26 #include <blockinput.h> | |
27 #include <atimer.h> | |
28 | |
29 #ifdef HAVE_UNISTD_H | |
30 #include <unistd.h> | |
31 #endif | |
32 | |
33 #ifdef HAVE_SYS_TIME_H | |
34 #include <sys/time.h> | |
35 #endif | |
36 | |
37 /* Free-list of atimer structures. */ | |
38 | |
39 static struct atimer *free_atimers; | |
40 | |
27670
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
41 /* 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
|
42 lock_atimer. */ |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
43 |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
44 static struct atimer *stopped_atimers; |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
45 |
27433 | 46 /* List of active atimers, sorted by expiration time. The timer that |
47 will become ripe next is always at the front of this list. */ | |
48 | |
49 static struct atimer *atimers; | |
50 | |
51 /* Non-zero means alarm_signal_handler has found ripe timers but | |
52 interrupt_input_blocked was non-zero. In this case, timer | |
53 functions are not called until the next UNBLOCK_INPUT because timer | |
54 functions are expected to call X, and X cannot be assumed to be | |
55 reentrant. */ | |
56 | |
57 int pending_atimers; | |
58 | |
39667 | 59 /* Block/unblock SIGALRM. */ |
27433 | 60 |
61 #define BLOCK_ATIMERS sigblock (sigmask (SIGALRM)) | |
62 #define UNBLOCK_ATIMERS sigunblock (sigmask (SIGALRM)) | |
63 | |
64 /* Function prototypes. */ | |
65 | |
66 static void set_alarm P_ ((void)); | |
67 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
|
68 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
|
69 struct atimer *)); |
29672
2722b6b5400d
(alarm_signal_handler): Add forward declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
28119
diff
changeset
|
70 SIGTYPE alarm_signal_handler (); |
27433 | 71 |
72 | |
73 /* Start a new atimer of type TYPE. TIME specifies when the timer is | |
74 ripe. FN is the function to call when the timer fires. | |
75 CLIENT_DATA is stored in the client_data member of the atimer | |
76 structure returned and so made available to FN when it is called. | |
77 | |
78 If TYPE is ATIMER_ABSOLUTE, TIME is the absolute time at which the | |
79 timer fires. | |
80 | |
81 If TYPE is ATIMER_RELATIVE, the timer is ripe TIME s/us in the | |
82 future. | |
83 | |
84 In both cases, the timer is automatically freed after it has fired. | |
85 | |
86 If TYPE is ATIMER_CONTINUOUS, the timer fires every TIME s/us. | |
87 | |
88 Value is a pointer to the atimer started. It can be used in calls | |
89 to cancel_atimer; don't free it yourself. */ | |
90 | |
91 struct atimer * | |
92 start_atimer (type, time, fn, client_data) | |
93 enum atimer_type type; | |
94 EMACS_TIME time; | |
95 atimer_callback fn; | |
96 void *client_data; | |
97 { | |
98 struct atimer *t; | |
99 | |
100 /* Round TIME up to the next full second if we don't have | |
101 itimers. */ | |
102 #ifndef HAVE_SETITIMER | |
103 if (EMACS_USECS (time) != 0) | |
104 { | |
27452
7580a16f676c
(start_atimer) [!HAVE_SETITIMER]: Use EMACS_SET_SECS
Eli Zaretskii <eliz@gnu.org>
parents:
27433
diff
changeset
|
105 EMACS_SET_USECS (time, 0); |
7580a16f676c
(start_atimer) [!HAVE_SETITIMER]: Use EMACS_SET_SECS
Eli Zaretskii <eliz@gnu.org>
parents:
27433
diff
changeset
|
106 EMACS_SET_SECS (time, EMACS_SECS (time) + 1); |
27433 | 107 } |
108 #endif /* not HAVE_SETITIMER */ | |
109 | |
110 /* Get an atimer structure from the free-list, or allocate | |
111 a new one. */ | |
112 if (free_atimers) | |
113 { | |
114 t = free_atimers; | |
115 free_atimers = t->next; | |
116 } | |
117 else | |
118 t = (struct atimer *) xmalloc (sizeof *t); | |
119 | |
120 /* Fill the atimer structure. */ | |
121 bzero (t, sizeof *t); | |
122 t->type = type; | |
123 t->fn = fn; | |
124 t->client_data = client_data; | |
125 | |
126 BLOCK_ATIMERS; | |
127 | |
128 /* Compute the timer's expiration time. */ | |
129 switch (type) | |
130 { | |
131 case ATIMER_ABSOLUTE: | |
132 t->expiration = time; | |
133 break; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
134 |
27433 | 135 case ATIMER_RELATIVE: |
136 EMACS_GET_TIME (t->expiration); | |
137 EMACS_ADD_TIME (t->expiration, t->expiration, time); | |
138 break; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
139 |
27433 | 140 case ATIMER_CONTINUOUS: |
141 EMACS_GET_TIME (t->expiration); | |
142 EMACS_ADD_TIME (t->expiration, t->expiration, time); | |
143 t->interval = time; | |
144 break; | |
145 } | |
146 | |
147 /* Insert the timer in the list of active atimers. */ | |
148 schedule_atimer (t); | |
149 UNBLOCK_ATIMERS; | |
150 | |
151 /* Arrange for a SIGALRM at the time the next atimer is ripe. */ | |
152 set_alarm (); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
153 |
27433 | 154 return t; |
155 } | |
156 | |
157 | |
158 /* Cancel and free atimer TIMER. */ | |
159 | |
160 void | |
161 cancel_atimer (timer) | |
162 struct atimer *timer; | |
163 { | |
27913
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
164 int i; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
165 |
27433 | 166 BLOCK_ATIMERS; |
167 | |
27913
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
168 for (i = 0; i < 2; ++i) |
27903
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
169 { |
27913
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
170 struct atimer *t, *prev; |
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
171 struct atimer **list = i ? &stopped_atimers : &atimers; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
172 |
27903
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
173 /* 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
|
174 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
|
175 ; |
27433 | 176 |
27913
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
177 /* 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
|
178 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
|
179 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
|
180 if (t) |
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
181 { |
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
182 if (prev) |
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
183 prev->next = t->next; |
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
184 else |
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
185 *list = t->next; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
186 |
27903
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
187 t->next = free_atimers; |
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
188 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
|
189 break; |
27903
cc3d4c12e03b
(cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents:
27734
diff
changeset
|
190 } |
27433 | 191 } |
192 | |
193 UNBLOCK_ATIMERS; | |
194 } | |
195 | |
196 | |
27913
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
197 /* 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
|
198 result list. */ |
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
199 |
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
200 static struct atimer * |
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
201 append_atimer_lists (list1, list2) |
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
202 struct atimer *list1, *list2; |
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
203 { |
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
204 if (list1 == NULL) |
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
205 return list2; |
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
206 else if (list2 == NULL) |
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
207 return list1; |
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
208 else |
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
209 { |
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
210 struct atimer *p; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
211 |
27913
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
212 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
|
213 ; |
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
214 p->next = list2; |
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
215 return list1; |
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
216 } |
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
217 } |
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 /* 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
|
221 |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
222 void |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
223 stop_other_atimers (t) |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
224 struct atimer *t; |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
225 { |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
226 BLOCK_ATIMERS; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
227 |
27670
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
228 if (t) |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
229 { |
27734
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
230 struct atimer *p, *prev; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
231 |
27734
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
232 /* 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
|
233 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
|
234 ; |
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
235 |
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
236 if (p == t) |
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 (prev) |
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
239 prev->next = t->next; |
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
240 else |
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
241 atimers = t->next; |
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
242 t->next = NULL; |
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
243 } |
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
244 else |
5c49b0be3b7b
(stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents:
27670
diff
changeset
|
245 /* 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
|
246 t = NULL; |
27670
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
247 } |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
248 |
27913
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
249 stopped_atimers = append_atimer_lists (atimers, stopped_atimers); |
27670
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
250 atimers = t; |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
251 UNBLOCK_ATIMERS; |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
252 } |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
253 |
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 /* 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
|
256 stop_other_atimers. */ |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
257 |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
258 void |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
259 run_all_atimers () |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
260 { |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
261 if (stopped_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 struct atimer *t = atimers; |
27913
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
264 struct atimer *next; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
265 |
27670
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
266 BLOCK_ATIMERS; |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
267 atimers = stopped_atimers; |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
268 stopped_atimers = NULL; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
269 |
27913
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
270 while (t) |
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
271 { |
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
272 next = t->next; |
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
273 schedule_atimer (t); |
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
274 t = next; |
81d5641c8b04
(start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents:
27903
diff
changeset
|
275 } |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
276 |
27670
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
277 UNBLOCK_ATIMERS; |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
278 } |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
279 } |
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 /* 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
|
283 |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
284 Lisp_Object |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
285 unwind_stop_other_atimers (dummy) |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
286 Lisp_Object dummy; |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
287 { |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
288 run_all_atimers (); |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
289 return Qnil; |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
290 } |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
291 |
cf2edc15eaa9
(stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
27452
diff
changeset
|
292 |
27433 | 293 /* Arrange for a SIGALRM to arrive when the next timer is ripe. */ |
294 | |
295 static void | |
296 set_alarm () | |
297 { | |
298 #if defined (USG) && !defined (POSIX_SIGNALS) | |
299 /* USG systems forget handlers when they are used; | |
300 must reestablish each time. */ | |
301 signal (SIGALRM, alarm_signal_handler); | |
302 #endif /* USG */ | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
303 |
27433 | 304 if (atimers) |
305 { | |
306 EMACS_TIME now, time; | |
307 #ifdef HAVE_SETITIMER | |
308 struct itimerval it; | |
309 #endif | |
310 | |
311 /* Determine s/us till the next timer is ripe. */ | |
312 EMACS_GET_TIME (now); | |
313 EMACS_SUB_TIME (time, atimers->expiration, now); | |
314 | |
315 #ifdef HAVE_SETITIMER | |
316 /* Don't set the interval to 0; this disables the timer. */ | |
317 if (EMACS_TIME_LE (atimers->expiration, now)) | |
318 { | |
319 EMACS_SET_SECS (time, 0); | |
320 EMACS_SET_USECS (time, 1000); | |
321 } | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
322 |
27433 | 323 bzero (&it, sizeof it); |
324 it.it_value = time; | |
325 setitimer (ITIMER_REAL, &it, 0); | |
326 #else /* not HAVE_SETITIMER */ | |
327 alarm (max (EMACS_SECS (time), 1)); | |
328 #endif /* not HAVE_SETITIMER */ | |
329 } | |
330 } | |
331 | |
332 | |
333 /* Insert timer T into the list of active atimers `atimers', keeping | |
334 the list sorted by expiration time. T must not be in this list | |
335 already. */ | |
336 | |
337 static void | |
338 schedule_atimer (t) | |
339 struct atimer *t; | |
340 { | |
341 struct atimer *a = atimers, *prev = NULL; | |
342 | |
343 /* Look for the first atimer that is ripe after T. */ | |
344 while (a && EMACS_TIME_GT (t->expiration, a->expiration)) | |
345 prev = a, a = a->next; | |
346 | |
347 /* Insert T in front of the atimer found, if any. */ | |
348 if (prev) | |
349 prev->next = t; | |
350 else | |
351 atimers = t; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
352 |
27433 | 353 t->next = a; |
354 } | |
355 | |
93894
065fbf6b6fd0
(alarm_signal_handler): Call run_timers if not SYNC_INPUT.
Jan Djärv <jan.h.d@swipnet.se>
parents:
79759
diff
changeset
|
356 static void |
065fbf6b6fd0
(alarm_signal_handler): Call run_timers if not SYNC_INPUT.
Jan Djärv <jan.h.d@swipnet.se>
parents:
79759
diff
changeset
|
357 run_timers () |
27433 | 358 { |
359 EMACS_TIME now; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
360 |
27433 | 361 EMACS_GET_TIME (now); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
362 |
27433 | 363 while (atimers |
364 && (pending_atimers = interrupt_input_blocked) == 0 | |
365 && EMACS_TIME_LE (atimers->expiration, now)) | |
366 { | |
367 struct atimer *t; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
368 |
27433 | 369 t = atimers; |
370 atimers = atimers->next; | |
371 t->fn (t); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
372 |
27433 | 373 if (t->type == ATIMER_CONTINUOUS) |
374 { | |
375 EMACS_ADD_TIME (t->expiration, now, t->interval); | |
376 schedule_atimer (t); | |
377 } | |
378 else | |
379 { | |
380 t->next = free_atimers; | |
381 free_atimers = t; | |
382 } | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
383 |
27433 | 384 EMACS_GET_TIME (now); |
385 } | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39687
diff
changeset
|
386 |
101847
b8c8f770feb3
(run_timers): Update pending_atimers.
Chong Yidong <cyd@stupidchicken.com>
parents:
101675
diff
changeset
|
387 if (! atimers) |
b8c8f770feb3
(run_timers): Update pending_atimers.
Chong Yidong <cyd@stupidchicken.com>
parents:
101675
diff
changeset
|
388 pending_atimers = 0; |
b8c8f770feb3
(run_timers): Update pending_atimers.
Chong Yidong <cyd@stupidchicken.com>
parents:
101675
diff
changeset
|
389 |
101675
9c67a492eb59
* atimer.c (run_timers, alarm_signal_handler):
Juanma Barranquero <lekktu@gmail.com>
parents:
101647
diff
changeset
|
390 #ifdef SYNC_INPUT |
101647
a802fb91191e
(run_timers, alarm_signal_handler): Update pending_signals.
Chong Yidong <cyd@stupidchicken.com>
parents:
100951
diff
changeset
|
391 if (pending_atimers) |
a802fb91191e
(run_timers, alarm_signal_handler): Update pending_signals.
Chong Yidong <cyd@stupidchicken.com>
parents:
100951
diff
changeset
|
392 pending_signals = 1; |
a802fb91191e
(run_timers, alarm_signal_handler): Update pending_signals.
Chong Yidong <cyd@stupidchicken.com>
parents:
100951
diff
changeset
|
393 else |
a802fb91191e
(run_timers, alarm_signal_handler): Update pending_signals.
Chong Yidong <cyd@stupidchicken.com>
parents:
100951
diff
changeset
|
394 { |
a802fb91191e
(run_timers, alarm_signal_handler): Update pending_signals.
Chong Yidong <cyd@stupidchicken.com>
parents:
100951
diff
changeset
|
395 pending_signals = interrupt_input_pending; |
a802fb91191e
(run_timers, alarm_signal_handler): Update pending_signals.
Chong Yidong <cyd@stupidchicken.com>
parents:
100951
diff
changeset
|
396 set_alarm (); |
a802fb91191e
(run_timers, alarm_signal_handler): Update pending_signals.
Chong Yidong <cyd@stupidchicken.com>
parents:
100951
diff
changeset
|
397 } |
101675
9c67a492eb59
* atimer.c (run_timers, alarm_signal_handler):
Juanma Barranquero <lekktu@gmail.com>
parents:
101647
diff
changeset
|
398 #else |
9c67a492eb59
* atimer.c (run_timers, alarm_signal_handler):
Juanma Barranquero <lekktu@gmail.com>
parents:
101647
diff
changeset
|
399 if (! pending_atimers) |
9c67a492eb59
* atimer.c (run_timers, alarm_signal_handler):
Juanma Barranquero <lekktu@gmail.com>
parents:
101647
diff
changeset
|
400 set_alarm (); |
9c67a492eb59
* atimer.c (run_timers, alarm_signal_handler):
Juanma Barranquero <lekktu@gmail.com>
parents:
101647
diff
changeset
|
401 #endif |
27433 | 402 } |
403 | |
404 | |
93894
065fbf6b6fd0
(alarm_signal_handler): Call run_timers if not SYNC_INPUT.
Jan Djärv <jan.h.d@swipnet.se>
parents:
79759
diff
changeset
|
405 /* Signal handler for SIGALRM. SIGNO is the signal number, i.e. |
065fbf6b6fd0
(alarm_signal_handler): Call run_timers if not SYNC_INPUT.
Jan Djärv <jan.h.d@swipnet.se>
parents:
79759
diff
changeset
|
406 SIGALRM. */ |
065fbf6b6fd0
(alarm_signal_handler): Call run_timers if not SYNC_INPUT.
Jan Djärv <jan.h.d@swipnet.se>
parents:
79759
diff
changeset
|
407 |
065fbf6b6fd0
(alarm_signal_handler): Call run_timers if not SYNC_INPUT.
Jan Djärv <jan.h.d@swipnet.se>
parents:
79759
diff
changeset
|
408 SIGTYPE |
065fbf6b6fd0
(alarm_signal_handler): Call run_timers if not SYNC_INPUT.
Jan Djärv <jan.h.d@swipnet.se>
parents:
79759
diff
changeset
|
409 alarm_signal_handler (signo) |
065fbf6b6fd0
(alarm_signal_handler): Call run_timers if not SYNC_INPUT.
Jan Djärv <jan.h.d@swipnet.se>
parents:
79759
diff
changeset
|
410 int signo; |
065fbf6b6fd0
(alarm_signal_handler): Call run_timers if not SYNC_INPUT.
Jan Djärv <jan.h.d@swipnet.se>
parents:
79759
diff
changeset
|
411 { |
065fbf6b6fd0
(alarm_signal_handler): Call run_timers if not SYNC_INPUT.
Jan Djärv <jan.h.d@swipnet.se>
parents:
79759
diff
changeset
|
412 pending_atimers = 1; |
101675
9c67a492eb59
* atimer.c (run_timers, alarm_signal_handler):
Juanma Barranquero <lekktu@gmail.com>
parents:
101647
diff
changeset
|
413 #ifdef SYNC_INPUT |
101647
a802fb91191e
(run_timers, alarm_signal_handler): Update pending_signals.
Chong Yidong <cyd@stupidchicken.com>
parents:
100951
diff
changeset
|
414 pending_signals = 1; |
101675
9c67a492eb59
* atimer.c (run_timers, alarm_signal_handler):
Juanma Barranquero <lekktu@gmail.com>
parents:
101647
diff
changeset
|
415 #else |
93894
065fbf6b6fd0
(alarm_signal_handler): Call run_timers if not SYNC_INPUT.
Jan Djärv <jan.h.d@swipnet.se>
parents:
79759
diff
changeset
|
416 run_timers (); |
065fbf6b6fd0
(alarm_signal_handler): Call run_timers if not SYNC_INPUT.
Jan Djärv <jan.h.d@swipnet.se>
parents:
79759
diff
changeset
|
417 #endif |
065fbf6b6fd0
(alarm_signal_handler): Call run_timers if not SYNC_INPUT.
Jan Djärv <jan.h.d@swipnet.se>
parents:
79759
diff
changeset
|
418 } |
065fbf6b6fd0
(alarm_signal_handler): Call run_timers if not SYNC_INPUT.
Jan Djärv <jan.h.d@swipnet.se>
parents:
79759
diff
changeset
|
419 |
065fbf6b6fd0
(alarm_signal_handler): Call run_timers if not SYNC_INPUT.
Jan Djärv <jan.h.d@swipnet.se>
parents:
79759
diff
changeset
|
420 |
27433 | 421 /* Call alarm_signal_handler for pending timers. */ |
422 | |
423 void | |
424 do_pending_atimers () | |
425 { | |
426 if (pending_atimers) | |
427 { | |
428 BLOCK_ATIMERS; | |
93894
065fbf6b6fd0
(alarm_signal_handler): Call run_timers if not SYNC_INPUT.
Jan Djärv <jan.h.d@swipnet.se>
parents:
79759
diff
changeset
|
429 run_timers (); |
27433 | 430 UNBLOCK_ATIMERS; |
431 } | |
432 } | |
433 | |
434 | |
435 /* Turn alarms on/off. This seems to be temporarily necessary on | |
436 some systems like HPUX (see process.c). */ | |
437 | |
438 void | |
439 turn_on_atimers (on) | |
440 int on; | |
441 { | |
442 if (on) | |
443 { | |
444 signal (SIGALRM, alarm_signal_handler); | |
445 set_alarm (); | |
446 } | |
447 else | |
448 alarm (0); | |
449 } | |
450 | |
451 | |
452 void | |
453 init_atimer () | |
454 { | |
103104
2380af35be5c
(init_atimer): Also clear stopped_atimers.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
101847
diff
changeset
|
455 free_atimers = stopped_atimers = atimers = NULL; |
27433 | 456 pending_atimers = 0; |
101647
a802fb91191e
(run_timers, alarm_signal_handler): Update pending_signals.
Chong Yidong <cyd@stupidchicken.com>
parents:
100951
diff
changeset
|
457 /* pending_signals is initialized in init_keyboard.*/ |
27433 | 458 signal (SIGALRM, alarm_signal_handler); |
459 } | |
52401 | 460 |
461 /* arch-tag: e6308261-eec6-404b-89fb-6e5909518d70 | |
462 (do not change this comment) */ |