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 ******************************************************************/
27 #include <lwp/stackdep.h>
29 #define STACKSIZE 1000 /* stacksize for a thread */
30 #define NSTACKS 2 /* # stacks to be put in cache initialy */
42 static void _init_thread
_P0()
44 lwp_setstkcache(STACKSIZE
, NSTACKS
);
52 int start_new_thread
_P2(func
, void (*func
) _P((void *)), arg
, void *arg
)
56 dprintf(("start_new_thread called\n"));
59 success
= lwp_create(&tid
, func
, MINPRIO
, 0, lwp_newstk(), 1, arg
);
60 return success
< 0 ? 0 : 1;
63 long get_thread_ident
_P0()
68 if (lwp_self(&tid
) < 0)
73 static void do_exit_thread
_P1(no_cleanup
, int no_cleanup
)
75 dprintf(("exit_thread called\n"));
84 void exit_thread
_P0()
89 void _exit_thread
_P0()
95 static void do_exit_prog
_P2(status
, int status
, no_cleanup
, int no_cleanup
)
97 dprintf(("exit_prog(%d) called\n", status
));
106 void exit_prog
_P1(status
, int status
)
108 do_exit_prog(status
, 0);
111 void _exit_prog
_P1(status
, int status
)
113 do_exit_prog(status
, 1);
115 #endif /* NO_EXIT_PROG */
120 type_lock allocate_lock
_P0()
123 extern char *malloc();
125 dprintf(("allocate_lock called\n"));
129 lock
= (struct lock
*) malloc(sizeof(struct lock
));
130 lock
->lock_locked
= 0;
131 (void) mon_create(&lock
->lock_monitor
);
132 (void) cv_create(&lock
->lock_condvar
, lock
->lock_monitor
);
133 dprintf(("allocate_lock() -> %lx\n", (long)lock
));
134 return (type_lock
) lock
;
137 void free_lock
_P1(lock
, type_lock lock
)
139 dprintf(("free_lock(%lx) called\n", (long)lock
));
140 mon_destroy(((struct lock
*) lock
)->lock_monitor
);
144 int acquire_lock
_P2(lock
, type_lock lock
, waitflag
, int waitflag
)
148 dprintf(("acquire_lock(%lx, %d) called\n", (long)lock
, waitflag
));
151 (void) mon_enter(((struct lock
*) lock
)->lock_monitor
);
153 while (((struct lock
*) lock
)->lock_locked
)
154 cv_wait(((struct lock
*) lock
)->lock_condvar
);
155 if (!((struct lock
*) lock
)->lock_locked
) {
157 ((struct lock
*) lock
)->lock_locked
= 1;
159 cv_broadcast(((struct lock
*) lock
)->lock_condvar
);
160 mon_exit(((struct lock
*) lock
)->lock_monitor
);
161 dprintf(("acquire_lock(%lx, %d) -> %d\n", (long)lock
, waitflag
, success
));
165 void release_lock
_P1(lock
, type_lock lock
)
167 dprintf(("release_lock(%lx) called\n", (long)lock
));
168 (void) mon_enter(((struct lock
*) lock
)->lock_monitor
);
169 ((struct lock
*) lock
)->lock_locked
= 0;
170 cv_broadcast(((struct lock
*) lock
)->lock_condvar
);
171 mon_exit(((struct lock
*) lock
)->lock_monitor
);
177 type_sema allocate_sema
_P1(value
, int value
)
180 dprintf(("allocate_sema called\n"));
184 dprintf(("allocate_sema() -> %lx\n", (long) sema
));
185 return (type_sema
) sema
;
188 void free_sema
_P1(sema
, type_sema sema
)
190 dprintf(("free_sema(%lx) called\n", (long) sema
));
193 void down_sema
_P1(sema
, type_sema sema
)
195 dprintf(("down_sema(%lx) called\n", (long) sema
));
196 dprintf(("down_sema(%lx) return\n", (long) sema
));
199 void up_sema
_P1(sema
, type_sema sema
)
201 dprintf(("up_sema(%lx)\n", (long) sema
));