1 /* Copyright (C) 2001-2019 Artifex Software, Inc. 2 All Rights Reserved. 3 4 This software is provided AS-IS with no warranty, either express or 5 implied. 6 7 This software is distributed under license and may not be copied, 8 modified or distributed except as expressly authorized under the terms 9 of the license contained in the file LICENSE in this distribution. 10 11 Refer to licensing information at http://www.artifex.com or contact 12 Artifex Software, Inc., 1305 Grant Avenue - Suite 200, Novato, 13 CA 94945, U.S.A., +1(415)492-9861, for further information. 14 */ 15 16 17 /* Interface to synchronization primitives */ 18 19 /* Initial version 2/1/98 by John Desrosiers (soho@crl.com) */ 20 21 #if !defined(gxsync_INCLUDED) 22 # define gxsync_INCLUDED 23 24 #include "gpsync.h" 25 #include "gsmemory.h" 26 27 /* This module abstracts the platform-specific synchronization primitives. */ 28 /* Since these routines will see heavy use, performance is important. */ 29 30 /* ----- Semaphore interface ----- */ 31 /* These have the usual queued, counting semaphore semantics: at init time, */ 32 /* the event count is set to 0 ('wait' will wait until 1st signal). */ 33 typedef struct gx_semaphore_s { 34 gs_memory_t *memory; /* allocator to free memory */ 35 gp_semaphore native; /* MUST BE LAST last since length is undef'd */ 36 /* platform-dep impl, len is gp_semaphore_sizeof() */ 37 } gx_semaphore_t; 38 39 gx_semaphore_t * /* returns a new semaphore, 0 if error */ 40 gx_semaphore_alloc( 41 gs_memory_t * memory /* memory allocator to use */ 42 ); 43 void 44 gx_semaphore_free( 45 gx_semaphore_t * sema /* semaphore to delete */ 46 ); 47 48 gx_semaphore_t *gx_semaphore_label(gx_semaphore_t *mon, const char *name); 49 #ifndef BOBBIN 50 #define gx_semaphore_label(A,B) (A) 51 #endif 52 53 #define gx_semaphore_wait(sema) gp_semaphore_wait(&(sema)->native) 54 #define gx_semaphore_signal(sema) gp_semaphore_signal(&(sema)->native) 55 56 /* ----- Monitor interface ----- */ 57 /* These have the usual monitor semantics: at init time, */ 58 /* the event count is set to 1 (1st 'enter' succeeds immediately). */ 59 typedef struct gx_monitor_s { 60 gs_memory_t *memory; /* allocator to free memory */ 61 gp_monitor native; /* platform-dep impl, len is gp_monitor_sizeof() */ 62 } gx_monitor_t; 63 64 gx_monitor_t * /* returns a new monitor, 0 if error */ 65 gx_monitor_alloc( 66 gs_memory_t * memory /* memory allocator to use */ 67 ); 68 void 69 gx_monitor_free( 70 gx_monitor_t * mon /* monitor to delete */ 71 ); 72 73 gx_monitor_t *gx_monitor_label(gx_monitor_t *mon, const char *name); 74 #ifndef BOBBIN 75 #define gx_monitor_label(A,B) (A) 76 #endif 77 78 #define gx_monitor_enter(sema) gp_monitor_enter(&(sema)->native) 79 #define gx_monitor_leave(sema) gp_monitor_leave(&(sema)->native) 80 81 #endif /* !defined(gxsync_INCLUDED) */ 82