1 /***********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
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 ******************************************************************/
28 #include </usr/include/thread.h>
34 static void _init_thread
_P0()
42 void (*func
) _P((void *));
46 static void *new_func
_P1(funcarg
, void *funcarg
)
48 void (*func
) _P((void *));
51 func
= ((struct func_arg
*) funcarg
)->func
;
52 arg
= ((struct func_arg
*) funcarg
)->arg
;
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"));
68 funcarg
= (struct func_arg
*) malloc(sizeof(struct func_arg
));
71 if (thr_create(0, 0, new_func
, funcarg
, THR_DETACHED
, 0)) {
73 free((void *) funcarg
);
76 return success
< 0 ? 0 : 1;
79 long get_thread_ident
_P0()
86 static void do_exit_thread
_P1(no_cleanup
, int no_cleanup
)
88 dprintf(("exit_thread called\n"));
97 void exit_thread
_P0()
102 void _exit_thread
_P0()
108 static void do_exit_prog
_P2(status
, int status
, no_cleanup
, int no_cleanup
)
110 dprintf(("exit_prog(%d) called\n", 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 */
136 type_lock allocate_lock
_P0()
140 dprintf(("allocate_lock called\n"));
144 lock
= (mutex_t
*) malloc(sizeof(mutex_t
));
145 if (mutex_init(lock
, USYNC_THREAD
, 0)) {
146 perror("mutex_init");
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
);
161 int acquire_lock
_P2(lock
, type_lock lock
, waitflag
, int waitflag
)
165 dprintf(("acquire_lock(%lx, %d) called\n", (long)lock
, waitflag
));
167 success
= mutex_lock((mutex_t
*) lock
);
169 success
= mutex_trylock((mutex_t
*) lock
);
171 perror(waitflag
? "mutex_lock" : "mutex_trylock");
173 success
= !success
; /* solaris does it the other way round */
174 dprintf(("acquire_lock(%lx, %d) -> %d\n", (long)lock
, waitflag
, 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");
188 type_sema allocate_sema
_P1(value
, int value
)
191 dprintf(("allocate_sema called\n"));
195 sema
= (sema_t
*) malloc(sizeof(sema_t
));
196 if (sema_init(sema
, value
, USYNC_THREAD
, 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");
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
))
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
))