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: gp_nsync.c,v 1.4 2002/02/21 22:24:52 giles Exp $ */
18 /* Dummy thread / semaphore / monitor implementation */
19 #include "std.h"
20 #include "gserror.h"
21 #include "gserrors.h"
22 #include "gpsync.h"
23
24 /* ------- Synchronization primitives -------- */
25
26 /* Semaphores */
27
28 uint
gp_semaphore_sizeof(void)29 gp_semaphore_sizeof(void)
30 {
31 return sizeof(gp_semaphore);
32 }
33
34 int
gp_semaphore_open(gp_semaphore * sema)35 gp_semaphore_open(gp_semaphore * sema)
36 {
37 if (sema)
38 *(int *)sema = 0;
39 return 0;
40 }
41
42 int
gp_semaphore_close(gp_semaphore * sema)43 gp_semaphore_close(gp_semaphore * sema)
44 {
45 return 0;
46 }
47
48 int
gp_semaphore_wait(gp_semaphore * sema)49 gp_semaphore_wait(gp_semaphore * sema)
50 {
51 if (*(int *)sema == 0)
52 return_error(gs_error_unknownerror); /* no real waiting */
53 --(*(int *)sema);
54 return 0;
55 }
56
57 int
gp_semaphore_signal(gp_semaphore * sema)58 gp_semaphore_signal(gp_semaphore * sema)
59 {
60 ++(*(int *)sema);
61 return 0;
62 }
63
64 /* Monitors */
65
66 uint
gp_monitor_sizeof(void)67 gp_monitor_sizeof(void)
68 {
69 return sizeof(gp_monitor);
70 }
71
72 int
gp_monitor_open(gp_monitor * mon)73 gp_monitor_open(gp_monitor * mon)
74 {
75 if (mon)
76 mon->dummy_ = 0;
77 return 0;
78 }
79
80 int
gp_monitor_close(gp_monitor * mon)81 gp_monitor_close(gp_monitor * mon)
82 {
83 return 0;
84 }
85
86 int
gp_monitor_enter(gp_monitor * mon)87 gp_monitor_enter(gp_monitor * mon)
88 {
89 if (mon->dummy_ != 0)
90 return_error(gs_error_unknownerror);
91 mon->dummy_ = mon;
92 return 0;
93 }
94
95 int
gp_monitor_leave(gp_monitor * mon)96 gp_monitor_leave(gp_monitor * mon)
97 {
98 if (mon->dummy_ != mon)
99 return_error(gs_error_unknownerror);
100 mon->dummy_ = 0;
101 return 0;
102 }
103
104 /* Thread creation */
105
106 int
gp_create_thread(gp_thread_creation_callback_t proc,void * proc_data)107 gp_create_thread(gp_thread_creation_callback_t proc, void *proc_data)
108 {
109 return_error(gs_error_unknownerror);
110 }
111