diff options
Diffstat (limited to 'src/atimer.c')
| -rw-r--r-- | src/atimer.c | 51 |
1 files changed, 8 insertions, 43 deletions
diff --git a/src/atimer.c b/src/atimer.c index 5dbd807872a..d3b6c7d8fd3 100644 --- a/src/atimer.c +++ b/src/atimer.c | |||
| @@ -40,14 +40,6 @@ static struct atimer *stopped_atimers; | |||
| 40 | 40 | ||
| 41 | static struct atimer *atimers; | 41 | static struct atimer *atimers; |
| 42 | 42 | ||
| 43 | /* Non-zero means alarm signal handler has found ripe timers but | ||
| 44 | interrupt_input_blocked was non-zero. In this case, timer | ||
| 45 | functions are not called until the next UNBLOCK_INPUT because timer | ||
| 46 | functions are expected to call X, and X cannot be assumed to be | ||
| 47 | reentrant. */ | ||
| 48 | |||
| 49 | int pending_atimers; | ||
| 50 | |||
| 51 | /* Block/unblock SIGALRM. */ | 43 | /* Block/unblock SIGALRM. */ |
| 52 | 44 | ||
| 53 | static void | 45 | static void |
| @@ -341,16 +333,11 @@ schedule_atimer (struct atimer *t) | |||
| 341 | static void | 333 | static void |
| 342 | run_timers (void) | 334 | run_timers (void) |
| 343 | { | 335 | { |
| 344 | EMACS_TIME now; | 336 | EMACS_TIME now = current_emacs_time (); |
| 345 | 337 | ||
| 346 | while (atimers | 338 | while (atimers && EMACS_TIME_LE (atimers->expiration, now)) |
| 347 | && (pending_atimers = interrupt_input_blocked) == 0 | ||
| 348 | && (now = current_emacs_time (), | ||
| 349 | EMACS_TIME_LE (atimers->expiration, now))) | ||
| 350 | { | 339 | { |
| 351 | struct atimer *t; | 340 | struct atimer *t = atimers; |
| 352 | |||
| 353 | t = atimers; | ||
| 354 | atimers = atimers->next; | 341 | atimers = atimers->next; |
| 355 | t->fn (t); | 342 | t->fn (t); |
| 356 | 343 | ||
| @@ -366,16 +353,7 @@ run_timers (void) | |||
| 366 | } | 353 | } |
| 367 | } | 354 | } |
| 368 | 355 | ||
| 369 | if (! atimers) | 356 | set_alarm (); |
| 370 | pending_atimers = 0; | ||
| 371 | |||
| 372 | if (pending_atimers) | ||
| 373 | pending_signals = 1; | ||
| 374 | else | ||
| 375 | { | ||
| 376 | pending_signals = interrupt_input_pending; | ||
| 377 | set_alarm (); | ||
| 378 | } | ||
| 379 | } | 357 | } |
| 380 | 358 | ||
| 381 | 359 | ||
| @@ -385,23 +363,16 @@ run_timers (void) | |||
| 385 | static void | 363 | static void |
| 386 | handle_alarm_signal (int sig) | 364 | handle_alarm_signal (int sig) |
| 387 | { | 365 | { |
| 388 | pending_atimers = 1; | ||
| 389 | pending_signals = 1; | 366 | pending_signals = 1; |
| 390 | } | 367 | } |
| 391 | 368 | ||
| 392 | static void | ||
| 393 | deliver_alarm_signal (int sig) | ||
| 394 | { | ||
| 395 | handle_on_main_thread (sig, handle_alarm_signal); | ||
| 396 | } | ||
| 397 | |||
| 398 | 369 | ||
| 399 | /* Call alarm signal handler for pending timers. */ | 370 | /* Do pending timers. */ |
| 400 | 371 | ||
| 401 | void | 372 | void |
| 402 | do_pending_atimers (void) | 373 | do_pending_atimers (void) |
| 403 | { | 374 | { |
| 404 | if (pending_atimers) | 375 | if (atimers) |
| 405 | { | 376 | { |
| 406 | block_atimers (); | 377 | block_atimers (); |
| 407 | run_timers (); | 378 | run_timers (); |
| @@ -417,12 +388,7 @@ void | |||
| 417 | turn_on_atimers (bool on) | 388 | turn_on_atimers (bool on) |
| 418 | { | 389 | { |
| 419 | if (on) | 390 | if (on) |
| 420 | { | 391 | set_alarm (); |
| 421 | struct sigaction action; | ||
| 422 | emacs_sigaction_init (&action, deliver_alarm_signal); | ||
| 423 | sigaction (SIGALRM, &action, 0); | ||
| 424 | set_alarm (); | ||
| 425 | } | ||
| 426 | else | 392 | else |
| 427 | alarm (0); | 393 | alarm (0); |
| 428 | } | 394 | } |
| @@ -433,8 +399,7 @@ init_atimer (void) | |||
| 433 | { | 399 | { |
| 434 | struct sigaction action; | 400 | struct sigaction action; |
| 435 | free_atimers = stopped_atimers = atimers = NULL; | 401 | free_atimers = stopped_atimers = atimers = NULL; |
| 436 | pending_atimers = 0; | ||
| 437 | /* pending_signals is initialized in init_keyboard.*/ | 402 | /* pending_signals is initialized in init_keyboard.*/ |
| 438 | emacs_sigaction_init (&action, deliver_alarm_signal); | 403 | emacs_sigaction_init (&action, handle_alarm_signal); |
| 439 | sigaction (SIGALRM, &action, 0); | 404 | sigaction (SIGALRM, &action, 0); |
| 440 | } | 405 | } |