blob: e2c75e3b07bccc4c9865b1d127f7ad67af48d687 [file] [log] [blame]
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +00001/***********************************************************
Guido van Rossum6d023c91995-01-04 19:12:13 +00002Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3The Netherlands.
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +00004
5 All Rights Reserved
6
Guido van Rossumd266eb41996-10-25 14:44:06 +00007Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +00009provided that the above copyright notice appear in all copies and that
Guido van Rossumd266eb41996-10-25 14:44:06 +000010both that copyright notice and this permission notice appear in
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000011supporting documentation, and that the names of Stichting Mathematisch
Guido van Rossumd266eb41996-10-25 14:44:06 +000012Centrum or CWI or Corporation for National Research Initiatives or
13CNRI not be used in advertising or publicity pertaining to
14distribution of the software without specific, written prior
15permission.
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000016
Guido van Rossumd266eb41996-10-25 14:44:06 +000017While CWI is the initial source for this software, a modified version
18is made available by the Corporation for National Research Initiatives
19(CNRI) at the Internet address ftp://ftp.python.org.
20
21STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28PERFORMANCE OF THIS SOFTWARE.
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000029
30******************************************************************/
31
32/*
33 * Initialization.
34 */
Guido van Rossum65d5b571998-12-21 19:32:43 +000035static void PyThread__init_thread _P0()
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000036{
37}
38
39/*
40 * Thread support.
41 */
Guido van Rossum65d5b571998-12-21 19:32:43 +000042int PyThread_start_new_thread _P2(func, void (*func) _P((void *)), arg, void *arg)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000043{
44 int success = 0; /* init not needed when SOLARIS_THREADS and */
45 /* C_THREADS implemented properly */
46
Guido van Rossum65d5b571998-12-21 19:32:43 +000047 dprintf(("PyThread_start_new_thread called\n"));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000048 if (!initialized)
Guido van Rossum65d5b571998-12-21 19:32:43 +000049 PyThread_init_thread();
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000050 return success < 0 ? 0 : 1;
51}
52
Guido van Rossum65d5b571998-12-21 19:32:43 +000053long PyThread_get_thread_ident _P0()
Guido van Rossume944da81994-05-23 12:43:41 +000054{
55 if (!initialized)
Guido van Rossum65d5b571998-12-21 19:32:43 +000056 PyThread_init_thread();
Guido van Rossume944da81994-05-23 12:43:41 +000057}
58
Guido van Rossum65d5b571998-12-21 19:32:43 +000059static void do_PyThread_exit_thread _P1(no_cleanup, int no_cleanup)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000060{
Guido van Rossum65d5b571998-12-21 19:32:43 +000061 dprintf(("PyThread_exit_thread called\n"));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000062 if (!initialized)
63 if (no_cleanup)
64 _exit(0);
65 else
66 exit(0);
67}
68
Guido van Rossum65d5b571998-12-21 19:32:43 +000069void PyThread_exit_thread _P0()
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000070{
Guido van Rossum65d5b571998-12-21 19:32:43 +000071 do_PyThread_exit_thread(0);
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000072}
73
Guido van Rossum65d5b571998-12-21 19:32:43 +000074void PyThread__exit_thread _P0()
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000075{
Guido van Rossum65d5b571998-12-21 19:32:43 +000076 do_PyThread_exit_thread(1);
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000077}
78
79#ifndef NO_EXIT_PROG
Guido van Rossum65d5b571998-12-21 19:32:43 +000080static void do_PyThread_exit_prog _P2(status, int status, no_cleanup, int no_cleanup)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000081{
Guido van Rossum65d5b571998-12-21 19:32:43 +000082 dprintf(("PyThread_exit_prog(%d) called\n", status));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000083 if (!initialized)
84 if (no_cleanup)
85 _exit(status);
86 else
87 exit(status);
88}
89
Guido van Rossum65d5b571998-12-21 19:32:43 +000090void PyThread_exit_prog _P1(status, int status)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000091{
Guido van Rossum65d5b571998-12-21 19:32:43 +000092 do_PyThread_exit_prog(status, 0);
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000093}
94
Guido van Rossum65d5b571998-12-21 19:32:43 +000095void PyThread__exit_prog _P1(status, int status)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000096{
Guido van Rossum65d5b571998-12-21 19:32:43 +000097 do_PyThread_exit_prog(status, 1);
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000098}
99#endif /* NO_EXIT_PROG */
100
101/*
102 * Lock support.
103 */
Guido van Rossum65d5b571998-12-21 19:32:43 +0000104PyThread_type_lock PyThread_allocate_lock _P0()
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000105{
106
Guido van Rossum65d5b571998-12-21 19:32:43 +0000107 dprintf(("PyThread_allocate_lock called\n"));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000108 if (!initialized)
Guido van Rossum65d5b571998-12-21 19:32:43 +0000109 PyThread_init_thread();
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000110
Guido van Rossum65d5b571998-12-21 19:32:43 +0000111 dprintf(("PyThread_allocate_lock() -> %lx\n", (long)lock));
112 return (PyThread_type_lock) lock;
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000113}
114
Guido van Rossum65d5b571998-12-21 19:32:43 +0000115void PyThread_free_lock _P1(lock, PyThread_type_lock lock)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000116{
Guido van Rossum65d5b571998-12-21 19:32:43 +0000117 dprintf(("PyThread_free_lock(%lx) called\n", (long)lock));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000118}
119
Guido van Rossum65d5b571998-12-21 19:32:43 +0000120int PyThread_acquire_lock _P2(lock, PyThread_type_lock lock, waitflag, int waitflag)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000121{
122 int success;
123
Guido van Rossum65d5b571998-12-21 19:32:43 +0000124 dprintf(("PyThread_acquire_lock(%lx, %d) called\n", (long)lock, waitflag));
125 dprintf(("PyThread_acquire_lock(%lx, %d) -> %d\n", (long)lock, waitflag, success));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000126 return success;
127}
128
Guido van Rossum65d5b571998-12-21 19:32:43 +0000129void PyThread_release_lock _P1(lock, PyThread_type_lock lock)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000130{
Guido van Rossum65d5b571998-12-21 19:32:43 +0000131 dprintf(("PyThread_release_lock(%lx) called\n", (long)lock));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000132}
133
134/*
135 * Semaphore support.
136 */
Guido van Rossum65d5b571998-12-21 19:32:43 +0000137PyThread_type_sema PyThread_allocate_sema _P1(value, int value)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000138{
Guido van Rossum65d5b571998-12-21 19:32:43 +0000139 dprintf(("PyThread_allocate_sema called\n"));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000140 if (!initialized)
Guido van Rossum65d5b571998-12-21 19:32:43 +0000141 PyThread_init_thread();
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000142
Guido van Rossum65d5b571998-12-21 19:32:43 +0000143 dprintf(("PyThread_allocate_sema() -> %lx\n", (long) sema));
144 return (PyThread_type_sema) sema;
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000145}
146
Guido van Rossum65d5b571998-12-21 19:32:43 +0000147void PyThread_free_sema _P1(sema, PyThread_type_sema sema)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000148{
Guido van Rossum65d5b571998-12-21 19:32:43 +0000149 dprintf(("PyThread_free_sema(%lx) called\n", (long) sema));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000150}
151
Guido van Rossum65d5b571998-12-21 19:32:43 +0000152int PyThread_down_sema _P2(sema, PyThread_type_sema sema, waitflag, int waitflag)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000153{
Guido van Rossum65d5b571998-12-21 19:32:43 +0000154 dprintf(("PyThread_down_sema(%lx, %d) called\n", (long) sema, waitflag));
155 dprintf(("PyThread_down_sema(%lx) return\n", (long) sema));
Guido van Rossumcf1474b1996-10-08 14:17:53 +0000156 return -1;
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000157}
158
Guido van Rossum65d5b571998-12-21 19:32:43 +0000159void PyThread_up_sema _P1(sema, PyThread_type_sema sema)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000160{
Guido van Rossum65d5b571998-12-21 19:32:43 +0000161 dprintf(("PyThread_up_sema(%lx)\n", (long) sema));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000162}