Guido van Rossum | 34679b7 | 1993-01-26 13:33:44 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | 6d023c9 | 1995-01-04 19:12:13 +0000 | [diff] [blame] | 2 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 3 | The Netherlands. |
Guido van Rossum | 34679b7 | 1993-01-26 13:33:44 +0000 | [diff] [blame] | 4 | |
| 5 | All Rights Reserved |
| 6 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
Guido van Rossum | 34679b7 | 1993-01-26 13:33:44 +0000 | [diff] [blame] | 9 | provided that the above copyright notice appear in all copies and that |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 10 | both that copyright notice and this permission notice appear in |
Guido van Rossum | 34679b7 | 1993-01-26 13:33:44 +0000 | [diff] [blame] | 11 | supporting documentation, and that the names of Stichting Mathematisch |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 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 |
| 15 | permission. |
Guido van Rossum | 34679b7 | 1993-01-26 13:33:44 +0000 | [diff] [blame] | 16 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 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. |
| 20 | |
| 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. |
Guido van Rossum | 34679b7 | 1993-01-26 13:33:44 +0000 | [diff] [blame] | 29 | |
| 30 | ******************************************************************/ |
| 31 | |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 32 | /* Thread package. |
| 33 | This is intended to be usable independently from Python. |
| 34 | The implementation for system foobar is in a file thread_foobar.h |
| 35 | which is included by this file dependent on config settings. |
| 36 | Stuff shared by all thread_*.h files is collected here. */ |
| 37 | |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 38 | #include "config.h" |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 39 | |
Guido van Rossum | f261526 | 1998-12-04 18:50:20 +0000 | [diff] [blame] | 40 | /* config.h may or may not define DL_IMPORT */ |
| 41 | #ifndef DL_IMPORT /* declarations for DLL import/export */ |
| 42 | #define DL_IMPORT(RTYPE) RTYPE |
| 43 | #endif |
| 44 | |
Guido van Rossum | 2571cc8 | 1999-04-07 16:07:23 +0000 | [diff] [blame] | 45 | #ifndef DONT_HAVE_STDIO_H |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 46 | #include <stdio.h> |
Guido van Rossum | 2571cc8 | 1999-04-07 16:07:23 +0000 | [diff] [blame] | 47 | #endif |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 48 | |
| 49 | #ifdef HAVE_STDLIB_H |
| 50 | #include <stdlib.h> |
| 51 | #else |
Guido van Rossum | 2571cc8 | 1999-04-07 16:07:23 +0000 | [diff] [blame] | 52 | #ifdef Py_DEBUG |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 53 | extern char *getenv(); |
| 54 | #endif |
Guido van Rossum | 2571cc8 | 1999-04-07 16:07:23 +0000 | [diff] [blame] | 55 | #endif |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 56 | |
Guido van Rossum | 80bb965 | 1996-12-05 23:27:02 +0000 | [diff] [blame] | 57 | #ifdef HAVE_UNISTD_H |
| 58 | #include <unistd.h> |
| 59 | #endif |
| 60 | |
Guido van Rossum | 64f9105 | 1997-05-22 20:41:59 +0000 | [diff] [blame] | 61 | #ifdef __DGUX |
| 62 | #define _USING_POSIX4A_DRAFT6 |
| 63 | #endif |
| 64 | |
Guido van Rossum | d11bfdd | 1997-04-29 21:48:34 +0000 | [diff] [blame] | 65 | #ifdef __sgi |
| 66 | #ifndef HAVE_PTHREAD_H /* XXX Need to check in configure.in */ |
| 67 | #undef _POSIX_THREADS |
| 68 | #endif |
| 69 | #endif |
| 70 | |
Guido van Rossum | 49b5606 | 1998-10-01 20:42:43 +0000 | [diff] [blame] | 71 | #include "pythread.h" |
Guido van Rossum | 1984f1e | 1992-08-04 12:41:02 +0000 | [diff] [blame] | 72 | |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 73 | #ifdef __ksr__ |
| 74 | #define _POSIX_THREADS |
Guido van Rossum | f9f2e82 | 1992-08-17 08:59:08 +0000 | [diff] [blame] | 75 | #endif |
| 76 | |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 77 | #ifndef _POSIX_THREADS |
| 78 | |
Guido van Rossum | 1984f1e | 1992-08-04 12:41:02 +0000 | [diff] [blame] | 79 | #ifdef __sgi |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 80 | #define SGI_THREADS |
Guido van Rossum | 1984f1e | 1992-08-04 12:41:02 +0000 | [diff] [blame] | 81 | #endif |
Guido van Rossum | 1984f1e | 1992-08-04 12:41:02 +0000 | [diff] [blame] | 82 | |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 83 | #ifdef HAVE_THREAD_H |
| 84 | #define SOLARIS_THREADS |
| 85 | #endif |
Guido van Rossum | 1984f1e | 1992-08-04 12:41:02 +0000 | [diff] [blame] | 86 | |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 87 | #if defined(sun) && !defined(SOLARIS_THREADS) |
| 88 | #define SUN_LWP |
| 89 | #endif |
| 90 | |
Guido van Rossum | 095249f | 2000-04-24 15:06:51 +0000 | [diff] [blame] | 91 | #ifdef __MWERKS__ |
| 92 | #define _POSIX_THREADS |
| 93 | #endif |
| 94 | |
Sjoerd Mullender | 66bca32 | 1993-12-03 16:54:45 +0000 | [diff] [blame] | 95 | #endif /* _POSIX_THREADS */ |
Guido van Rossum | 1984f1e | 1992-08-04 12:41:02 +0000 | [diff] [blame] | 96 | |
| 97 | #ifdef __STDC__ |
| 98 | #define _P(args) args |
| 99 | #define _P0() (void) |
| 100 | #define _P1(v,t) (t) |
| 101 | #define _P2(v1,t1,v2,t2) (t1,t2) |
| 102 | #else |
| 103 | #define _P(args) () |
| 104 | #define _P0() () |
| 105 | #define _P1(v,t) (v) t; |
| 106 | #define _P2(v1,t1,v2,t2) (v1,v2) t1; t2; |
Sjoerd Mullender | 66bca32 | 1993-12-03 16:54:45 +0000 | [diff] [blame] | 107 | #endif /* __STDC__ */ |
Guido van Rossum | 1984f1e | 1992-08-04 12:41:02 +0000 | [diff] [blame] | 108 | |
Guido van Rossum | 408027e | 1996-12-30 16:17:54 +0000 | [diff] [blame] | 109 | #ifdef Py_DEBUG |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 110 | static int thread_debug = 0; |
| 111 | #define dprintf(args) ((thread_debug & 1) && printf args) |
| 112 | #define d2printf(args) ((thread_debug & 8) && printf args) |
| 113 | #else |
| 114 | #define dprintf(args) |
| 115 | #define d2printf(args) |
| 116 | #endif |
| 117 | |
Guido van Rossum | 1984f1e | 1992-08-04 12:41:02 +0000 | [diff] [blame] | 118 | static int initialized; |
| 119 | |
Guido van Rossum | 65d5b57 | 1998-12-21 19:32:43 +0000 | [diff] [blame] | 120 | static void PyThread__init_thread(); /* Forward */ |
Sjoerd Mullender | aee8bc1 | 1992-09-02 11:25:37 +0000 | [diff] [blame] | 121 | |
Guido van Rossum | 65d5b57 | 1998-12-21 19:32:43 +0000 | [diff] [blame] | 122 | void PyThread_init_thread _P0() |
Sjoerd Mullender | aee8bc1 | 1992-09-02 11:25:37 +0000 | [diff] [blame] | 123 | { |
Guido van Rossum | 408027e | 1996-12-30 16:17:54 +0000 | [diff] [blame] | 124 | #ifdef Py_DEBUG |
Sjoerd Mullender | 66bca32 | 1993-12-03 16:54:45 +0000 | [diff] [blame] | 125 | char *p = getenv("THREADDEBUG"); |
| 126 | |
| 127 | if (p) { |
| 128 | if (*p) |
| 129 | thread_debug = atoi(p); |
| 130 | else |
| 131 | thread_debug = 1; |
| 132 | } |
Guido van Rossum | 408027e | 1996-12-30 16:17:54 +0000 | [diff] [blame] | 133 | #endif /* Py_DEBUG */ |
Sjoerd Mullender | aee8bc1 | 1992-09-02 11:25:37 +0000 | [diff] [blame] | 134 | if (initialized) |
| 135 | return; |
| 136 | initialized = 1; |
Guido van Rossum | 65d5b57 | 1998-12-21 19:32:43 +0000 | [diff] [blame] | 137 | dprintf(("PyThread_init_thread called\n")); |
| 138 | PyThread__init_thread(); |
Sjoerd Mullender | aee8bc1 | 1992-09-02 11:25:37 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 141 | #ifdef SGI_THREADS |
| 142 | #include "thread_sgi.h" |
Sjoerd Mullender | 66bca32 | 1993-12-03 16:54:45 +0000 | [diff] [blame] | 143 | #endif |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 144 | |
| 145 | #ifdef SOLARIS_THREADS |
| 146 | #include "thread_solaris.h" |
| 147 | #endif |
| 148 | |
| 149 | #ifdef SUN_LWP |
| 150 | #include "thread_lwp.h" |
| 151 | #endif |
| 152 | |
Guido van Rossum | 07bd90e | 2000-05-08 13:41:38 +0000 | [diff] [blame] | 153 | #ifdef _GNU_PTH |
| 154 | #include "thread_pth.h" |
| 155 | #else |
Sjoerd Mullender | 66bca32 | 1993-12-03 16:54:45 +0000 | [diff] [blame] | 156 | #ifdef _POSIX_THREADS |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 157 | #include "thread_pthread.h" |
Sjoerd Mullender | e893412 | 1993-01-13 12:08:48 +0000 | [diff] [blame] | 158 | #endif |
Guido van Rossum | 07bd90e | 2000-05-08 13:41:38 +0000 | [diff] [blame] | 159 | #endif |
Guido van Rossum | f9f2e82 | 1992-08-17 08:59:08 +0000 | [diff] [blame] | 160 | |
Guido van Rossum | 1984f1e | 1992-08-04 12:41:02 +0000 | [diff] [blame] | 161 | #ifdef C_THREADS |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 162 | #include "thread_cthread.h" |
Guido van Rossum | 1984f1e | 1992-08-04 12:41:02 +0000 | [diff] [blame] | 163 | #endif |
Guido van Rossum | f9f2e82 | 1992-08-17 08:59:08 +0000 | [diff] [blame] | 164 | |
Guido van Rossum | c3f82b6 | 1995-01-17 16:29:31 +0000 | [diff] [blame] | 165 | #ifdef NT_THREADS |
| 166 | #include "thread_nt.h" |
| 167 | #endif |
| 168 | |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 169 | #ifdef OS2_THREADS |
| 170 | #include "thread_os2.h" |
| 171 | #endif |
| 172 | |
Guido van Rossum | 1a8791e | 1998-08-04 22:46:29 +0000 | [diff] [blame] | 173 | #ifdef BEOS_THREADS |
| 174 | #include "thread_beos.h" |
| 175 | #endif |
| 176 | |
Guido van Rossum | 2571cc8 | 1999-04-07 16:07:23 +0000 | [diff] [blame] | 177 | #ifdef WINCE_THREADS |
| 178 | #include "thread_wince.h" |
| 179 | #endif |
| 180 | |
Guido van Rossum | f9f2e82 | 1992-08-17 08:59:08 +0000 | [diff] [blame] | 181 | /* |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 182 | #ifdef FOOBAR_THREADS |
| 183 | #include "thread_foobar.h" |
Guido van Rossum | 1984f1e | 1992-08-04 12:41:02 +0000 | [diff] [blame] | 184 | #endif |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 185 | */ |