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