Mercurial > emacs
annotate src/blockinput.h @ 58986:59945307b86b
* syssignal.h: Declare main_thread.
(SIGNAL_THREAD_CHECK): New macro.
* keyboard.c (input_available_signal): Move thread checking code
to macro SIGNAL_THREAD_CHECK and call that macro.
(interrupt_signal): Call SIGNAL_THREAD_CHECK.
* alloc.c (uninterrupt_malloc): Move main_thread to emacs.c.
* emacs.c: Define main_thread.
(main): Initialize main_thread.
(handle_USR1_signal, handle_USR2_signal, fatal_error_signal)
(memory_warning_signal): Call SIGNAL_THREAD_CHECK.
* floatfns.c (float_error): Call SIGNAL_THREAD_CHECK.
* dispnew.c (window_change_signal): Call SIGNAL_THREAD_CHECK.
* sysdep.c (select_alarm): Call SIGNAL_THREAD_CHECK.
* process.c (send_process_trap, sigchld_handler): Call
SIGNAL_THREAD_CHECK.
* data.c (arith_error): Call SIGNAL_THREAD_CHECK.
* atimer.c (alarm_signal_handler): Call SIGNAL_THREAD_CHECK.
author | Jan Djärv <jan.h.d@swipnet.se> |
---|---|
date | Wed, 15 Dec 2004 21:40:41 +0000 |
parents | 5407da499273 |
children | 306f7ce8d80d 4c90ffeb71c5 |
rev | line source |
---|---|
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2437
diff
changeset
|
1 /* blockinput.h - interface to blocking complicated interrupt-driven input. |
56135 | 2 Copyright (C) 1989, 1993, 2004 Free Software Foundation, Inc. |
2437 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 2, or (at your option) | |
9 any later version. | |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
2721
diff
changeset
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
2721
diff
changeset
|
19 Boston, MA 02111-1307, USA. */ |
2437 | 20 |
29926
5a1dca465b50
Protect against multiple inclusion. Include
Dave Love <fx@gnu.org>
parents:
27426
diff
changeset
|
21 #ifndef EMACS_BLOCKINPUT_H |
5a1dca465b50
Protect against multiple inclusion. Include
Dave Love <fx@gnu.org>
parents:
27426
diff
changeset
|
22 #define EMACS_BLOCKINPUT_H |
5a1dca465b50
Protect against multiple inclusion. Include
Dave Love <fx@gnu.org>
parents:
27426
diff
changeset
|
23 |
5a1dca465b50
Protect against multiple inclusion. Include
Dave Love <fx@gnu.org>
parents:
27426
diff
changeset
|
24 #include "atimer.h" |
2437 | 25 |
26 /* When Emacs is using signal-driven input, the processing of those | |
27 input signals can get pretty hairy. For example, when Emacs is | |
28 running under X windows, handling an input signal can entail | |
29 retrieving events from the X event queue, or making other X calls. | |
30 | |
31 If an input signal occurs while Emacs is in the midst of some | |
32 non-reentrant code, and the signal processing invokes that same | |
33 code, we lose. For example, malloc and the Xlib functions aren't | |
34 usually re-entrant, and both are used by the X input signal handler | |
35 - if we try to process an input signal in the midst of executing | |
36 any of these functions, we'll lose. | |
37 | |
38 To avoid this, we make the following requirements: | |
39 | |
40 * Everyone must evaluate BLOCK_INPUT before entering these functions, | |
41 and then call UNBLOCK_INPUT after performing them. Calls | |
42 BLOCK_INPUT and UNBLOCK_INPUT may be nested. | |
43 | |
44 * Any complicated interrupt handling code should test | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
29926
diff
changeset
|
45 interrupt_input_blocked, and put off its work until later. |
2437 | 46 |
47 * If the interrupt handling code wishes, it may set | |
48 interrupt_input_pending to a non-zero value. If that flag is set | |
49 when input becomes unblocked, UNBLOCK_INPUT will send a new SIGIO. */ | |
50 | |
2479
6d011b24f6fe
(interrupt_input_blocked): Make this signed int.
Richard M. Stallman <rms@gnu.org>
parents:
2477
diff
changeset
|
51 extern int interrupt_input_blocked; |
2437 | 52 |
53 /* Nonzero means an input interrupt has arrived | |
54 during the current critical section. */ | |
55 extern int interrupt_input_pending; | |
56 | |
27426
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
57 |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
58 /* Non-zero means asynchronous timers should be run when input is |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
59 unblocked. */ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
60 |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
61 extern int pending_atimers; |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
62 |
2437 | 63 /* Begin critical section. */ |
64 #define BLOCK_INPUT (interrupt_input_blocked++) | |
65 | |
2721
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
66 /* End critical section. |
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
67 |
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
68 If doing signal-driven input, and a signal came in when input was |
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
69 blocked, reinvoke the signal handler now to deal with it. |
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
70 |
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
71 We used to have two possible definitions of this macro - one for |
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
72 when SIGIO was #defined, and one for when it wasn't; when SIGIO |
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
73 wasn't #defined, we wouldn't bother to check if we should re-invoke |
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
74 the signal handler. But that doesn't work very well; some of the |
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
75 files which use this macro don't #include the right files to get |
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
76 SIGIO. |
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
77 |
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
78 So, we always test interrupt_input_pending now; that's not too |
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
79 expensive, and it'll never get set if we don't need to resignal. */ |
27426
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
80 |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
81 #define UNBLOCK_INPUT \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
82 do \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
83 { \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
84 --interrupt_input_blocked; \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
85 if (interrupt_input_blocked == 0) \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
86 { \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
87 if (interrupt_input_pending) \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
88 reinvoke_input_signal (); \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
89 if (pending_atimers) \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
90 do_pending_atimers (); \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
91 } \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
92 else if (interrupt_input_blocked < 0) \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
93 abort (); \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
94 } \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
95 while (0) |
2437 | 96 |
97 #define TOTALLY_UNBLOCK_INPUT (interrupt_input_blocked = 0) | |
98 #define UNBLOCK_INPUT_RESIGNAL UNBLOCK_INPUT | |
21515 | 99 |
55658
0e26a0be1ee5
(INPUT_BLOCKED_P): New macro.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
100 /* In critical section ? */ |
0e26a0be1ee5
(INPUT_BLOCKED_P): New macro.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
101 #define INPUT_BLOCKED_P (interrupt_input_blocked > 0) |
0e26a0be1ee5
(INPUT_BLOCKED_P): New macro.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
102 |
21515 | 103 /* Defined in keyboard.c */ |
21796
f7ca88e90856
(reinvoke_input_signal): Don't use prototype decl.
Richard M. Stallman <rms@gnu.org>
parents:
21515
diff
changeset
|
104 /* Don't use a prototype here; it causes trouble in some files. */ |
f7ca88e90856
(reinvoke_input_signal): Don't use prototype decl.
Richard M. Stallman <rms@gnu.org>
parents:
21515
diff
changeset
|
105 extern void reinvoke_input_signal (); |
29926
5a1dca465b50
Protect against multiple inclusion. Include
Dave Love <fx@gnu.org>
parents:
27426
diff
changeset
|
106 |
5a1dca465b50
Protect against multiple inclusion. Include
Dave Love <fx@gnu.org>
parents:
27426
diff
changeset
|
107 #endif /* EMACS_BLOCKINPUT_H */ |
52401 | 108 |
109 /* arch-tag: 51a9ec86-945a-4966-8f04-2d1341250e03 | |
110 (do not change this comment) */ |