xref: /plan9/sys/src/cmd/gs/src/gp_macpoll.c (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 2001-2003 artofcode LLC.  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: gp_macpoll.c,v 1.3 2004/12/09 00:59:59 giles Exp $ */
18 /*
19  * Macintosh platform polling support for Ghostscript.
20  *
21  */
22 
23 #ifndef __CARBON__
24 #include <Timer.h>
25 #else
26 #include <Carbon.h>
27 #endif
28 
29 #include "gx.h"
30 #include "gp.h"
31 #include "gsdll.h"
32 #include "gpcheck.h"
33 #include "iapi.h"
34 #include "iref.h"
35 #include "iminst.h"
36 #include "imain.h"
37 
38 #ifdef CHECK_INTERRUPTS
39 
40 extern HWND hwndtext;
41 
42 /* ------ Process message loop ------ */
43 /*
44  * Check messages and interrupts; return true if interrupted.
45  * This is called frequently - it must be quick!
46  */
gp_check_interrupts(const gs_memory_t * mem)47 int gp_check_interrupts(const gs_memory_t *mem)
48 {
49 	/* static variables need to go away for thread safety */
50 	static unsigned long	lastYieldTicks = 0;
51 	int iRetVal = 0;
52 
53 	if ((TickCount() - lastYieldTicks) > 2) {
54 	    lastYieldTicks = TickCount();
55 	    if (pgsdll_callback) {
56 		/* WARNING: The use of the old gsdll interface is deprecated.
57 		 * The caller should use the newer gsapi_set_poll.
58 		 * If the caller needs access to "hwndtext", it should do
59 		 * this via caller_handle which is passed to poll_fn.
60 		 */
61 		/* the hwnd parameter which is submitted in gsdll_init
62 		 * to the DLL is returned in every gsdll_poll message
63 		 * in the count parameter
64 		 */
65 		iRetVal = (*pgsdll_callback)(GSDLL_POLL, 0, (long) hwndtext);
66 	    } else {
67 	    	if (mem == NULL) {
68 	    		/* this is not thread safe */
69 	    		mem = gs_lib_ctx_get_non_gc_memory_t();
70 	    	}
71 		if (mem && mem->gs_lib_ctx && mem->gs_lib_ctx->poll_fn)
72 		    iRetVal = (*mem->gs_lib_ctx->poll_fn)(mem->gs_lib_ctx->caller_handle);
73 	    }
74 	}
75 	return iRetVal;
76 }
77 #endif
78