Mercurial > emacs
annotate src/blockinput.h @ 3674:cfa45731460e
(Fcopy_keymap): Check Fkeymapp value with NILP.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 12 Jun 1993 07:19:39 +0000 |
parents | ca5cb6cafc40 |
children | ee40177f6c68 |
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. |
2437 | 2 Copyright (C) 1989, 1993 Free Software Foundation, Inc. |
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 | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | |
20 | |
21 /* When Emacs is using signal-driven input, the processing of those | |
22 input signals can get pretty hairy. For example, when Emacs is | |
23 running under X windows, handling an input signal can entail | |
24 retrieving events from the X event queue, or making other X calls. | |
25 | |
26 If an input signal occurs while Emacs is in the midst of some | |
27 non-reentrant code, and the signal processing invokes that same | |
28 code, we lose. For example, malloc and the Xlib functions aren't | |
29 usually re-entrant, and both are used by the X input signal handler | |
30 - if we try to process an input signal in the midst of executing | |
31 any of these functions, we'll lose. | |
32 | |
33 To avoid this, we make the following requirements: | |
34 | |
35 * Everyone must evaluate BLOCK_INPUT before entering these functions, | |
36 and then call UNBLOCK_INPUT after performing them. Calls | |
37 BLOCK_INPUT and UNBLOCK_INPUT may be nested. | |
38 | |
39 * Any complicated interrupt handling code should test | |
40 interrupt_input_blocked, and put off its work until later. | |
41 | |
42 * If the interrupt handling code wishes, it may set | |
43 interrupt_input_pending to a non-zero value. If that flag is set | |
44 when input becomes unblocked, UNBLOCK_INPUT will send a new SIGIO. */ | |
45 | |
2479
6d011b24f6fe
(interrupt_input_blocked): Make this signed int.
Richard M. Stallman <rms@gnu.org>
parents:
2477
diff
changeset
|
46 extern int interrupt_input_blocked; |
2437 | 47 |
48 /* Nonzero means an input interrupt has arrived | |
49 during the current critical section. */ | |
50 extern int interrupt_input_pending; | |
51 | |
52 /* Begin critical section. */ | |
53 #define BLOCK_INPUT (interrupt_input_blocked++) | |
54 | |
2721
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
55 /* End critical section. |
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
56 |
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
57 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
|
58 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
|
59 |
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 SIGIO. |
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
66 |
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
67 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
|
68 expensive, and it'll never get set if we don't need to resignal. */ |
2437 | 69 #define UNBLOCK_INPUT \ |
70 (interrupt_input_blocked--, \ | |
71 (interrupt_input_blocked < 0 ? (abort (), 0) : 0), \ | |
2477
4d0d858bc33f
(UNBLOCK_INPUT): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
72 ((interrupt_input_blocked == 0 && interrupt_input_pending != 0) \ |
2721
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
73 ? (reinvoke_input_signal (), 0) \ |
2437 | 74 : 0)) |
75 | |
76 #define TOTALLY_UNBLOCK_INPUT (interrupt_input_blocked = 0) | |
77 #define UNBLOCK_INPUT_RESIGNAL UNBLOCK_INPUT |