Update copyright year to 2014 by running admin/update-copyright.
[emacs.git] / src / blockinput.h
blob8303c8c4d36ecfefd823a23ef7cdd8229d8bb35f
1 /* blockinput.h - interface to blocking complicated interrupt-driven input.
2 Copyright (C) 1989, 1993, 2001-2014 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
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 3 of the License, or
9 (at your option) any later version.
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.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19 #ifndef EMACS_BLOCKINPUT_H
20 #define EMACS_BLOCKINPUT_H
22 INLINE_HEADER_BEGIN
24 /* Emacs should avoid doing anything hairy in a signal handler, because
25 so many system functions are non-reentrant. For example, malloc
26 and the Xlib functions aren't usually re-entrant, so if they were
27 used by the SIGIO handler, we'd lose.
29 To avoid this, we make the following requirements:
31 * Everyone must evaluate BLOCK_INPUT before performing actions that
32 might conflict with a signal handler, and then call UNBLOCK_INPUT
33 after performing them. Calls BLOCK_INPUT and UNBLOCK_INPUT may be
34 nested.
36 * Any complicated interrupt handling code should test
37 INPUT_BLOCKED_P, and put off its work until later.
39 * If the interrupt handling code wishes, it may set
40 pending_signals to a non-zero value. If that flag is set
41 when input becomes unblocked, UNBLOCK_INPUT will then read
42 input and process timers.
44 Historically, Emacs signal handlers did much more than they do now,
45 and this caused many BLOCK_INPUT calls to be sprinkled around the code.
46 FIXME: Remove calls that aren't needed now. */
48 extern volatile int interrupt_input_blocked;
50 /* Begin critical section. */
52 INLINE void
53 block_input (void)
55 interrupt_input_blocked++;
58 extern void unblock_input (void);
59 extern void totally_unblock_input (void);
60 extern void unblock_input_to (int);
62 /* In critical section? */
64 INLINE bool
65 input_blocked_p (void)
67 return interrupt_input_blocked > 0;
70 INLINE_HEADER_END
72 #endif /* EMACS_BLOCKINPUT_H */