Simplify and avoid signal-handling races.
[bpt/emacs.git] / src / blockinput.h
CommitLineData
9ac0d9e0 1/* blockinput.h - interface to blocking complicated interrupt-driven input.
acaf905b 2 Copyright (C) 1989, 1993, 2001-2012 Free Software Foundation, Inc.
33f9662a
JB
3
4This file is part of GNU Emacs.
5
b9b1cc14 6GNU Emacs is free software: you can redistribute it and/or modify
33f9662a 7it under the terms of the GNU General Public License as published by
b9b1cc14
GM
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
33f9662a
JB
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
b9b1cc14 17along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
33f9662a 18
b6df5543
DL
19#ifndef EMACS_BLOCKINPUT_H
20#define EMACS_BLOCKINPUT_H
21
4d7e6e51
PE
22INLINE_HEADER_BEGIN
23#ifndef BLOCKINPUT_INLINE
24# define BLOCKINPUT_INLINE INLINE
25#endif
33f9662a 26
4d7e6e51
PE
27/* Emacs should avoid doing anything hairy in a signal handler, because
28 so many system functions are non-reentrant. For example, malloc
29 and the Xlib functions aren't usually re-entrant, so if they were
30 used by the SIGIO handler, we'd lose.
33f9662a
JB
31
32 To avoid this, we make the following requirements:
33
4d7e6e51
PE
34 * Everyone must evaluate BLOCK_INPUT before performing actions that
35 might conflict with a signal handler, and then call UNBLOCK_INPUT
36 after performing them. Calls BLOCK_INPUT and UNBLOCK_INPUT may be
37 nested.
33f9662a
JB
38
39 * Any complicated interrupt handling code should test
4d7e6e51 40 INPUT_BLOCKED_P, and put off its work until later.
33f9662a
JB
41
42 * If the interrupt handling code wishes, it may set
4d7e6e51
PE
43 pending_signals to a non-zero value. If that flag is set
44 when input becomes unblocked, UNBLOCK_INPUT will then read
45 input and process timers.
33f9662a 46
4d7e6e51
PE
47 Historically, Emacs signal handlers did much more than they do now,
48 and this caused many BLOCK_INPUT calls to be sprinkled around the code.
49 FIXME: Remove calls that aren't needed now. */
95d9dd00 50
4d7e6e51 51extern volatile int interrupt_input_blocked;
95d9dd00 52
4d7e6e51 53/* Begin critical section. */
95d9dd00 54
4d7e6e51
PE
55BLOCKINPUT_INLINE void
56block_input (void)
57{
58 interrupt_input_blocked++;
59}
edfda783 60
4d7e6e51
PE
61extern void unblock_input (void);
62extern void totally_unblock_input (void);
63extern void unblock_input_to (int);
ec5d8db7 64
c2de28ef 65/* In critical section ? */
c2de28ef 66
4d7e6e51
PE
67BLOCKINPUT_INLINE bool
68input_blocked_p (void)
69{
70 return 0 < interrupt_input_blocked;
71}
72
73INLINE_HEADER_END
b6df5543
DL
74
75#endif /* EMACS_BLOCKINPUT_H */