blob: 6d5d77cc49924eb8001db170f704c942d8fc5b79 [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 Rossumfd71b9e2000-06-30 23:50:40 +00007Copyright (c) 2000, BeOpen.com.
8Copyright (c) 1995-2000, Corporation for National Research Initiatives.
9Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
10All rights reserved.
Guido van Rossum34679b71993-01-26 13:33:44 +000011
Guido van Rossumfd71b9e2000-06-30 23:50:40 +000012See the file "Misc/COPYRIGHT" for information on usage and
13redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
Guido van Rossum34679b71993-01-26 13:33:44 +000014
15******************************************************************/
16
Guido van Rossum1d5735e1994-08-30 08:27:36 +000017/* Thread package.
18 This is intended to be usable independently from Python.
19 The implementation for system foobar is in a file thread_foobar.h
20 which is included by this file dependent on config settings.
21 Stuff shared by all thread_*.h files is collected here. */
22
Guido van Rossum1d5735e1994-08-30 08:27:36 +000023#include "config.h"
Guido van Rossum1d5735e1994-08-30 08:27:36 +000024
Guido van Rossumf2615261998-12-04 18:50:20 +000025/* config.h may or may not define DL_IMPORT */
26#ifndef DL_IMPORT /* declarations for DLL import/export */
27#define DL_IMPORT(RTYPE) RTYPE
28#endif
29
Guido van Rossum2571cc81999-04-07 16:07:23 +000030#ifndef DONT_HAVE_STDIO_H
Guido van Rossum1d5735e1994-08-30 08:27:36 +000031#include <stdio.h>
Guido van Rossum2571cc81999-04-07 16:07:23 +000032#endif
Guido van Rossum1d5735e1994-08-30 08:27:36 +000033
34#ifdef HAVE_STDLIB_H
35#include <stdlib.h>
36#else
Guido van Rossum2571cc81999-04-07 16:07:23 +000037#ifdef Py_DEBUG
Guido van Rossum1d5735e1994-08-30 08:27:36 +000038extern char *getenv();
39#endif
Guido van Rossum2571cc81999-04-07 16:07:23 +000040#endif
Guido van Rossum1d5735e1994-08-30 08:27:36 +000041
Guido van Rossum80bb9651996-12-05 23:27:02 +000042#ifdef HAVE_UNISTD_H
43#include <unistd.h>
44#endif
45
Guido van Rossum64f91051997-05-22 20:41:59 +000046#ifdef __DGUX
47#define _USING_POSIX4A_DRAFT6
48#endif
49
Guido van Rossumd11bfdd1997-04-29 21:48:34 +000050#ifdef __sgi
51#ifndef HAVE_PTHREAD_H /* XXX Need to check in configure.in */
52#undef _POSIX_THREADS
53#endif
54#endif
55
Guido van Rossum49b56061998-10-01 20:42:43 +000056#include "pythread.h"
Guido van Rossum1984f1e1992-08-04 12:41:02 +000057
Guido van Rossum1d5735e1994-08-30 08:27:36 +000058#ifdef __ksr__
59#define _POSIX_THREADS
Guido van Rossumf9f2e821992-08-17 08:59:08 +000060#endif
61
Guido van Rossum1d5735e1994-08-30 08:27:36 +000062#ifndef _POSIX_THREADS
63
Guido van Rossum1984f1e1992-08-04 12:41:02 +000064#ifdef __sgi
Guido van Rossum1d5735e1994-08-30 08:27:36 +000065#define SGI_THREADS
Guido van Rossum1984f1e1992-08-04 12:41:02 +000066#endif
Guido van Rossum1984f1e1992-08-04 12:41:02 +000067
Guido van Rossum1d5735e1994-08-30 08:27:36 +000068#ifdef HAVE_THREAD_H
69#define SOLARIS_THREADS
70#endif
Guido van Rossum1984f1e1992-08-04 12:41:02 +000071
Guido van Rossum1d5735e1994-08-30 08:27:36 +000072#if defined(sun) && !defined(SOLARIS_THREADS)
73#define SUN_LWP
74#endif
75
Guido van Rossum095249f2000-04-24 15:06:51 +000076#ifdef __MWERKS__
77#define _POSIX_THREADS
78#endif
79
Sjoerd Mullender66bca321993-12-03 16:54:45 +000080#endif /* _POSIX_THREADS */
Guido van Rossum1984f1e1992-08-04 12:41:02 +000081
82#ifdef __STDC__
83#define _P(args) args
84#define _P0() (void)
85#define _P1(v,t) (t)
86#define _P2(v1,t1,v2,t2) (t1,t2)
87#else
88#define _P(args) ()
89#define _P0() ()
90#define _P1(v,t) (v) t;
91#define _P2(v1,t1,v2,t2) (v1,v2) t1; t2;
Sjoerd Mullender66bca321993-12-03 16:54:45 +000092#endif /* __STDC__ */
Guido van Rossum1984f1e1992-08-04 12:41:02 +000093
Guido van Rossum408027e1996-12-30 16:17:54 +000094#ifdef Py_DEBUG
Guido van Rossum1d5735e1994-08-30 08:27:36 +000095static int thread_debug = 0;
96#define dprintf(args) ((thread_debug & 1) && printf args)
97#define d2printf(args) ((thread_debug & 8) && printf args)
98#else
99#define dprintf(args)
100#define d2printf(args)
101#endif
102
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000103static int initialized;
104
Guido van Rossum65d5b571998-12-21 19:32:43 +0000105static void PyThread__init_thread(); /* Forward */
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000106
Guido van Rossum65d5b571998-12-21 19:32:43 +0000107void PyThread_init_thread _P0()
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000108{
Guido van Rossum408027e1996-12-30 16:17:54 +0000109#ifdef Py_DEBUG
Sjoerd Mullender66bca321993-12-03 16:54:45 +0000110 char *p = getenv("THREADDEBUG");
111
112 if (p) {
113 if (*p)
114 thread_debug = atoi(p);
115 else
116 thread_debug = 1;
117 }
Guido van Rossum408027e1996-12-30 16:17:54 +0000118#endif /* Py_DEBUG */
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000119 if (initialized)
120 return;
121 initialized = 1;
Guido van Rossum65d5b571998-12-21 19:32:43 +0000122 dprintf(("PyThread_init_thread called\n"));
123 PyThread__init_thread();
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000124}
125
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000126#ifdef SGI_THREADS
127#include "thread_sgi.h"
Sjoerd Mullender66bca321993-12-03 16:54:45 +0000128#endif
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000129
130#ifdef SOLARIS_THREADS
131#include "thread_solaris.h"
132#endif
133
134#ifdef SUN_LWP
135#include "thread_lwp.h"
136#endif
137
Guido van Rossum07bd90e2000-05-08 13:41:38 +0000138#ifdef _GNU_PTH
139#include "thread_pth.h"
140#else
Sjoerd Mullender66bca321993-12-03 16:54:45 +0000141#ifdef _POSIX_THREADS
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000142#include "thread_pthread.h"
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000143#endif
Guido van Rossum07bd90e2000-05-08 13:41:38 +0000144#endif
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000145
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000146#ifdef C_THREADS
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000147#include "thread_cthread.h"
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000148#endif
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000149
Guido van Rossumc3f82b61995-01-17 16:29:31 +0000150#ifdef NT_THREADS
151#include "thread_nt.h"
152#endif
153
Guido van Rossum8e9ebfd1997-11-22 21:53:48 +0000154#ifdef OS2_THREADS
155#include "thread_os2.h"
156#endif
157
Guido van Rossum1a8791e1998-08-04 22:46:29 +0000158#ifdef BEOS_THREADS
159#include "thread_beos.h"
160#endif
161
Guido van Rossum2571cc81999-04-07 16:07:23 +0000162#ifdef WINCE_THREADS
163#include "thread_wince.h"
164#endif
165
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000166/*
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000167#ifdef FOOBAR_THREADS
168#include "thread_foobar.h"
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000169#endif
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000170*/