blob: 56ef137278b75878c5e84b81a5a0b5627fe7a9b8 [file] [log] [blame]
Guido van Rossum34679b71993-01-26 13:33:44 +00001/***********************************************************
2Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
3Amsterdam, The Netherlands.
4
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
Guido van Rossum1984f1e1992-08-04 12:41:02 +000025#include "thread.h"
26
Guido van Rossumf9f2e821992-08-17 08:59:08 +000027#ifdef DEBUG
Sjoerd Mullenderd10d8291992-09-11 15:19:27 +000028static int thread_debug = 0;
29#define dprintf(args) (thread_debug && printf args)
Guido van Rossumf9f2e821992-08-17 08:59:08 +000030#else
31#define dprintf(args)
32#endif
33
Guido van Rossum1984f1e1992-08-04 12:41:02 +000034#ifdef __sgi
35#include <stdlib.h>
36#include <stdio.h>
37#include <signal.h>
38#include <sys/types.h>
39#include <sys/prctl.h>
40#include <ulocks.h>
Sjoerd Mullendere8934121993-01-13 12:08:48 +000041#include <errno.h>
Guido van Rossum1984f1e1992-08-04 12:41:02 +000042
Sjoerd Mullender76ab5fe1993-01-13 12:49:46 +000043#define HDR_SIZE 2680 /* sizeof(ushdr_t) */
Guido van Rossumf9f2e821992-08-17 08:59:08 +000044#define MAXPROC 100 /* max # of threads that can be started */
45
Guido van Rossum1984f1e1992-08-04 12:41:02 +000046static usptr_t *shared_arena;
Guido van Rossumf9f2e821992-08-17 08:59:08 +000047static ulock_t count_lock; /* protection for some variables */
48static ulock_t wait_lock; /* lock used to wait for other threads */
49static int waiting_for_threads; /* protected by count_lock */
50static int nthreads; /* protected by count_lock */
Guido van Rossum1984f1e1992-08-04 12:41:02 +000051static int exit_status;
Sjoerd Mullendered59d201993-01-06 13:36:38 +000052static int do_exit; /* indicates that the program is to exit */
Guido van Rossumf9f2e821992-08-17 08:59:08 +000053static int exiting; /* we're already exiting (for maybe_exit) */
54static pid_t my_pid; /* PID of main thread */
55static pid_t pidlist[MAXPROC]; /* PIDs of other threads */
56static int maxpidindex; /* # of PIDs in pidlist */
Guido van Rossum1984f1e1992-08-04 12:41:02 +000057#endif
58#ifdef sun
59#include <lwp/lwp.h>
60#include <lwp/stackdep.h>
61
Guido van Rossumf9f2e821992-08-17 08:59:08 +000062#define STACKSIZE 1000 /* stacksize for a thread */
Guido van Rossum1984f1e1992-08-04 12:41:02 +000063#define NSTACKS 2 /* # stacks to be put in cache initialy */
64
65struct lock {
66 int lock_locked;
67 cv_t lock_condvar;
68 mon_t lock_monitor;
69};
70#endif
71#ifdef C_THREADS
72#include <cthreads.h>
73#endif
74
75#ifdef __STDC__
76#define _P(args) args
77#define _P0() (void)
78#define _P1(v,t) (t)
79#define _P2(v1,t1,v2,t2) (t1,t2)
80#else
81#define _P(args) ()
82#define _P0() ()
83#define _P1(v,t) (v) t;
84#define _P2(v1,t1,v2,t2) (v1,v2) t1; t2;
85#endif
86
87static int initialized;
88
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +000089#ifdef __sgi
90/*
91 * This routine is called as a signal handler when another thread
92 * exits. When that happens, we must see whether we have to exit as
93 * well (because of an exit_prog()) or whether we should continue on.
94 */
95static void exit_sig _P0()
96{
97 dprintf(("exit_sig called\n"));
98 if (exiting && getpid() == my_pid) {
99 dprintf(("already exiting\n"));
100 return;
101 }
102 if (do_exit) {
103 dprintf(("exiting in exit_sig\n"));
104 exit_thread();
105 }
106}
107
108/*
109 * This routine is called when a process calls exit(). If that wasn't
110 * done from the library, we do as if an exit_prog() was intended.
111 */
112static void maybe_exit _P0()
113{
114 dprintf(("maybe_exit called\n"));
115 if (exiting) {
116 dprintf(("already exiting\n"));
117 return;
118 }
119 exit_prog(0);
120}
121#endif
122
123/*
124 * Initialization.
125 */
126void init_thread _P0()
127{
128#ifdef __sgi
129 struct sigaction s;
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000130#ifdef USE_DL
131 long addr, size;
132#endif
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000133#endif
134
Sjoerd Mullenderd10d8291992-09-11 15:19:27 +0000135#ifdef DEBUG
136 thread_debug = getenv("THREADDEBUG") != 0;
137#endif
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000138 if (initialized)
139 return;
140 initialized = 1;
Sjoerd Mullendered59d201993-01-06 13:36:38 +0000141 dprintf(("init_thread called\n"));
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000142
143#ifdef __sgi
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000144#ifdef USE_DL
145 if ((size = usconfig(CONF_INITSIZE, 64*1024)) < 0)
146 perror("usconfig - CONF_INITSIZE (check)");
147 if (usconfig(CONF_INITSIZE, size) < 0)
148 perror("usconfig - CONF_INITSIZE (reset)");
Sjoerd Mullender76ab5fe1993-01-13 12:49:46 +0000149 addr = (long) dl_getrange(size + HDR_SIZE);
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000150 dprintf(("trying to use addr %lx-%lx for shared arena\n", addr, addr+size));
151 errno = 0;
152 if ((addr = usconfig(CONF_ATTACHADDR, addr)) < 0 && errno != 0)
153 perror("usconfig - CONF_ATTACHADDR (set)");
154#endif
Sjoerd Mullendered59d201993-01-06 13:36:38 +0000155 if (usconfig(CONF_INITUSERS, 16) < 0)
156 perror("usconfig - CONF_INITUSERS");
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000157 my_pid = getpid(); /* so that we know which is the main thread */
158 atexit(maybe_exit);
159 s.sa_handler = exit_sig;
160 sigemptyset(&s.sa_mask);
Sjoerd Mullenderd10d8291992-09-11 15:19:27 +0000161 /*sigaddset(&s.sa_mask, SIGUSR1);*/
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000162 s.sa_flags = 0;
163 sigaction(SIGUSR1, &s, 0);
Sjoerd Mullendered59d201993-01-06 13:36:38 +0000164 if (prctl(PR_SETEXITSIG, SIGUSR1) < 0)
165 perror("prctl - PR_SETEXITSIG");
166 if (usconfig(CONF_ARENATYPE, US_SHAREDONLY) < 0)
167 perror("usconfig - CONF_ARENATYPE");
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000168 /*usconfig(CONF_LOCKTYPE, US_DEBUGPLUS);*/
Sjoerd Mullendered59d201993-01-06 13:36:38 +0000169 if ((shared_arena = usinit(tmpnam(0))) == 0)
170 perror("usinit");
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000171#ifdef USE_DL
172 if (usconfig(CONF_ATTACHADDR, addr) < 0) /* reset address */
173 perror("usconfig - CONF_ATTACHADDR (reset)");
Sjoerd Mullendered59d201993-01-06 13:36:38 +0000174#endif
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000175 if ((count_lock = usnewlock(shared_arena)) == NULL)
176 perror("usnewlock (count_lock)");
177 (void) usinitlock(count_lock);
178 if ((wait_lock = usnewlock(shared_arena)) == NULL)
179 perror("usnewlock (wait_lock)");
180 dprintf(("arena start: %lx, arena size: %ld\n", (long) shared_arena, (long) usconfig(CONF_GETSIZE, shared_arena)));
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000181#endif
182#ifdef sun
183 lwp_setstkcache(STACKSIZE, NSTACKS);
184#endif
185#ifdef C_THREADS
186 cthread_init();
187#endif
188}
189
190/*
191 * Thread support.
192 */
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000193int start_new_thread _P2(func, void (*func) _P((void *)), arg, void *arg)
194{
195#ifdef sun
196 thread_t tid;
197#endif
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000198#if defined(__sgi) && defined(USE_DL)
199 long addr, size;
200 static int local_initialized = 0;
201#endif
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000202 int success = 0; /* init not needed when SOLARIS and */
203 /* C_THREADS implemented properly */
204
205 dprintf(("start_new_thread called\n"));
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000206 if (!initialized)
207 init_thread();
208#ifdef __sgi
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000209 switch (ussetlock(count_lock)) {
210 case 0: return 0;
211 case -1: perror("ussetlock (count_lock)");
212 }
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000213 if (maxpidindex >= MAXPROC)
214 success = -1;
215 else {
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000216#ifdef USE_DL
217 if (!local_initialized) {
218 if ((size = usconfig(CONF_INITSIZE, 64*1024)) < 0)
219 perror("usconfig - CONF_INITSIZE (check)");
220 if (usconfig(CONF_INITSIZE, size) < 0)
221 perror("usconfig - CONF_INITSIZE (reset)");
Sjoerd Mullender76ab5fe1993-01-13 12:49:46 +0000222 addr = (long) dl_getrange(size + HDR_SIZE);
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000223 dprintf(("trying to use addr %lx-%lx for sproc\n", addr, addr+size));
224 errno = 0;
225 if ((addr = usconfig(CONF_ATTACHADDR, addr)) < 0 && errno != 0)
226 perror("usconfig - CONF_ATTACHADDR (set)");
227 }
228#endif
229 if ((success = sproc(func, PR_SALL, arg)) < 0)
230 perror("sproc");
231#ifdef USE_DL
232 if (!local_initialized) {
233 if (usconfig(CONF_ATTACHADDR, addr) < 0) /* reset address */
234 perror("usconfig - CONF_ATTACHADDR (reset)");
235 local_initialized = 1;
236 }
237#endif
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000238 if (success >= 0) {
239 nthreads++;
240 pidlist[maxpidindex++] = success;
241 }
242 }
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000243 if (usunsetlock(count_lock) < 0)
244 perror("usunsetlock (count_lock)");
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000245#endif
246#ifdef SOLARIS
247 (void) thread_create(0, 0, func, arg, THREAD_NEW_LWP);
248#endif
249#ifdef sun
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000250 success = lwp_create(&tid, func, MINPRIO, 0, lwp_newstk(), 1, arg);
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000251#endif
252#ifdef C_THREADS
253 (void) cthread_fork(func, arg);
254#endif
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000255 return success < 0 ? 0 : 1;
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000256}
257
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000258static void do_exit_thread _P1(no_cleanup, int no_cleanup)
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000259{
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000260 dprintf(("exit_thread called\n"));
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000261 if (!initialized)
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000262 if (no_cleanup)
263 _exit(0);
264 else
265 exit(0);
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000266#ifdef __sgi
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000267 if (ussetlock(count_lock) < 0)
268 perror("ussetlock (count_lock)");
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000269 nthreads--;
270 if (getpid() == my_pid) {
271 /* main thread; wait for other threads to exit */
272 exiting = 1;
273 if (do_exit) {
274 int i;
275
276 /* notify other threads */
Sjoerd Mullenderd10d8291992-09-11 15:19:27 +0000277 if (nthreads >= 0) {
278 dprintf(("kill other threads\n"));
279 for (i = 0; i < maxpidindex; i++)
280 (void) kill(pidlist[i], SIGKILL);
281 _exit(exit_status);
282 }
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000283 }
284 waiting_for_threads = 1;
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000285 if (ussetlock(wait_lock) < 0)
286 perror("ussetlock (wait_lock)");
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000287 for (;;) {
288 if (nthreads < 0) {
289 dprintf(("really exit (%d)\n", exit_status));
290 if (no_cleanup)
291 _exit(exit_status);
292 else
293 exit(exit_status);
294 }
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000295 if (usunsetlock(count_lock) < 0)
296 perror("usunsetlock (count_lock)");
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000297 dprintf(("waiting for other threads (%d)\n", nthreads));
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000298 if (ussetlock(wait_lock) < 0)
299 perror("ussetlock (wait_lock)");
300 if (ussetlock(count_lock) < 0)
301 perror("ussetlock (count_lock)");
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000302 }
303 }
304 /* not the main thread */
305 if (waiting_for_threads) {
306 dprintf(("main thread is waiting\n"));
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000307 if (usunsetlock(wait_lock) < 0)
308 perror("usunsetlock (wait_lock)");
Sjoerd Mullenderd10d8291992-09-11 15:19:27 +0000309 } else if (do_exit)
310 (void) kill(my_pid, SIGUSR1);
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000311 if (usunsetlock(count_lock) < 0)
312 perror("usunsetlock (count_lock)");
Guido van Rossumff4949e1992-08-05 19:58:53 +0000313 _exit(0);
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000314#endif
315#ifdef SOLARIS
316 thread_exit();
317#endif
318#ifdef sun
319 lwp_destroy(SELF);
320#endif
321#ifdef C_THREADS
322 cthread_exit(0);
323#endif
324}
325
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000326void exit_thread _P0()
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000327{
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000328 do_exit_thread(0);
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000329}
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000330
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000331void _exit_thread _P0()
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000332{
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000333 do_exit_thread(1);
334}
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000335
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000336static void do_exit_prog _P2(status, int status, no_cleanup, int no_cleanup)
337{
338 dprintf(("exit_prog(%d) called\n", status));
339 if (!initialized)
340 if (no_cleanup)
341 _exit(status);
342 else
343 exit(status);
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000344#ifdef __sgi
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000345 do_exit = 1;
346 exit_status = status;
347 do_exit_thread(no_cleanup);
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000348#endif
349#ifdef sun
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000350 pod_exit(status);
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000351#endif
352}
353
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000354void exit_prog _P1(status, int status)
355{
356 do_exit_prog(status, 0);
357}
358
359void _exit_prog _P1(status, int status)
360{
361 do_exit_prog(status, 1);
362}
363
364/*
365 * Lock support.
366 */
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000367type_lock allocate_lock _P0()
368{
369#ifdef __sgi
370 ulock_t lock;
371#endif
372#ifdef sun
373 struct lock *lock;
374 extern char *malloc();
375#endif
376
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000377 dprintf(("allocate_lock called\n"));
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000378 if (!initialized)
379 init_thread();
380
381#ifdef __sgi
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000382 if ((lock = usnewlock(shared_arena)) == NULL)
383 perror("usnewlock");
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000384 (void) usinitlock(lock);
385#endif
386#ifdef sun
387 lock = (struct lock *) malloc(sizeof(struct lock));
388 lock->lock_locked = 0;
389 (void) mon_create(&lock->lock_monitor);
390 (void) cv_create(&lock->lock_condvar, lock->lock_monitor);
391#endif
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000392 dprintf(("allocate_lock() -> %lx\n", (long)lock));
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000393 return (type_lock) lock;
394}
395
396void free_lock _P1(lock, type_lock lock)
397{
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000398 dprintf(("free_lock(%lx) called\n", (long)lock));
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000399#ifdef __sgi
400 usfreelock((ulock_t) lock, shared_arena);
401#endif
402#ifdef sun
403 mon_destroy(((struct lock *) lock)->lock_monitor);
404 free((char *) lock);
405#endif
406}
407
408int acquire_lock _P2(lock, type_lock lock, waitflag, int waitflag)
409{
410 int success;
411
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000412 dprintf(("acquire_lock(%lx, %d) called\n", (long)lock, waitflag));
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000413#ifdef __sgi
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000414 errno = 0; /* clear it just in case */
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000415 if (waitflag)
416 success = ussetlock((ulock_t) lock);
417 else
418 success = uscsetlock((ulock_t) lock, 1); /* Try it once */
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000419 if (success < 0)
420 perror(waitflag ? "ussetlock" : "uscsetlock");
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000421#endif
422#ifdef sun
423 success = 0;
424
425 (void) mon_enter(((struct lock *) lock)->lock_monitor);
426 if (waitflag)
427 while (((struct lock *) lock)->lock_locked)
428 cv_wait(((struct lock *) lock)->lock_condvar);
429 if (!((struct lock *) lock)->lock_locked) {
430 success = 1;
431 ((struct lock *) lock)->lock_locked = 1;
432 }
433 cv_broadcast(((struct lock *) lock)->lock_condvar);
434 mon_exit(((struct lock *) lock)->lock_monitor);
435#endif
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000436 dprintf(("acquire_lock(%lx, %d) -> %d\n", (long)lock, waitflag, success));
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000437 return success;
438}
439
440void release_lock _P1(lock, type_lock lock)
441{
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000442 dprintf(("release_lock(%lx) called\n", (long)lock));
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000443#ifdef __sgi
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000444 if (usunsetlock((ulock_t) lock) < 0)
445 perror("usunsetlock");
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000446#endif
447#ifdef sun
448 (void) mon_enter(((struct lock *) lock)->lock_monitor);
449 ((struct lock *) lock)->lock_locked = 0;
450 cv_broadcast(((struct lock *) lock)->lock_condvar);
451 mon_exit(((struct lock *) lock)->lock_monitor);
452#endif
453}
454
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000455/*
456 * Semaphore support.
457 */
458type_sema allocate_sema _P1(value, int value)
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000459{
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000460#ifdef __sgi
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000461 usema_t *sema;
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000462#endif
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000463
464 dprintf(("allocate_sema called\n"));
Sjoerd Mullenderd10d8291992-09-11 15:19:27 +0000465 if (!initialized)
466 init_thread();
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000467
468#ifdef __sgi
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000469 if ((sema = usnewsema(shared_arena, value)) == NULL)
470 perror("usnewsema");
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000471 dprintf(("allocate_sema() -> %lx\n", (long) sema));
472 return (type_sema) sema;
473#endif
474}
475
476void free_sema _P1(sema, type_sema sema)
477{
478 dprintf(("free_sema(%lx) called\n", (long) sema));
479#ifdef __sgi
480 usfreesema((usema_t *) sema, shared_arena);
481#endif
482}
483
484void down_sema _P1(sema, type_sema sema)
485{
486 dprintf(("down_sema(%lx) called\n", (long) sema));
487#ifdef __sgi
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000488 if (uspsema((usema_t *) sema) < 0)
489 perror("uspsema");
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000490#endif
491 dprintf(("down_sema(%lx) return\n", (long) sema));
492}
493
494void up_sema _P1(sema, type_sema sema)
495{
496 dprintf(("up_sema(%lx)\n", (long) sema));
497#ifdef __sgi
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000498 if (usvsema((usema_t *) sema) < 0)
499 perror("usvsema");
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000500#endif
501}