(Completion Options): Fix typo.
[bpt/emacs.git] / src / blockinput.h
CommitLineData
9ac0d9e0 1/* blockinput.h - interface to blocking complicated interrupt-driven input.
a0ecb2ac 2 Copyright (C) 1989, 1993, 2004 Free Software Foundation, Inc.
33f9662a
JB
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to
3b7ad313
EN
18the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
33f9662a 20
b6df5543
DL
21#ifndef EMACS_BLOCKINPUT_H
22#define EMACS_BLOCKINPUT_H
23
24#include "atimer.h"
33f9662a
JB
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
177c0ea7 45 interrupt_input_blocked, and put off its work until later.
33f9662a
JB
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
61836955 51extern int interrupt_input_blocked;
33f9662a
JB
52
53/* Nonzero means an input interrupt has arrived
54 during the current critical section. */
55extern int interrupt_input_pending;
56
95d9dd00
GM
57
58/* Non-zero means asynchronous timers should be run when input is
59 unblocked. */
60
61extern int pending_atimers;
62
33f9662a
JB
63/* Begin critical section. */
64#define BLOCK_INPUT (interrupt_input_blocked++)
65
40a4095a
JB
66/* End critical section.
67
68 If doing signal-driven input, and a signal came in when input was
69 blocked, reinvoke the signal handler now to deal with it.
70
71 We used to have two possible definitions of this macro - one for
72 when SIGIO was #defined, and one for when it wasn't; when SIGIO
73 wasn't #defined, we wouldn't bother to check if we should re-invoke
74 the signal handler. But that doesn't work very well; some of the
75 files which use this macro don't #include the right files to get
76 SIGIO.
77
78 So, we always test interrupt_input_pending now; that's not too
79 expensive, and it'll never get set if we don't need to resignal. */
95d9dd00
GM
80
81#define UNBLOCK_INPUT \
82 do \
83 { \
84 --interrupt_input_blocked; \
85 if (interrupt_input_blocked == 0) \
86 { \
87 if (interrupt_input_pending) \
88 reinvoke_input_signal (); \
89 if (pending_atimers) \
90 do_pending_atimers (); \
91 } \
92 else if (interrupt_input_blocked < 0) \
93 abort (); \
94 } \
95 while (0)
33f9662a 96
835ee136
RS
97/* Undo any number of BLOCK_INPUT calls,
98 and also reinvoke any pending signal. */
99
100#define TOTALLY_UNBLOCK_INPUT \
101 if (interrupt_input_blocked != 0) \
102 { \
103 interrupt_input_blocked = 1; \
104 UNBLOCK_INPUT; \
105 } \
106 else
107
108/* Undo any number of BLOCK_INPUT calls down to level LEVEL,
109 and also (if the level is now 0) reinvoke any pending signal. */
110
111#define UNBLOCK_INPUT_TO(LEVEL) \
112 do \
113 { \
114 int oldlevel = interrupt_input_blocked; \
115 interrupt_input_blocked = (LEVEL) + 1; \
116 if (interrupt_input_blocked != oldlevel + 1) \
117 UNBLOCK_INPUT; \
118 } \
119 while (0)
120
33f9662a 121#define UNBLOCK_INPUT_RESIGNAL UNBLOCK_INPUT
ec5d8db7 122
c2de28ef
KS
123/* In critical section ? */
124#define INPUT_BLOCKED_P (interrupt_input_blocked > 0)
125
ec5d8db7 126/* Defined in keyboard.c */
de4df76b
RS
127/* Don't use a prototype here; it causes trouble in some files. */
128extern void reinvoke_input_signal ();
b6df5543
DL
129
130#endif /* EMACS_BLOCKINPUT_H */
ab5796a9
MB
131
132/* arch-tag: 51a9ec86-945a-4966-8f04-2d1341250e03
133 (do not change this comment) */