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