annotate src/atimer.c @ 29041:49e8918cab44

Fix file description. (log-view-mode-map): Unsatisfying fix for when cvs-mode-map is not available. (log-view-font-lock-keywords): Only use cvs-filename-face if present. (log-view-current-file): Only use cvs-pcl-cvs-dirchange-re if present.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sun, 21 May 2000 02:12:34 +0000
parents 98625ad8a015
children 2722b6b5400d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27433
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1 /* Asynchronous timers.
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2 Copyright (C) 2000 Free Software Foundation, Inc.
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
3
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
4 This file is part of GNU Emacs.
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8 the Free Software Foundation; either version 2, or (at your option)
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9 any later version.
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 GNU General Public License for more details.
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21 #include <config.h>
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22 #include <lisp.h>
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23 #include <signal.h>
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24 #include <syssignal.h>
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25 #include <systime.h>
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26 #include <blockinput.h>
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27 #include <atimer.h>
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 #include <stdio.h>
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 #ifdef HAVE_UNISTD_H
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31 #include <unistd.h>
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 #endif
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34 #ifdef HAVE_SYS_TIME_H
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 #include <sys/time.h>
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 #endif
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38 /* The ubiquitous min/max macros. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40 #define max(X, Y) ((X) > (Y) ? (X) : (Y))
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 #define min(X, Y) ((X) < (Y) ? (X) : (Y))
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 /* Free-list of atimer structures. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 static struct atimer *free_atimers;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46
27670
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
47 /* 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
48 lock_atimer. */
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
49
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
50 static struct atimer *stopped_atimers;
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
51
27433
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 /* List of active atimers, sorted by expiration time. The timer that
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 will become ripe next is always at the front of this list. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 static struct atimer *atimers;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 /* Non-zero means alarm_signal_handler has found ripe timers but
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 interrupt_input_blocked was non-zero. In this case, timer
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 functions are not called until the next UNBLOCK_INPUT because timer
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 functions are expected to call X, and X cannot be assumed to be
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 reentrant. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 int pending_atimers;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 /* Block/unblock SIGALRM.. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 #define BLOCK_ATIMERS sigblock (sigmask (SIGALRM))
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68 #define UNBLOCK_ATIMERS sigunblock (sigmask (SIGALRM))
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 /* Function prototypes. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 static void set_alarm P_ ((void));
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 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
74 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
75 struct atimer *));
27433
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 /* Start a new atimer of type TYPE. TIME specifies when the timer is
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 ripe. FN is the function to call when the timer fires.
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 CLIENT_DATA is stored in the client_data member of the atimer
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 structure returned and so made available to FN when it is called.
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 If TYPE is ATIMER_ABSOLUTE, TIME is the absolute time at which the
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 timer fires.
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 If TYPE is ATIMER_RELATIVE, the timer is ripe TIME s/us in the
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 future.
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 In both cases, the timer is automatically freed after it has fired.
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91 If TYPE is ATIMER_CONTINUOUS, the timer fires every TIME s/us.
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 Value is a pointer to the atimer started. It can be used in calls
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94 to cancel_atimer; don't free it yourself. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96 struct atimer *
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97 start_atimer (type, time, fn, client_data)
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 enum atimer_type type;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 EMACS_TIME time;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100 atimer_callback fn;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 void *client_data;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 {
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 struct atimer *t;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 /* Round TIME up to the next full second if we don't have
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106 itimers. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107 #ifndef HAVE_SETITIMER
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108 if (EMACS_USECS (time) != 0)
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109 {
27452
7580a16f676c (start_atimer) [!HAVE_SETITIMER]: Use EMACS_SET_SECS
Eli Zaretskii <eliz@gnu.org>
parents: 27433
diff changeset
110 EMACS_SET_USECS (time, 0);
7580a16f676c (start_atimer) [!HAVE_SETITIMER]: Use EMACS_SET_SECS
Eli Zaretskii <eliz@gnu.org>
parents: 27433
diff changeset
111 EMACS_SET_SECS (time, EMACS_SECS (time) + 1);
27433
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112 }
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113 #endif /* not HAVE_SETITIMER */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 /* Get an atimer structure from the free-list, or allocate
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116 a new one. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117 if (free_atimers)
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118 {
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 t = free_atimers;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120 free_atimers = t->next;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
121 }
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
122 else
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
123 t = (struct atimer *) xmalloc (sizeof *t);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 /* Fill the atimer structure. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126 bzero (t, sizeof *t);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
127 t->type = type;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128 t->fn = fn;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129 t->client_data = client_data;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131 BLOCK_ATIMERS;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133 /* Compute the timer's expiration time. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134 switch (type)
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135 {
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 case ATIMER_ABSOLUTE:
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 t->expiration = time;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138 break;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140 case ATIMER_RELATIVE:
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141 EMACS_GET_TIME (t->expiration);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142 EMACS_ADD_TIME (t->expiration, t->expiration, time);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 break;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145 case ATIMER_CONTINUOUS:
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 EMACS_GET_TIME (t->expiration);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 EMACS_ADD_TIME (t->expiration, t->expiration, time);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148 t->interval = time;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149 break;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150 }
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
152 /* Insert the timer in the list of active atimers. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 schedule_atimer (t);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154 UNBLOCK_ATIMERS;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 /* Arrange for a SIGALRM at the time the next atimer is ripe. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157 set_alarm ();
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 return t;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160 }
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163 /* Cancel and free atimer TIMER. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165 void
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 cancel_atimer (timer)
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 struct atimer *timer;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168 {
27913
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
169 int i;
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
170
27433
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 BLOCK_ATIMERS;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172
27913
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
173 for (i = 0; i < 2; ++i)
27903
cc3d4c12e03b (cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents: 27734
diff changeset
174 {
27913
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
175 struct atimer *t, *prev;
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
176 struct atimer **list = i ? &stopped_atimers : &atimers;
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
177
27903
cc3d4c12e03b (cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents: 27734
diff changeset
178 /* 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
179 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
180 ;
27433
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
181
27913
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
182 /* 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
183 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
184 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
185 if (t)
cc3d4c12e03b (cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents: 27734
diff changeset
186 {
cc3d4c12e03b (cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents: 27734
diff changeset
187 if (prev)
cc3d4c12e03b (cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents: 27734
diff changeset
188 prev->next = t->next;
cc3d4c12e03b (cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents: 27734
diff changeset
189 else
cc3d4c12e03b (cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents: 27734
diff changeset
190 *list = t->next;
cc3d4c12e03b (cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents: 27734
diff changeset
191
cc3d4c12e03b (cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents: 27734
diff changeset
192 t->next = free_atimers;
cc3d4c12e03b (cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents: 27734
diff changeset
193 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
194 break;
27903
cc3d4c12e03b (cancel_atimer): Handle canceling an atimer when
Gerd Moellmann <gerd@gnu.org>
parents: 27734
diff changeset
195 }
27433
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196 }
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
197
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
198 UNBLOCK_ATIMERS;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199 }
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
201
27913
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
202 /* 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
203 result list. */
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 static struct atimer *
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
206 append_atimer_lists (list1, list2)
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
207 struct atimer *list1, *list2;
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
208 {
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
209 if (list1 == NULL)
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
210 return list2;
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
211 else if (list2 == NULL)
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
212 return list1;
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
213 else
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 struct atimer *p;
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 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
218 ;
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
219 p->next = list2;
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
220 return list1;
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 }
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
223
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
224
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
225 /* 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
226
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
227 void
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
228 stop_other_atimers (t)
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
229 struct atimer *t;
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
230 {
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
231 BLOCK_ATIMERS;
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
232
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
233 if (t)
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
234 {
27734
5c49b0be3b7b (stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents: 27670
diff changeset
235 struct atimer *p, *prev;
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 /* See if T is active. */
5c49b0be3b7b (stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents: 27670
diff changeset
238 for (p = atimers, prev = 0; p && p != t; p = p->next)
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
5c49b0be3b7b (stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents: 27670
diff changeset
241 if (p == t)
5c49b0be3b7b (stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents: 27670
diff changeset
242 {
5c49b0be3b7b (stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents: 27670
diff changeset
243 if (prev)
5c49b0be3b7b (stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents: 27670
diff changeset
244 prev->next = t->next;
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 atimers = t->next;
5c49b0be3b7b (stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents: 27670
diff changeset
247 t->next = NULL;
5c49b0be3b7b (stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents: 27670
diff changeset
248 }
5c49b0be3b7b (stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents: 27670
diff changeset
249 else
5c49b0be3b7b (stop_other_atimers): Don't call cancel_atimer because
Gerd Moellmann <gerd@gnu.org>
parents: 27670
diff changeset
250 /* 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
251 t = NULL;
27670
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
27913
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
254 stopped_atimers = append_atimer_lists (atimers, stopped_atimers);
27670
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
255 atimers = t;
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
256 UNBLOCK_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
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 /* 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
261 stop_other_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 void
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
264 run_all_atimers ()
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
265 {
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
266 if (stopped_atimers)
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
267 {
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
268 struct atimer *t = atimers;
27913
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
269 struct atimer *next;
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
270
27670
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
271 BLOCK_ATIMERS;
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
272 atimers = stopped_atimers;
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
273 stopped_atimers = NULL;
27913
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
274
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
275 while (t)
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
276 {
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
277 next = t->next;
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
278 schedule_atimer (t);
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
279 t = next;
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
280 }
81d5641c8b04 (start_atimer): Don't abort when timers are stopped.
Gerd Moellmann <gerd@gnu.org>
parents: 27903
diff changeset
281
27670
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
282 UNBLOCK_ATIMERS;
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 }
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
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
287 /* 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
288
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
289 Lisp_Object
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
290 unwind_stop_other_atimers (dummy)
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
291 Lisp_Object dummy;
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 run_all_atimers ();
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
294 return Qnil;
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
295 }
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
296
cf2edc15eaa9 (stopped_atimers): New variable.
Gerd Moellmann <gerd@gnu.org>
parents: 27452
diff changeset
297
27433
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
298 /* Arrange for a SIGALRM to arrive when the next timer is ripe. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
299
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
300 static void
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
301 set_alarm ()
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
302 {
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
303 #if defined (USG) && !defined (POSIX_SIGNALS)
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
304 /* USG systems forget handlers when they are used;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
305 must reestablish each time. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
306 signal (SIGALRM, alarm_signal_handler);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
307 #endif /* USG */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
308
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
309 if (atimers)
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
310 {
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
311 EMACS_TIME now, time;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
312 #ifdef HAVE_SETITIMER
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
313 struct itimerval it;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
314 #endif
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
315
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
316 /* Determine s/us till the next timer is ripe. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
317 EMACS_GET_TIME (now);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
318 EMACS_SUB_TIME (time, atimers->expiration, now);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
319
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
320 #ifdef HAVE_SETITIMER
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
321 /* Don't set the interval to 0; this disables the timer. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
322 if (EMACS_TIME_LE (atimers->expiration, now))
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
323 {
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
324 EMACS_SET_SECS (time, 0);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
325 EMACS_SET_USECS (time, 1000);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
326 }
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
327
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
328 bzero (&it, sizeof it);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
329 it.it_value = time;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
330 setitimer (ITIMER_REAL, &it, 0);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
331 #else /* not HAVE_SETITIMER */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
332 alarm (max (EMACS_SECS (time), 1));
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
333 #endif /* not HAVE_SETITIMER */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
334 }
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
335 }
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
336
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
337
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
338 /* Insert timer T into the list of active atimers `atimers', keeping
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
339 the list sorted by expiration time. T must not be in this list
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
340 already. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
341
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
342 static void
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
343 schedule_atimer (t)
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
344 struct atimer *t;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
345 {
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
346 struct atimer *a = atimers, *prev = NULL;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
347
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
348 /* Look for the first atimer that is ripe after T. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
349 while (a && EMACS_TIME_GT (t->expiration, a->expiration))
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
350 prev = a, a = a->next;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
351
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
352 /* Insert T in front of the atimer found, if any. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
353 if (prev)
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
354 prev->next = t;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
355 else
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
356 atimers = t;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
357
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
358 t->next = a;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
359 }
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
360
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
361
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
362 /* Signal handler for SIGALRM. SIGNO is the signal number, i.e.
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
363 SIGALRM. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
364
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
365 SIGTYPE
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
366 alarm_signal_handler (signo)
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
367 int signo;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
368 {
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
369 EMACS_TIME now;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
370
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
371 EMACS_GET_TIME (now);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
372 pending_atimers = 0;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
373
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
374 while (atimers
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
375 && (pending_atimers = interrupt_input_blocked) == 0
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
376 && EMACS_TIME_LE (atimers->expiration, now))
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
377 {
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
378 struct atimer *t;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
379
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
380 t = atimers;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
381 atimers = atimers->next;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
382 t->fn (t);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
383
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
384 if (t->type == ATIMER_CONTINUOUS)
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
385 {
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
386 EMACS_ADD_TIME (t->expiration, now, t->interval);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
387 schedule_atimer (t);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
388 }
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
389 else
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
390 {
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
391 t->next = free_atimers;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
392 free_atimers = t;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
393 }
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
394
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
395 EMACS_GET_TIME (now);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
396 }
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
397
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
398 #if defined (USG) && !defined (POSIX_SIGNALS)
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
399 /* USG systems forget handlers when they are used;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
400 must reestablish each time. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
401 signal (SIGALRM, alarm_signal_handler);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
402 #endif /* USG */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
403
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
404 set_alarm ();
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
405 }
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
406
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
407
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
408 /* Call alarm_signal_handler for pending timers. */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
409
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
410 void
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
411 do_pending_atimers ()
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
412 {
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
413 if (pending_atimers)
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
414 {
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
415 BLOCK_ATIMERS;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
416 alarm_signal_handler (SIGALRM);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
417 UNBLOCK_ATIMERS;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
418 }
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
419 }
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
420
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
421
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
422 /* Turn alarms on/off. This seems to be temporarily necessary on
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
423 some systems like HPUX (see process.c). */
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
424
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
425 void
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
426 turn_on_atimers (on)
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
427 int on;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
428 {
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
429 if (on)
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
430 {
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
431 signal (SIGALRM, alarm_signal_handler);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
432 set_alarm ();
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
433 }
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
434 else
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
435 alarm (0);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
436 }
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
437
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
438
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
439 void
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
440 init_atimer ()
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
441 {
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
442 free_atimers = atimers = NULL;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
443 pending_atimers = 0;
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
444 signal (SIGALRM, alarm_signal_handler);
87dcc6a2c31b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
445 }