comparison src/atimer.c @ 49600:23a1cea22d13

Trailing whitespace deleted.
author Juanma Barranquero <lekktu@gmail.com>
date Tue, 04 Feb 2003 14:56:31 +0000
parents 3b31607ebbe1
children 695cf19ef79e d7ddb3e565de
comparison
equal deleted inserted replaced
49599:5ade352e8d1c 49600:23a1cea22d13
130 switch (type) 130 switch (type)
131 { 131 {
132 case ATIMER_ABSOLUTE: 132 case ATIMER_ABSOLUTE:
133 t->expiration = time; 133 t->expiration = time;
134 break; 134 break;
135 135
136 case ATIMER_RELATIVE: 136 case ATIMER_RELATIVE:
137 EMACS_GET_TIME (t->expiration); 137 EMACS_GET_TIME (t->expiration);
138 EMACS_ADD_TIME (t->expiration, t->expiration, time); 138 EMACS_ADD_TIME (t->expiration, t->expiration, time);
139 break; 139 break;
140 140
141 case ATIMER_CONTINUOUS: 141 case ATIMER_CONTINUOUS:
142 EMACS_GET_TIME (t->expiration); 142 EMACS_GET_TIME (t->expiration);
143 EMACS_ADD_TIME (t->expiration, t->expiration, time); 143 EMACS_ADD_TIME (t->expiration, t->expiration, time);
144 t->interval = time; 144 t->interval = time;
145 break; 145 break;
149 schedule_atimer (t); 149 schedule_atimer (t);
150 UNBLOCK_ATIMERS; 150 UNBLOCK_ATIMERS;
151 151
152 /* Arrange for a SIGALRM at the time the next atimer is ripe. */ 152 /* Arrange for a SIGALRM at the time the next atimer is ripe. */
153 set_alarm (); 153 set_alarm ();
154 154
155 return t; 155 return t;
156 } 156 }
157 157
158 158
159 /* Cancel and free atimer TIMER. */ 159 /* Cancel and free atimer TIMER. */
161 void 161 void
162 cancel_atimer (timer) 162 cancel_atimer (timer)
163 struct atimer *timer; 163 struct atimer *timer;
164 { 164 {
165 int i; 165 int i;
166 166
167 BLOCK_ATIMERS; 167 BLOCK_ATIMERS;
168 168
169 for (i = 0; i < 2; ++i) 169 for (i = 0; i < 2; ++i)
170 { 170 {
171 struct atimer *t, *prev; 171 struct atimer *t, *prev;
172 struct atimer **list = i ? &stopped_atimers : &atimers; 172 struct atimer **list = i ? &stopped_atimers : &atimers;
173 173
174 /* See if TIMER is active or stopped. */ 174 /* See if TIMER is active or stopped. */
175 for (t = *list, prev = NULL; t && t != timer; prev = t, t = t->next) 175 for (t = *list, prev = NULL; t && t != timer; prev = t, t = t->next)
176 ; 176 ;
177 177
178 /* If it is, take it off the its list, and put in on the 178 /* If it is, take it off the its list, and put in on the
182 { 182 {
183 if (prev) 183 if (prev)
184 prev->next = t->next; 184 prev->next = t->next;
185 else 185 else
186 *list = t->next; 186 *list = t->next;
187 187
188 t->next = free_atimers; 188 t->next = free_atimers;
189 free_atimers = t; 189 free_atimers = t;
190 break; 190 break;
191 } 191 }
192 } 192 }
207 else if (list2 == NULL) 207 else if (list2 == NULL)
208 return list1; 208 return list1;
209 else 209 else
210 { 210 {
211 struct atimer *p; 211 struct atimer *p;
212 212
213 for (p = list1; p->next; p = p->next) 213 for (p = list1; p->next; p = p->next)
214 ; 214 ;
215 p->next = list2; 215 p->next = list2;
216 return list1; 216 return list1;
217 } 217 }
223 void 223 void
224 stop_other_atimers (t) 224 stop_other_atimers (t)
225 struct atimer *t; 225 struct atimer *t;
226 { 226 {
227 BLOCK_ATIMERS; 227 BLOCK_ATIMERS;
228 228
229 if (t) 229 if (t)
230 { 230 {
231 struct atimer *p, *prev; 231 struct atimer *p, *prev;
232 232
233 /* See if T is active. */ 233 /* See if T is active. */
234 for (p = atimers, prev = 0; p && p != t; p = p->next) 234 for (p = atimers, prev = 0; p && p != t; p = p->next)
235 ; 235 ;
236 236
237 if (p == t) 237 if (p == t)
244 } 244 }
245 else 245 else
246 /* T is not active. Let's handle this like T == 0. */ 246 /* T is not active. Let's handle this like T == 0. */
247 t = NULL; 247 t = NULL;
248 } 248 }
249 249
250 stopped_atimers = append_atimer_lists (atimers, stopped_atimers); 250 stopped_atimers = append_atimer_lists (atimers, stopped_atimers);
251 atimers = t; 251 atimers = t;
252 UNBLOCK_ATIMERS; 252 UNBLOCK_ATIMERS;
253 } 253 }
254 254
261 { 261 {
262 if (stopped_atimers) 262 if (stopped_atimers)
263 { 263 {
264 struct atimer *t = atimers; 264 struct atimer *t = atimers;
265 struct atimer *next; 265 struct atimer *next;
266 266
267 BLOCK_ATIMERS; 267 BLOCK_ATIMERS;
268 atimers = stopped_atimers; 268 atimers = stopped_atimers;
269 stopped_atimers = NULL; 269 stopped_atimers = NULL;
270 270
271 while (t) 271 while (t)
272 { 272 {
273 next = t->next; 273 next = t->next;
274 schedule_atimer (t); 274 schedule_atimer (t);
275 t = next; 275 t = next;
276 } 276 }
277 277
278 UNBLOCK_ATIMERS; 278 UNBLOCK_ATIMERS;
279 } 279 }
280 } 280 }
281 281
282 282
299 #if defined (USG) && !defined (POSIX_SIGNALS) 299 #if defined (USG) && !defined (POSIX_SIGNALS)
300 /* USG systems forget handlers when they are used; 300 /* USG systems forget handlers when they are used;
301 must reestablish each time. */ 301 must reestablish each time. */
302 signal (SIGALRM, alarm_signal_handler); 302 signal (SIGALRM, alarm_signal_handler);
303 #endif /* USG */ 303 #endif /* USG */
304 304
305 if (atimers) 305 if (atimers)
306 { 306 {
307 EMACS_TIME now, time; 307 EMACS_TIME now, time;
308 #ifdef HAVE_SETITIMER 308 #ifdef HAVE_SETITIMER
309 struct itimerval it; 309 struct itimerval it;
318 if (EMACS_TIME_LE (atimers->expiration, now)) 318 if (EMACS_TIME_LE (atimers->expiration, now))
319 { 319 {
320 EMACS_SET_SECS (time, 0); 320 EMACS_SET_SECS (time, 0);
321 EMACS_SET_USECS (time, 1000); 321 EMACS_SET_USECS (time, 1000);
322 } 322 }
323 323
324 bzero (&it, sizeof it); 324 bzero (&it, sizeof it);
325 it.it_value = time; 325 it.it_value = time;
326 setitimer (ITIMER_REAL, &it, 0); 326 setitimer (ITIMER_REAL, &it, 0);
327 #else /* not HAVE_SETITIMER */ 327 #else /* not HAVE_SETITIMER */
328 alarm (max (EMACS_SECS (time), 1)); 328 alarm (max (EMACS_SECS (time), 1));
348 /* Insert T in front of the atimer found, if any. */ 348 /* Insert T in front of the atimer found, if any. */
349 if (prev) 349 if (prev)
350 prev->next = t; 350 prev->next = t;
351 else 351 else
352 atimers = t; 352 atimers = t;
353 353
354 t->next = a; 354 t->next = a;
355 } 355 }
356 356
357 357
358 /* Signal handler for SIGALRM. SIGNO is the signal number, i.e. 358 /* Signal handler for SIGALRM. SIGNO is the signal number, i.e.
361 SIGTYPE 361 SIGTYPE
362 alarm_signal_handler (signo) 362 alarm_signal_handler (signo)
363 int signo; 363 int signo;
364 { 364 {
365 EMACS_TIME now; 365 EMACS_TIME now;
366 366
367 EMACS_GET_TIME (now); 367 EMACS_GET_TIME (now);
368 pending_atimers = 0; 368 pending_atimers = 0;
369 369
370 while (atimers 370 while (atimers
371 && (pending_atimers = interrupt_input_blocked) == 0 371 && (pending_atimers = interrupt_input_blocked) == 0
372 && EMACS_TIME_LE (atimers->expiration, now)) 372 && EMACS_TIME_LE (atimers->expiration, now))
373 { 373 {
374 struct atimer *t; 374 struct atimer *t;
375 375
376 t = atimers; 376 t = atimers;
377 atimers = atimers->next; 377 atimers = atimers->next;
378 t->fn (t); 378 t->fn (t);
379 379
380 if (t->type == ATIMER_CONTINUOUS) 380 if (t->type == ATIMER_CONTINUOUS)
381 { 381 {
382 EMACS_ADD_TIME (t->expiration, now, t->interval); 382 EMACS_ADD_TIME (t->expiration, now, t->interval);
383 schedule_atimer (t); 383 schedule_atimer (t);
384 } 384 }
385 else 385 else
386 { 386 {
387 t->next = free_atimers; 387 t->next = free_atimers;
388 free_atimers = t; 388 free_atimers = t;
389 } 389 }
390 390
391 EMACS_GET_TIME (now); 391 EMACS_GET_TIME (now);
392 } 392 }
393 393
394 set_alarm (); 394 set_alarm ();
395 } 395 }
396 396
397 397
398 /* Call alarm_signal_handler for pending timers. */ 398 /* Call alarm_signal_handler for pending timers. */