xref: /plan9/sys/src/cmd/gs/src/gsmemlok.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1998, 1999 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: gsmemlok.h,v 1.5 2002/06/16 08:45:42 lpd Exp $ */
18 /* Interface to monitor-locked heap memory allocator */
19 
20 /* Initial version 2/1/98 by John Desrosiers (soho@crl.com) */
21 
22 #if !defined(gsmemlok_INCLUDED)
23 #  define gsmemlok_INCLUDED
24 
25 #include "gsmemory.h"
26 #include "gxsync.h"
27 
28 /*
29  * This allocator encapsulates another allocator with a mutex.
30  * Note that it does not keep track of memory that it acquires:
31  * thus free_all with FREE_ALL_DATA is a no-op.
32  */
33 
34 typedef struct gs_memory_locked_s {
35     gs_memory_common;		/* interface outside world sees */
36     gs_memory_t *target;	/* allocator to front */
37     gx_monitor_t *monitor;	/* monitor to serialize access to functions */
38 } gs_memory_locked_t;
39 
40 /* ---------- Public constructors/destructors ---------- */
41 
42 /* Initialize a locked memory manager. */
43 int gs_memory_locked_init(
44 			  gs_memory_locked_t * lmem,	/* allocator to init */
45 			  gs_memory_t * target	/* allocator to monitor lock */
46 			  );
47 
48 /* Release a locked memory manager. */
49 /* Note that this has no effect on the target. */
50 void gs_memory_locked_release(gs_memory_locked_t *lmem);
51 
52 /* Get the target of a locked memory manager. */
53 gs_memory_t * gs_memory_locked_target(const gs_memory_locked_t *lmem);
54 
55 #endif /*!defined(gsmemlok_INCLUDED) */
56