blob: 9da701dc71f6b164a0e81c04317fe5c2c2d50dac [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
40#include <stdio.h>
41
42#ifdef HAVE_STDLIB_H
43#include <stdlib.h>
44#else
45extern char *getenv();
46#endif
47
Guido van Rossum80bb9651996-12-05 23:27:02 +000048#ifdef HAVE_UNISTD_H
49#include <unistd.h>
50#endif
51
Guido van Rossum64f91051997-05-22 20:41:59 +000052#ifdef __DGUX
53#define _USING_POSIX4A_DRAFT6
54#endif
55
Guido van Rossumd11bfdd1997-04-29 21:48:34 +000056#ifdef __sgi
57#ifndef HAVE_PTHREAD_H /* XXX Need to check in configure.in */
58#undef _POSIX_THREADS
59#endif
60#endif
61
Guido van Rossum1984f1e1992-08-04 12:41:02 +000062#include "thread.h"
63
Guido van Rossum1d5735e1994-08-30 08:27:36 +000064#ifdef __ksr__
65#define _POSIX_THREADS
Guido van Rossumf9f2e821992-08-17 08:59:08 +000066#endif
67
Guido van Rossum1d5735e1994-08-30 08:27:36 +000068#ifndef _POSIX_THREADS
69
Guido van Rossum1984f1e1992-08-04 12:41:02 +000070#ifdef __sgi
Guido van Rossum1d5735e1994-08-30 08:27:36 +000071#define SGI_THREADS
Guido van Rossum1984f1e1992-08-04 12:41:02 +000072#endif
Guido van Rossum1984f1e1992-08-04 12:41:02 +000073
Guido van Rossum1d5735e1994-08-30 08:27:36 +000074#ifdef HAVE_THREAD_H
75#define SOLARIS_THREADS
76#endif
Guido van Rossum1984f1e1992-08-04 12:41:02 +000077
Guido van Rossum1d5735e1994-08-30 08:27:36 +000078#if defined(sun) && !defined(SOLARIS_THREADS)
79#define SUN_LWP
80#endif
81
Sjoerd Mullender66bca321993-12-03 16:54:45 +000082#endif /* _POSIX_THREADS */
Guido van Rossum1984f1e1992-08-04 12:41:02 +000083
84#ifdef __STDC__
85#define _P(args) args
86#define _P0() (void)
87#define _P1(v,t) (t)
88#define _P2(v1,t1,v2,t2) (t1,t2)
89#else
90#define _P(args) ()
91#define _P0() ()
92#define _P1(v,t) (v) t;
93#define _P2(v1,t1,v2,t2) (v1,v2) t1; t2;
Sjoerd Mullender66bca321993-12-03 16:54:45 +000094#endif /* __STDC__ */
Guido van Rossum1984f1e1992-08-04 12:41:02 +000095
Guido van Rossum408027e1996-12-30 16:17:54 +000096#ifdef Py_DEBUG
Guido van Rossum1d5735e1994-08-30 08:27:36 +000097static int thread_debug = 0;
98#define dprintf(args) ((thread_debug & 1) && printf args)
99#define d2printf(args) ((thread_debug & 8) && printf args)
100#else
101#define dprintf(args)
102#define d2printf(args)
103#endif
104
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000105static int initialized;
106
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000107static void _init_thread(); /* Forward */
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000108
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000109void init_thread _P0()
110{
Guido van Rossum408027e1996-12-30 16:17:54 +0000111#ifdef Py_DEBUG
Sjoerd Mullender66bca321993-12-03 16:54:45 +0000112 char *p = getenv("THREADDEBUG");
113
114 if (p) {
115 if (*p)
116 thread_debug = atoi(p);
117 else
118 thread_debug = 1;
119 }
Guido van Rossum408027e1996-12-30 16:17:54 +0000120#endif /* Py_DEBUG */
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000121 if (initialized)
122 return;
123 initialized = 1;
Sjoerd Mullendered59d201993-01-06 13:36:38 +0000124 dprintf(("init_thread called\n"));
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000125 _init_thread();
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000126}
127
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000128#ifdef SGI_THREADS
129#include "thread_sgi.h"
Sjoerd Mullender66bca321993-12-03 16:54:45 +0000130#endif
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000131
132#ifdef SOLARIS_THREADS
133#include "thread_solaris.h"
134#endif
135
136#ifdef SUN_LWP
137#include "thread_lwp.h"
138#endif
139
Sjoerd Mullender66bca321993-12-03 16:54:45 +0000140#ifdef _POSIX_THREADS
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000141#include "thread_pthread.h"
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000142#endif
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000143
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000144#ifdef C_THREADS
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000145#include "thread_cthread.h"
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000146#endif
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000147
Guido van Rossumc3f82b61995-01-17 16:29:31 +0000148#ifdef NT_THREADS
149#include "thread_nt.h"
150#endif
151
Guido van Rossum8e9ebfd1997-11-22 21:53:48 +0000152#ifdef OS2_THREADS
153#include "thread_os2.h"
154#endif
155
Guido van Rossum1a8791e1998-08-04 22:46:29 +0000156#ifdef BEOS_THREADS
157#include "thread_beos.h"
158#endif
159
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000160/*
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000161#ifdef FOOBAR_THREADS
162#include "thread_foobar.h"
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000163#endif
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000164*/