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