Don't reference removed files in Makefile
[python/dscho.git] / Python / thread_lwp.h
bloba4e943f008f459b51e71124e4b29fb1a0aef851b
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 <lwp/lwp.h>
27 #include <lwp/stackdep.h>
29 #define STACKSIZE 1000 /* stacksize for a thread */
30 #define NSTACKS 2 /* # stacks to be put in cache initialy */
32 struct lock {
33 int lock_locked;
34 cv_t lock_condvar;
35 mon_t lock_monitor;
40 * Initialization.
42 static void _init_thread _P0()
44 lwp_setstkcache(STACKSIZE, NSTACKS);
48 * Thread support.
52 int start_new_thread _P2(func, void (*func) _P((void *)), arg, void *arg)
54 thread_t tid;
55 int success;
56 dprintf(("start_new_thread called\n"));
57 if (!initialized)
58 init_thread();
59 success = lwp_create(&tid, func, MINPRIO, 0, lwp_newstk(), 1, arg);
60 return success < 0 ? 0 : 1;
63 long get_thread_ident _P0()
65 thread_t tid;
66 if (!initialized)
67 init_thread();
68 if (lwp_self(&tid) < 0)
69 return -1;
70 return tid.thread_id;
73 static void do_exit_thread _P1(no_cleanup, int no_cleanup)
75 dprintf(("exit_thread called\n"));
76 if (!initialized)
77 if (no_cleanup)
78 _exit(0);
79 else
80 exit(0);
81 lwp_destroy(SELF);
84 void exit_thread _P0()
86 do_exit_thread(0);
89 void _exit_thread _P0()
91 do_exit_thread(1);
94 #ifndef NO_EXIT_PROG
95 static void do_exit_prog _P2(status, int status, no_cleanup, int no_cleanup)
97 dprintf(("exit_prog(%d) called\n", status));
98 if (!initialized)
99 if (no_cleanup)
100 _exit(status);
101 else
102 exit(status);
103 pod_exit(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 */
118 * Lock support.
120 type_lock allocate_lock _P0()
122 struct lock *lock;
123 extern char *malloc();
125 dprintf(("allocate_lock called\n"));
126 if (!initialized)
127 init_thread();
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);
141 free((char *) lock);
144 int acquire_lock _P2(lock, type_lock lock, waitflag, int waitflag)
146 int success;
148 dprintf(("acquire_lock(%lx, %d) called\n", (long)lock, waitflag));
149 success = 0;
151 (void) mon_enter(((struct lock *) lock)->lock_monitor);
152 if (waitflag)
153 while (((struct lock *) lock)->lock_locked)
154 cv_wait(((struct lock *) lock)->lock_condvar);
155 if (!((struct lock *) lock)->lock_locked) {
156 success = 1;
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));
162 return 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);
175 * Semaphore support.
177 type_sema allocate_sema _P1(value, int value)
179 type_sema sema = 0;
180 dprintf(("allocate_sema called\n"));
181 if (!initialized)
182 init_thread();
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));