blob: 0f46223499ccbe379211188514f5c814af159cb1 [file] [log] [blame]
Guido van Rossum34679b71993-01-26 13:33:44 +00001/***********************************************************
Guido van Rossum6d023c91995-01-04 19:12:13 +00002Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3The Netherlands.
Guido van Rossum34679b71993-01-26 13:33:44 +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 Rossum34679b71993-01-26 13:33:44 +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 Rossum34679b71993-01-26 13:33:44 +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 Rossum34679b71993-01-26 13:33:44 +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 Rossum34679b71993-01-26 13:33:44 +000029
30******************************************************************/
31
Guido van Rossum1d5735e1994-08-30 08:27:36 +000032/* 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 Rossum1d5735e1994-08-30 08:27:36 +000038#include "config.h"
Guido van Rossum1d5735e1994-08-30 08:27:36 +000039
Guido van Rossumf2615261998-12-04 18:50:20 +000040/* 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 Rossum2571cc81999-04-07 16:07:23 +000045#ifndef DONT_HAVE_STDIO_H
Guido van Rossum1d5735e1994-08-30 08:27:36 +000046#include <stdio.h>
Guido van Rossum2571cc81999-04-07 16:07:23 +000047#endif
Guido van Rossum1d5735e1994-08-30 08:27:36 +000048
49#ifdef HAVE_STDLIB_H
50#include <stdlib.h>
51#else
Guido van Rossum2571cc81999-04-07 16:07:23 +000052#ifdef Py_DEBUG
Guido van Rossum1d5735e1994-08-30 08:27:36 +000053extern char *getenv();
54#endif
Guido van Rossum2571cc81999-04-07 16:07:23 +000055#endif
Guido van Rossum1d5735e1994-08-30 08:27:36 +000056
Guido van Rossum80bb9651996-12-05 23:27:02 +000057#ifdef HAVE_UNISTD_H
58#include <unistd.h>
59#endif
60
Guido van Rossum64f91051997-05-22 20:41:59 +000061#ifdef __DGUX
62#define _USING_POSIX4A_DRAFT6
63#endif
64
Guido van Rossumd11bfdd1997-04-29 21:48:34 +000065#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 Rossum49b56061998-10-01 20:42:43 +000071#include "pythread.h"
Guido van Rossum1984f1e1992-08-04 12:41:02 +000072
Guido van Rossum1d5735e1994-08-30 08:27:36 +000073#ifdef __ksr__
74#define _POSIX_THREADS
Guido van Rossumf9f2e821992-08-17 08:59:08 +000075#endif
76
Guido van Rossum1d5735e1994-08-30 08:27:36 +000077#ifndef _POSIX_THREADS
78
Guido van Rossum1984f1e1992-08-04 12:41:02 +000079#ifdef __sgi
Guido van Rossum1d5735e1994-08-30 08:27:36 +000080#define SGI_THREADS
Guido van Rossum1984f1e1992-08-04 12:41:02 +000081#endif
Guido van Rossum1984f1e1992-08-04 12:41:02 +000082
Guido van Rossum1d5735e1994-08-30 08:27:36 +000083#ifdef HAVE_THREAD_H
84#define SOLARIS_THREADS
85#endif
Guido van Rossum1984f1e1992-08-04 12:41:02 +000086
Guido van Rossum1d5735e1994-08-30 08:27:36 +000087#if defined(sun) && !defined(SOLARIS_THREADS)
88#define SUN_LWP
89#endif
90
Sjoerd Mullender66bca321993-12-03 16:54:45 +000091#endif /* _POSIX_THREADS */
Guido van Rossum1984f1e1992-08-04 12:41:02 +000092
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;
Sjoerd Mullender66bca321993-12-03 16:54:45 +0000103#endif /* __STDC__ */
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000104
Guido van Rossum408027e1996-12-30 16:17:54 +0000105#ifdef Py_DEBUG
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000106static 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
113
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000114static int initialized;
115
Guido van Rossum65d5b571998-12-21 19:32:43 +0000116static void PyThread__init_thread(); /* Forward */
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000117
Guido van Rossum65d5b571998-12-21 19:32:43 +0000118void PyThread_init_thread _P0()
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000119{
Guido van Rossum408027e1996-12-30 16:17:54 +0000120#ifdef Py_DEBUG
Sjoerd Mullender66bca321993-12-03 16:54:45 +0000121 char *p = getenv("THREADDEBUG");
122
123 if (p) {
124 if (*p)
125 thread_debug = atoi(p);
126 else
127 thread_debug = 1;
128 }
Guido van Rossum408027e1996-12-30 16:17:54 +0000129#endif /* Py_DEBUG */
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000130 if (initialized)
131 return;
132 initialized = 1;
Guido van Rossum65d5b571998-12-21 19:32:43 +0000133 dprintf(("PyThread_init_thread called\n"));
134 PyThread__init_thread();
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000135}
136
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000137#ifdef SGI_THREADS
138#include "thread_sgi.h"
Sjoerd Mullender66bca321993-12-03 16:54:45 +0000139#endif
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000140
141#ifdef SOLARIS_THREADS
142#include "thread_solaris.h"
143#endif
144
145#ifdef SUN_LWP
146#include "thread_lwp.h"
147#endif
148
Sjoerd Mullender66bca321993-12-03 16:54:45 +0000149#ifdef _POSIX_THREADS
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000150#include "thread_pthread.h"
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000151#endif
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000152
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000153#ifdef C_THREADS
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000154#include "thread_cthread.h"
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000155#endif
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000156
Guido van Rossumc3f82b61995-01-17 16:29:31 +0000157#ifdef NT_THREADS
158#include "thread_nt.h"
159#endif
160
Guido van Rossum8e9ebfd1997-11-22 21:53:48 +0000161#ifdef OS2_THREADS
162#include "thread_os2.h"
163#endif
164
Guido van Rossum1a8791e1998-08-04 22:46:29 +0000165#ifdef BEOS_THREADS
166#include "thread_beos.h"
167#endif
168
Guido van Rossum2571cc81999-04-07 16:07:23 +0000169#ifdef WINCE_THREADS
170#include "thread_wince.h"
171#endif
172
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000173/*
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000174#ifdef FOOBAR_THREADS
175#include "thread_foobar.h"
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000176#endif
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000177*/