Don't reference removed files in Makefile
[python/dscho.git] / Python / thread_solaris.h
blob199d7d09d6f9309a80d8d1e7939260d31349109f
1 /***********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3 The Netherlands.
5 All Rights Reserved
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI not be used in advertising or publicity pertaining to
13 distribution of the software without specific, written prior permission.
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 ******************************************************************/
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <unistd.h>
28 #include </usr/include/thread.h>
32 * Initialization.
34 static void _init_thread _P0()
39 * Thread support.
41 struct func_arg {
42 void (*func) _P((void *));
43 void *arg;
46 static void *new_func _P1(funcarg, void *funcarg)
48 void (*func) _P((void *));
49 void *arg;
51 func = ((struct func_arg *) funcarg)->func;
52 arg = ((struct func_arg *) funcarg)->arg;
53 free(funcarg);
54 (*func)(arg);
55 return 0;
59 int start_new_thread _P2(func, void (*func) _P((void *)), arg, void *arg)
61 struct func_arg *funcarg;
62 int success = 0; /* init not needed when SOLARIS_THREADS and */
63 /* C_THREADS implemented properly */
65 dprintf(("start_new_thread called\n"));
66 if (!initialized)
67 init_thread();
68 funcarg = (struct func_arg *) malloc(sizeof(struct func_arg));
69 funcarg->func = func;
70 funcarg->arg = arg;
71 if (thr_create(0, 0, new_func, funcarg, THR_DETACHED, 0)) {
72 perror("thr_create");
73 free((void *) funcarg);
74 success = -1;
76 return success < 0 ? 0 : 1;
79 long get_thread_ident _P0()
81 if (!initialized)
82 init_thread();
83 return thr_self();
86 static void do_exit_thread _P1(no_cleanup, int no_cleanup)
88 dprintf(("exit_thread called\n"));
89 if (!initialized)
90 if (no_cleanup)
91 _exit(0);
92 else
93 exit(0);
94 thr_exit(0);
97 void exit_thread _P0()
99 do_exit_thread(0);
102 void _exit_thread _P0()
104 do_exit_thread(1);
107 #ifndef NO_EXIT_PROG
108 static void do_exit_prog _P2(status, int status, no_cleanup, int no_cleanup)
110 dprintf(("exit_prog(%d) called\n", status));
111 if (!initialized)
112 if (no_cleanup)
113 _exit(status);
114 else
115 exit(status);
116 if (no_cleanup)
117 _exit(status);
118 else
119 exit(status);
122 void exit_prog _P1(status, int status)
124 do_exit_prog(status, 0);
127 void _exit_prog _P1(status, int status)
129 do_exit_prog(status, 1);
131 #endif /* NO_EXIT_PROG */
134 * Lock support.
136 type_lock allocate_lock _P0()
138 mutex_t *lock;
140 dprintf(("allocate_lock called\n"));
141 if (!initialized)
142 init_thread();
144 lock = (mutex_t *) malloc(sizeof(mutex_t));
145 if (mutex_init(lock, USYNC_THREAD, 0)) {
146 perror("mutex_init");
147 free((void *) lock);
148 lock = 0;
150 dprintf(("allocate_lock() -> %lx\n", (long)lock));
151 return (type_lock) lock;
154 void free_lock _P1(lock, type_lock lock)
156 dprintf(("free_lock(%lx) called\n", (long)lock));
157 mutex_destroy((mutex_t *) lock);
158 free((void *) lock);
161 int acquire_lock _P2(lock, type_lock lock, waitflag, int waitflag)
163 int success;
165 dprintf(("acquire_lock(%lx, %d) called\n", (long)lock, waitflag));
166 if (waitflag)
167 success = mutex_lock((mutex_t *) lock);
168 else
169 success = mutex_trylock((mutex_t *) lock);
170 if (success < 0)
171 perror(waitflag ? "mutex_lock" : "mutex_trylock");
172 else
173 success = !success; /* solaris does it the other way round */
174 dprintf(("acquire_lock(%lx, %d) -> %d\n", (long)lock, waitflag, success));
175 return success;
178 void release_lock _P1(lock, type_lock lock)
180 dprintf(("release_lock(%lx) called\n", (long)lock));
181 if (mutex_unlock((mutex_t *) lock))
182 perror("mutex_unlock");
186 * Semaphore support.
188 type_sema allocate_sema _P1(value, int value)
190 sema_t *sema;
191 dprintf(("allocate_sema called\n"));
192 if (!initialized)
193 init_thread();
195 sema = (sema_t *) malloc(sizeof(sema_t));
196 if (sema_init(sema, value, USYNC_THREAD, 0)) {
197 perror("sema_init");
198 free((void *) sema);
199 sema = 0;
201 dprintf(("allocate_sema() -> %lx\n", (long) sema));
202 return (type_sema) sema;
205 void free_sema _P1(sema, type_sema sema)
207 dprintf(("free_sema(%lx) called\n", (long) sema));
208 if (sema_destroy((sema_t *) sema))
209 perror("sema_destroy");
210 free((void *) sema);
213 void down_sema _P1(sema, type_sema sema)
215 dprintf(("down_sema(%lx) called\n", (long) sema));
216 if (sema_wait((sema_t *) sema))
217 perror("sema_wait");
218 dprintf(("down_sema(%lx) return\n", (long) sema));
221 void up_sema _P1(sema, type_sema sema)
223 dprintf(("up_sema(%lx)\n", (long) sema));
224 if (sema_post((sema_t *) sema))
225 perror("sema_post");