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 or Corporation for National Research Initiatives or
13 CNRI not be used in advertising or publicity pertaining to
14 distribution of the software without specific, written prior
17 While CWI is the initial source for this software, a modified version
18 is made available by the Corporation for National Research Initiatives
19 (CNRI) at the Internet address ftp://ftp.python.org.
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28 PERFORMANCE OF THIS SOFTWARE.
30 ******************************************************************/
34 #include <lwp/stackdep.h>
36 #define STACKSIZE 1000 /* stacksize for a thread */
37 #define NSTACKS 2 /* # stacks to be put in cache initialy */
49 static void PyThread__init_thread
_P0()
51 lwp_setstkcache(STACKSIZE
, NSTACKS
);
59 int PyThread_start_new_thread
_P2(func
, void (*func
) _P((void *)), arg
, void *arg
)
63 dprintf(("PyThread_start_new_thread called\n"));
65 PyThread_init_thread();
66 success
= lwp_create(&tid
, func
, MINPRIO
, 0, lwp_newstk(), 1, arg
);
67 return success
< 0 ? 0 : 1;
70 long PyThread_get_thread_ident
_P0()
74 PyThread_init_thread();
75 if (lwp_self(&tid
) < 0)
80 static void do_PyThread_exit_thread
_P1(no_cleanup
, int no_cleanup
)
82 dprintf(("PyThread_exit_thread called\n"));
91 void PyThread_exit_thread
_P0()
93 do_PyThread_exit_thread(0);
96 void PyThread__exit_thread
_P0()
98 do_PyThread_exit_thread(1);
102 static void do_PyThread_exit_prog
_P2(status
, int status
, no_cleanup
, int no_cleanup
)
104 dprintf(("PyThread_exit_prog(%d) called\n", status
));
113 void PyThread_exit_prog
_P1(status
, int status
)
115 do_PyThread_exit_prog(status
, 0);
118 void PyThread__exit_prog
_P1(status
, int status
)
120 do_PyThread_exit_prog(status
, 1);
122 #endif /* NO_EXIT_PROG */
127 PyThread_type_lock PyThread_allocate_lock
_P0()
130 extern char *malloc();
132 dprintf(("PyThread_allocate_lock called\n"));
134 PyThread_init_thread();
136 lock
= (struct lock
*) malloc(sizeof(struct lock
));
137 lock
->lock_locked
= 0;
138 (void) mon_create(&lock
->lock_monitor
);
139 (void) cv_create(&lock
->lock_condvar
, lock
->lock_monitor
);
140 dprintf(("PyThread_allocate_lock() -> %lx\n", (long)lock
));
141 return (PyThread_type_lock
) lock
;
144 void PyThread_free_lock
_P1(lock
, PyThread_type_lock lock
)
146 dprintf(("PyThread_free_lock(%lx) called\n", (long)lock
));
147 mon_destroy(((struct lock
*) lock
)->lock_monitor
);
151 int PyThread_acquire_lock
_P2(lock
, PyThread_type_lock lock
, waitflag
, int waitflag
)
155 dprintf(("PyThread_acquire_lock(%lx, %d) called\n", (long)lock
, waitflag
));
158 (void) mon_enter(((struct lock
*) lock
)->lock_monitor
);
160 while (((struct lock
*) lock
)->lock_locked
)
161 cv_wait(((struct lock
*) lock
)->lock_condvar
);
162 if (!((struct lock
*) lock
)->lock_locked
) {
164 ((struct lock
*) lock
)->lock_locked
= 1;
166 cv_broadcast(((struct lock
*) lock
)->lock_condvar
);
167 mon_exit(((struct lock
*) lock
)->lock_monitor
);
168 dprintf(("PyThread_acquire_lock(%lx, %d) -> %d\n", (long)lock
, waitflag
, success
));
172 void PyThread_release_lock
_P1(lock
, PyThread_type_lock lock
)
174 dprintf(("PyThread_release_lock(%lx) called\n", (long)lock
));
175 (void) mon_enter(((struct lock
*) lock
)->lock_monitor
);
176 ((struct lock
*) lock
)->lock_locked
= 0;
177 cv_broadcast(((struct lock
*) lock
)->lock_condvar
);
178 mon_exit(((struct lock
*) lock
)->lock_monitor
);
184 PyThread_type_sema PyThread_allocate_sema
_P1(value
, int value
)
186 PyThread_type_sema sema
= 0;
187 dprintf(("PyThread_allocate_sema called\n"));
189 PyThread_init_thread();
191 dprintf(("PyThread_allocate_sema() -> %lx\n", (long) sema
));
192 return (PyThread_type_sema
) sema
;
195 void PyThread_free_sema
_P1(sema
, PyThread_type_sema sema
)
197 dprintf(("PyThread_free_sema(%lx) called\n", (long) sema
));
200 int PyThread_down_sema
_P2(sema
, PyThread_type_sema sema
, waitflag
, int waitflag
)
202 dprintf(("PyThread_down_sema(%lx, %d) called\n", (long) sema
, waitflag
));
203 dprintf(("PyThread_down_sema(%lx) return\n", (long) sema
));
207 void PyThread_up_sema
_P1(sema
, PyThread_type_sema sema
)
209 dprintf(("PyThread_up_sema(%lx)\n", (long) sema
));