xref: /plan9/sys/src/cmd/gs/src/gpcheck.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1992, 1994 Aladdin Enterprises.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: gpcheck.h,v 1.9 2004/08/13 12:59:03 stefan Exp $ */
18 /* Interrupt check interface */
19 
20 #ifndef gpcheck_INCLUDED
21 #  define gpcheck_INCLUDED
22 
23 /*
24  * On some platforms, the interpreter must check periodically for user-
25  * initiated actions.  (Eventually, this may be extended to all platforms,
26  * to handle multi-tasking through the 'context' facility.)  Routines that
27  * run for a long time must periodically call gp_check_interrupts(), and
28  * if it returns true, must clean up whatever they are doing and return an
29  * e_interrupted (or gs_error_interrupted) exceptional condition.
30  * The return_if_interrupt macro provides a convenient way to do this.
31  *
32  * On platforms that require an interrupt check, the makefile defines
33  * a symbol CHECK_INTERRUPTS.  Currently this is only the Microsoft
34  * Windows platform.
35  */
36 int gs_return_check_interrupt(const gs_memory_t *mem, int code);
37 
38 #ifdef CHECK_INTERRUPTS
39 int gp_check_interrupts(const gs_memory_t *mem);
40 #  define process_interrupts(mem) discard(gp_check_interrupts(mem))
41 #  define return_if_interrupt(mem)\
42     { int icode_ = gp_check_interrupts(mem);	\
43       if ( icode_ )\
44 	return gs_note_error((icode_ > 0 ? gs_error_interrupt : icode_));\
45     }
46 #  define return_check_interrupt(mem, code)	\
47     return gs_return_check_interrupt(mem, code)
48 #  define set_code_on_interrupt(mem, pcode)	\
49     if (*(pcode) == 0)\
50      *(pcode) = (gp_check_interrupts(mem) != 0) ? gs_error_interrupt : 0;
51 #else
52 #  define gp_check_interrupts(mem) 0
53 #  define process_interrupts(mem) DO_NOTHING
54 #  define return_if_interrupt(mem)	DO_NOTHING
55 #  define return_check_interrupt(mem, code)	\
56     return (code)
57 #  define set_code_on_interrupt(mem, code) DO_NOTHING
58 #endif
59 
60 #endif /* gpcheck_INCLUDED */
61