Mercurial > emacs
annotate src/blockinput.h @ 95551:949ded03c9f1
*** empty log message ***
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Wed, 04 Jun 2008 21:24:29 +0000 |
parents | 29adfc9354e7 |
children | d45acf0c8d23 |
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. |
75227
e90d04cd455a
Update copyright for years from Emacs 21 to present (mainly adding
Glenn Morris <rgm@gnu.org>
parents:
68651
diff
changeset
|
2 Copyright (C) 1989, 1993, 2001, 2002, 2003, 2004, |
79759 | 3 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
2437 | 4 |
5 This file is part of GNU Emacs. | |
6 | |
94994
29adfc9354e7
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79759
diff
changeset
|
7 GNU Emacs is free software: you can redistribute it and/or modify |
2437 | 8 it under the terms of the GNU General Public License as published by |
94994
29adfc9354e7
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79759
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
29adfc9354e7
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79759
diff
changeset
|
10 (at your option) any later version. |
2437 | 11 |
12 GNU Emacs is distributed in the hope that it will be useful, | |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
94994
29adfc9354e7
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79759
diff
changeset
|
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
2437 | 19 |
29926
5a1dca465b50
Protect against multiple inclusion. Include
Dave Love <fx@gnu.org>
parents:
27426
diff
changeset
|
20 #ifndef EMACS_BLOCKINPUT_H |
5a1dca465b50
Protect against multiple inclusion. Include
Dave Love <fx@gnu.org>
parents:
27426
diff
changeset
|
21 #define EMACS_BLOCKINPUT_H |
5a1dca465b50
Protect against multiple inclusion. Include
Dave Love <fx@gnu.org>
parents:
27426
diff
changeset
|
22 |
5a1dca465b50
Protect against multiple inclusion. Include
Dave Love <fx@gnu.org>
parents:
27426
diff
changeset
|
23 #include "atimer.h" |
2437 | 24 |
25 /* When Emacs is using signal-driven input, the processing of those | |
26 input signals can get pretty hairy. For example, when Emacs is | |
27 running under X windows, handling an input signal can entail | |
28 retrieving events from the X event queue, or making other X calls. | |
29 | |
30 If an input signal occurs while Emacs is in the midst of some | |
31 non-reentrant code, and the signal processing invokes that same | |
32 code, we lose. For example, malloc and the Xlib functions aren't | |
33 usually re-entrant, and both are used by the X input signal handler | |
34 - if we try to process an input signal in the midst of executing | |
35 any of these functions, we'll lose. | |
36 | |
37 To avoid this, we make the following requirements: | |
38 | |
39 * Everyone must evaluate BLOCK_INPUT before entering these functions, | |
40 and then call UNBLOCK_INPUT after performing them. Calls | |
41 BLOCK_INPUT and UNBLOCK_INPUT may be nested. | |
42 | |
43 * Any complicated interrupt handling code should test | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
29926
diff
changeset
|
44 interrupt_input_blocked, and put off its work until later. |
2437 | 45 |
46 * If the interrupt handling code wishes, it may set | |
47 interrupt_input_pending to a non-zero value. If that flag is set | |
48 when input becomes unblocked, UNBLOCK_INPUT will send a new SIGIO. */ | |
49 | |
75407
205d5c1af245
(interrupt_input_blocked): Declare volatile.
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
parents:
75227
diff
changeset
|
50 extern volatile int interrupt_input_blocked; |
2437 | 51 |
52 /* Nonzero means an input interrupt has arrived | |
53 during the current critical section. */ | |
54 extern int interrupt_input_pending; | |
55 | |
27426
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
56 |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
57 /* 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
|
58 unblocked. */ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
59 |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
60 extern int pending_atimers; |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
61 |
2437 | 62 /* Begin critical section. */ |
63 #define BLOCK_INPUT (interrupt_input_blocked++) | |
64 | |
2721
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
65 /* End critical section. |
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 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
|
68 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
|
69 |
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
70 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 SIGIO. |
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
76 |
ca5cb6cafc40
* blockinput.h (UNBLOCK_INPUT): We cannot assume that SIGIO is
Jim Blandy <jimb@redhat.com>
parents:
2479
diff
changeset
|
77 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
|
78 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
|
79 |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
80 #define UNBLOCK_INPUT \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
81 do \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
82 { \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
83 --interrupt_input_blocked; \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
84 if (interrupt_input_blocked == 0) \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
85 { \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
86 if (interrupt_input_pending) \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
87 reinvoke_input_signal (); \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
88 if (pending_atimers) \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
89 do_pending_atimers (); \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
90 } \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
91 else if (interrupt_input_blocked < 0) \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
92 abort (); \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
93 } \ |
e28edb0e4233
(pending_atimers): Add extern declaration.
Gerd Moellmann <gerd@gnu.org>
parents:
21796
diff
changeset
|
94 while (0) |
2437 | 95 |
60416
306f7ce8d80d
(UNBLOCK_INPUT_TO): New macro.
Richard M. Stallman <rms@gnu.org>
parents:
56135
diff
changeset
|
96 /* Undo any number of BLOCK_INPUT calls, |
306f7ce8d80d
(UNBLOCK_INPUT_TO): New macro.
Richard M. Stallman <rms@gnu.org>
parents:
56135
diff
changeset
|
97 and also reinvoke any pending signal. */ |
306f7ce8d80d
(UNBLOCK_INPUT_TO): New macro.
Richard M. Stallman <rms@gnu.org>
parents:
56135
diff
changeset
|
98 |
306f7ce8d80d
(UNBLOCK_INPUT_TO): New macro.
Richard M. Stallman <rms@gnu.org>
parents:
56135
diff
changeset
|
99 #define TOTALLY_UNBLOCK_INPUT \ |
60481
335c6a2f0c12
(TOTALLY_UNBLOCK_INPUT): Avoid dangling else.
Kim F. Storm <storm@cua.dk>
parents:
60474
diff
changeset
|
100 do if (interrupt_input_blocked != 0) \ |
60416
306f7ce8d80d
(UNBLOCK_INPUT_TO): New macro.
Richard M. Stallman <rms@gnu.org>
parents:
56135
diff
changeset
|
101 { \ |
306f7ce8d80d
(UNBLOCK_INPUT_TO): New macro.
Richard M. Stallman <rms@gnu.org>
parents:
56135
diff
changeset
|
102 interrupt_input_blocked = 1; \ |
306f7ce8d80d
(UNBLOCK_INPUT_TO): New macro.
Richard M. Stallman <rms@gnu.org>
parents:
56135
diff
changeset
|
103 UNBLOCK_INPUT; \ |
306f7ce8d80d
(UNBLOCK_INPUT_TO): New macro.
Richard M. Stallman <rms@gnu.org>
parents:
56135
diff
changeset
|
104 } \ |
60481
335c6a2f0c12
(TOTALLY_UNBLOCK_INPUT): Avoid dangling else.
Kim F. Storm <storm@cua.dk>
parents:
60474
diff
changeset
|
105 while (0) |
60416
306f7ce8d80d
(UNBLOCK_INPUT_TO): New macro.
Richard M. Stallman <rms@gnu.org>
parents:
56135
diff
changeset
|
106 |
306f7ce8d80d
(UNBLOCK_INPUT_TO): New macro.
Richard M. Stallman <rms@gnu.org>
parents:
56135
diff
changeset
|
107 /* Undo any number of BLOCK_INPUT calls down to level LEVEL, |
306f7ce8d80d
(UNBLOCK_INPUT_TO): New macro.
Richard M. Stallman <rms@gnu.org>
parents:
56135
diff
changeset
|
108 and also (if the level is now 0) reinvoke any pending signal. */ |
306f7ce8d80d
(UNBLOCK_INPUT_TO): New macro.
Richard M. Stallman <rms@gnu.org>
parents:
56135
diff
changeset
|
109 |
306f7ce8d80d
(UNBLOCK_INPUT_TO): New macro.
Richard M. Stallman <rms@gnu.org>
parents:
56135
diff
changeset
|
110 #define UNBLOCK_INPUT_TO(LEVEL) \ |
306f7ce8d80d
(UNBLOCK_INPUT_TO): New macro.
Richard M. Stallman <rms@gnu.org>
parents:
56135
diff
changeset
|
111 do \ |
306f7ce8d80d
(UNBLOCK_INPUT_TO): New macro.
Richard M. Stallman <rms@gnu.org>
parents:
56135
diff
changeset
|
112 { \ |
306f7ce8d80d
(UNBLOCK_INPUT_TO): New macro.
Richard M. Stallman <rms@gnu.org>
parents:
56135
diff
changeset
|
113 interrupt_input_blocked = (LEVEL) + 1; \ |
60474
3bb3556e7af0
(UNBLOCK_INPUT_TO): Always call UNBLOCK_INPUT.
Andreas Schwab <schwab@suse.de>
parents:
60416
diff
changeset
|
114 UNBLOCK_INPUT; \ |
60416
306f7ce8d80d
(UNBLOCK_INPUT_TO): New macro.
Richard M. Stallman <rms@gnu.org>
parents:
56135
diff
changeset
|
115 } \ |
306f7ce8d80d
(UNBLOCK_INPUT_TO): New macro.
Richard M. Stallman <rms@gnu.org>
parents:
56135
diff
changeset
|
116 while (0) |
306f7ce8d80d
(UNBLOCK_INPUT_TO): New macro.
Richard M. Stallman <rms@gnu.org>
parents:
56135
diff
changeset
|
117 |
2437 | 118 #define UNBLOCK_INPUT_RESIGNAL UNBLOCK_INPUT |
21515 | 119 |
55658
0e26a0be1ee5
(INPUT_BLOCKED_P): New macro.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
120 /* In critical section ? */ |
0e26a0be1ee5
(INPUT_BLOCKED_P): New macro.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
121 #define INPUT_BLOCKED_P (interrupt_input_blocked > 0) |
0e26a0be1ee5
(INPUT_BLOCKED_P): New macro.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
122 |
21515 | 123 /* Defined in keyboard.c */ |
21796
f7ca88e90856
(reinvoke_input_signal): Don't use prototype decl.
Richard M. Stallman <rms@gnu.org>
parents:
21515
diff
changeset
|
124 /* 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
|
125 extern void reinvoke_input_signal (); |
29926
5a1dca465b50
Protect against multiple inclusion. Include
Dave Love <fx@gnu.org>
parents:
27426
diff
changeset
|
126 |
5a1dca465b50
Protect against multiple inclusion. Include
Dave Love <fx@gnu.org>
parents:
27426
diff
changeset
|
127 #endif /* EMACS_BLOCKINPUT_H */ |
52401 | 128 |
129 /* arch-tag: 51a9ec86-945a-4966-8f04-2d1341250e03 | |
130 (do not change this comment) */ |