Added all documentation.
[python/dscho.git] / Python / thread.c
blob0f46223499ccbe379211188514f5c814af159cb1
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 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.
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 ******************************************************************/
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. */
38 #include "config.h"
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
45 #ifndef DONT_HAVE_STDIO_H
46 #include <stdio.h>
47 #endif
49 #ifdef HAVE_STDLIB_H
50 #include <stdlib.h>
51 #else
52 #ifdef Py_DEBUG
53 extern char *getenv();
54 #endif
55 #endif
57 #ifdef HAVE_UNISTD_H
58 #include <unistd.h>
59 #endif
61 #ifdef __DGUX
62 #define _USING_POSIX4A_DRAFT6
63 #endif
65 #ifdef __sgi
66 #ifndef HAVE_PTHREAD_H /* XXX Need to check in configure.in */
67 #undef _POSIX_THREADS
68 #endif
69 #endif
71 #include "pythread.h"
73 #ifdef __ksr__
74 #define _POSIX_THREADS
75 #endif
77 #ifndef _POSIX_THREADS
79 #ifdef __sgi
80 #define SGI_THREADS
81 #endif
83 #ifdef HAVE_THREAD_H
84 #define SOLARIS_THREADS
85 #endif
87 #if defined(sun) && !defined(SOLARIS_THREADS)
88 #define SUN_LWP
89 #endif
91 #endif /* _POSIX_THREADS */
93 #ifdef __STDC__
94 #define _P(args) args
95 #define _P0() (void)
96 #define _P1(v,t) (t)
97 #define _P2(v1,t1,v2,t2) (t1,t2)
98 #else
99 #define _P(args) ()
100 #define _P0() ()
101 #define _P1(v,t) (v) t;
102 #define _P2(v1,t1,v2,t2) (v1,v2) t1; t2;
103 #endif /* __STDC__ */
105 #ifdef Py_DEBUG
106 static int thread_debug = 0;
107 #define dprintf(args) ((thread_debug & 1) && printf args)
108 #define d2printf(args) ((thread_debug & 8) && printf args)
109 #else
110 #define dprintf(args)
111 #define d2printf(args)
112 #endif
114 static int initialized;
116 static void PyThread__init_thread(); /* Forward */
118 void PyThread_init_thread _P0()
120 #ifdef Py_DEBUG
121 char *p = getenv("THREADDEBUG");
123 if (p) {
124 if (*p)
125 thread_debug = atoi(p);
126 else
127 thread_debug = 1;
129 #endif /* Py_DEBUG */
130 if (initialized)
131 return;
132 initialized = 1;
133 dprintf(("PyThread_init_thread called\n"));
134 PyThread__init_thread();
137 #ifdef SGI_THREADS
138 #include "thread_sgi.h"
139 #endif
141 #ifdef SOLARIS_THREADS
142 #include "thread_solaris.h"
143 #endif
145 #ifdef SUN_LWP
146 #include "thread_lwp.h"
147 #endif
149 #ifdef _POSIX_THREADS
150 #include "thread_pthread.h"
151 #endif
153 #ifdef C_THREADS
154 #include "thread_cthread.h"
155 #endif
157 #ifdef NT_THREADS
158 #include "thread_nt.h"
159 #endif
161 #ifdef OS2_THREADS
162 #include "thread_os2.h"
163 #endif
165 #ifdef BEOS_THREADS
166 #include "thread_beos.h"
167 #endif
169 #ifdef WINCE_THREADS
170 #include "thread_wince.h"
171 #endif
174 #ifdef FOOBAR_THREADS
175 #include "thread_foobar.h"
176 #endif