aboutsummaryrefslogtreecommitdiffstats
path: root/src/atimer.c
diff options
context:
space:
mode:
authorPaul Eggert2012-09-06 18:27:44 -0700
committerPaul Eggert2012-09-06 18:27:44 -0700
commit2fe282993cf9c84f5be424dc93d03f9705a7edd8 (patch)
tree229edb6fe29e66984b2992f3f9fa081cd7fe8920 /src/atimer.c
parent845ce106c0ab157e25416964330875ad6c24b699 (diff)
downloademacs-2fe282993cf9c84f5be424dc93d03f9705a7edd8.tar.gz
emacs-2fe282993cf9c84f5be424dc93d03f9705a7edd8.zip
Signal-handler cleanup.
Emacs's signal handlers were written in the old 4.2BSD style with sigblock and sigmask and so forth, and this led to some inefficiencies and confusion. Rewrite these to use pthread_sigmask etc. without copying signal sets around. Also, get rid of the confusing macros 'SIGNAL_THREAD_CHECK' and 'signal', and instead use functions that do not attempt to take over the system name space. This patch causes Emacs's text segment to shrink by 0.7% on my platform, Fedora 17 x86-64. * configure.ac (PTY_OPEN, PTY_TTY_NAME_SPRINTF): Adjust to syssignal.h changes. (SIGNAL_H_AB): Remove; no longer needed. * src/alloc.c, src/emacsgtkfixed.c, src/nsfns.m, src/widget.c, src/xmenu.c: Do not include <signal.h> or "syssignal.h", as these modules do not use signals. * src/atimer.c, src/callproc.c, src/data.c, src/dispnew.c, src/emacs.c: * src/floatfns.c, src/gtkutil.c, src/keyboard.c, src/process.c, src/sound.c: * src/sysdep.c, src/term.c, src/xterm.c: Do not include <signal.h>, as "syssignal.h" does that for us now. * src/atimer.c (sigmask_atimers): New function. (block_atimers, unblock_atimers): New functions, replacing the old macros BLOCK_ATIMERS and UNBLOCK_ATIMERS. All uses replaced. * src/conf_post.h [SIGNAL_H_AHB]: Do not include <signal.h>; no longer needed here. * src/emacs.c (main): Inspect existing signal handler with sigaction, so that there's no need to block and unblock SIGHUP. * src/sysdep.c (struct save_signal): New member 'action', replacing old member 'handler'. (save_signal_handlers, restore_signal_handlers): Use sigaction instead of 'signal' to save and restore. (get_set_sighandler, set_sighandler) [!WINDOWSNT]: New function. All users of 'signal' modified to use set_sighandler if they're writeonly, and to use sys_signal if they're read+write. (emacs_sigaction_init, forwarded_signal): New functions. (sys_signal): Remove. All uses replaced by calls to sigaction and emacs_sigaction_init, or by direct calls to 'signal'. (sys_sigmask) [!__GNUC__]: Remove; no longer needed. (sys_sigblock, sys_sigunblock, sys_sigsetmask): Remove; all uses replaced by pthread_sigmask etc. calls. * src/syssignal.h: Include <signal.h>. (emacs_sigaction_init, forwarded_signal): New decls. (SIGMASKTYPE): Remove. All uses replaced by its definiens, sigset_t. (SIGEMPTYMASK): Remove; all uses replaced by its definiens, empty_mask. (sigmask, sys_sigmask): Remove; no longer needed. (sigpause): Remove. All uses replaced by its definiens, sigsuspend. (sigblock, sigunblock, sigfree): (sigsetmask) [!defined sigsetmask]: Remove. All uses replaced by pthread_sigmask. (signal): Remove. Its remaining uses (with SIG_DFL and SIG_IGN) no longer need to be replaced, and its typical old uses are now done via emacs_sigaction_init and sigaction. (sys_sigblock, sys_sigunblock, sys_sigsetmask): Remove decls. (sys_sigdel): Remove; unused. (NSIG): Remove a FIXME; the code's fine. Remove an unnecessary ifdef. Fixes: debbugs:12327
Diffstat (limited to 'src/atimer.c')
-rw-r--r--src/atimer.c49
1 files changed, 34 insertions, 15 deletions
diff --git a/src/atimer.c b/src/atimer.c
index 060dead9b17..34731920af5 100644
--- a/src/atimer.c
+++ b/src/atimer.c
@@ -17,7 +17,6 @@ You should have received a copy of the GNU General Public License
17along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ 17along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
18 18
19#include <config.h> 19#include <config.h>
20#include <signal.h>
21#include <stdio.h> 20#include <stdio.h>
22#include <setjmp.h> 21#include <setjmp.h>
23#include "lisp.h" 22#include "lisp.h"
@@ -51,8 +50,24 @@ int pending_atimers;
51 50
52/* Block/unblock SIGALRM. */ 51/* Block/unblock SIGALRM. */
53 52
54#define BLOCK_ATIMERS sigblock (sigmask (SIGALRM)) 53static void
55#define UNBLOCK_ATIMERS sigunblock (sigmask (SIGALRM)) 54sigmask_atimers (int how)
55{
56 sigset_t blocked;
57 sigemptyset (&blocked);
58 sigaddset (&blocked, SIGALRM);
59 pthread_sigmask (how, &blocked, 0);
60}
61static void
62block_atimers (void)
63{
64 sigmask_atimers (SIG_BLOCK);
65}
66static void
67unblock_atimers (void)
68{
69 sigmask_atimers (SIG_UNBLOCK);
70}
56 71
57/* Function prototypes. */ 72/* Function prototypes. */
58 73
@@ -109,7 +124,7 @@ start_atimer (enum atimer_type type, EMACS_TIME timestamp, atimer_callback fn,
109 t->fn = fn; 124 t->fn = fn;
110 t->client_data = client_data; 125 t->client_data = client_data;
111 126
112 BLOCK_ATIMERS; 127 block_atimers ();
113 128
114 /* Compute the timer's expiration time. */ 129 /* Compute the timer's expiration time. */
115 switch (type) 130 switch (type)
@@ -130,7 +145,7 @@ start_atimer (enum atimer_type type, EMACS_TIME timestamp, atimer_callback fn,
130 145
131 /* Insert the timer in the list of active atimers. */ 146 /* Insert the timer in the list of active atimers. */
132 schedule_atimer (t); 147 schedule_atimer (t);
133 UNBLOCK_ATIMERS; 148 unblock_atimers ();
134 149
135 /* Arrange for a SIGALRM at the time the next atimer is ripe. */ 150 /* Arrange for a SIGALRM at the time the next atimer is ripe. */
136 set_alarm (); 151 set_alarm ();
@@ -146,7 +161,7 @@ cancel_atimer (struct atimer *timer)
146{ 161{
147 int i; 162 int i;
148 163
149 BLOCK_ATIMERS; 164 block_atimers ();
150 165
151 for (i = 0; i < 2; ++i) 166 for (i = 0; i < 2; ++i)
152 { 167 {
@@ -173,7 +188,7 @@ cancel_atimer (struct atimer *timer)
173 } 188 }
174 } 189 }
175 190
176 UNBLOCK_ATIMERS; 191 unblock_atimers ();
177} 192}
178 193
179 194
@@ -204,7 +219,7 @@ append_atimer_lists (struct atimer *list_1, struct atimer *list_2)
204void 219void
205stop_other_atimers (struct atimer *t) 220stop_other_atimers (struct atimer *t)
206{ 221{
207 BLOCK_ATIMERS; 222 block_atimers ();
208 223
209 if (t) 224 if (t)
210 { 225 {
@@ -229,7 +244,7 @@ stop_other_atimers (struct atimer *t)
229 244
230 stopped_atimers = append_atimer_lists (atimers, stopped_atimers); 245 stopped_atimers = append_atimer_lists (atimers, stopped_atimers);
231 atimers = t; 246 atimers = t;
232 UNBLOCK_ATIMERS; 247 unblock_atimers ();
233} 248}
234 249
235 250
@@ -244,7 +259,7 @@ run_all_atimers (void)
244 struct atimer *t = atimers; 259 struct atimer *t = atimers;
245 struct atimer *next; 260 struct atimer *next;
246 261
247 BLOCK_ATIMERS; 262 block_atimers ();
248 atimers = stopped_atimers; 263 atimers = stopped_atimers;
249 stopped_atimers = NULL; 264 stopped_atimers = NULL;
250 265
@@ -255,7 +270,7 @@ run_all_atimers (void)
255 t = next; 270 t = next;
256 } 271 }
257 272
258 UNBLOCK_ATIMERS; 273 unblock_atimers ();
259 } 274 }
260} 275}
261 276
@@ -397,9 +412,9 @@ do_pending_atimers (void)
397{ 412{
398 if (pending_atimers) 413 if (pending_atimers)
399 { 414 {
400 BLOCK_ATIMERS; 415 block_atimers ();
401 run_timers (); 416 run_timers ();
402 UNBLOCK_ATIMERS; 417 unblock_atimers ();
403 } 418 }
404} 419}
405 420
@@ -412,7 +427,9 @@ turn_on_atimers (bool on)
412{ 427{
413 if (on) 428 if (on)
414 { 429 {
415 signal (SIGALRM, deliver_alarm_signal); 430 struct sigaction action;
431 emacs_sigaction_init (&action, deliver_alarm_signal);
432 sigaction (SIGALRM, &action, 0);
416 set_alarm (); 433 set_alarm ();
417 } 434 }
418 else 435 else
@@ -423,8 +440,10 @@ turn_on_atimers (bool on)
423void 440void
424init_atimer (void) 441init_atimer (void)
425{ 442{
443 struct sigaction action;
426 free_atimers = stopped_atimers = atimers = NULL; 444 free_atimers = stopped_atimers = atimers = NULL;
427 pending_atimers = 0; 445 pending_atimers = 0;
428 /* pending_signals is initialized in init_keyboard.*/ 446 /* pending_signals is initialized in init_keyboard.*/
429 signal (SIGALRM, deliver_alarm_signal); 447 emacs_sigaction_init (&action, deliver_alarm_signal);
448 sigaction (SIGALRM, &action, 0);
430} 449}