xref: /plan9/sys/src/cmd/gs/src/gxsync.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1998 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: gxsync.h,v 1.5 2002/06/16 08:45:43 lpd Exp $ */
18 /* Interface to synchronization primitives */
19 
20 /* Initial version 2/1/98 by John Desrosiers (soho@crl.com) */
21 
22 #if !defined(gxsync_INCLUDED)
23 #  define gxsync_INCLUDED
24 
25 #include "gpsync.h"
26 #include "gsmemory.h"
27 
28 /* This module abstracts the platform-specific synchronization primitives. */
29 /* Since these routines will see heavy use, performance is important. */
30 
31 /* ----- Semaphore interface ----- */
32 /* These have the usual queued, counting semaphore semantics: at init time, */
33 /* the event count is set to 0 ('wait' will wait until 1st signal). */
34 typedef struct gx_semaphore_s {
35     gs_memory_t *memory;	/* allocator to free memory */
36     gp_semaphore native;	/* MUST BE LAST last since length is undef'd */
37     /*  platform-dep impl, len is gp_semaphore_sizeof() */
38 } gx_semaphore_t;
39 
40 gx_semaphore_t *		/* returns a new semaphore, 0 if error */
41     gx_semaphore_alloc(
42 		       gs_memory_t * memory	/* memory allocator to use */
43 		       );
44 void
45     gx_semaphore_free(
46 		      gx_semaphore_t * sema	/* semaphore to delete */
47 		      );
48 
49 #define gx_semaphore_wait(sema)  gp_semaphore_wait(&(sema)->native)
50 #define gx_semaphore_signal(sema)  gp_semaphore_signal(&(sema)->native)
51 
52 
53 /* ----- Monitor interface ----- */
54 /* These have the usual monitor semantics: at init time, */
55 /* the event count is set to 1 (1st 'enter' succeeds immediately). */
56 typedef struct gx_monitor_s {
57     gs_memory_t *memory;	/* allocator to free memory */
58     gp_monitor native;		/* platform-dep impl, len is gp_monitor_sizeof() */
59 } gx_monitor_t;
60 
61 gx_monitor_t *			/* returns a new monitor, 0 if error */
62     gx_monitor_alloc(
63 		     gs_memory_t * memory	/* memory allocator to use */
64 		     );
65 void
66     gx_monitor_free(
67 		    gx_monitor_t * mon	/* monitor to delete */
68 		    );
69 
70 #define gx_monitor_enter(sema)  gp_monitor_enter(&(sema)->native)
71 #define gx_monitor_leave(sema)  gp_monitor_leave(&(sema)->native)
72 
73 #endif /* !defined(gxsync_INCLUDED) */
74