blob: 9349e5814ae9f9ae8832642653cc5be0789d30c2 [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 Rossum1984f1e1992-08-04 12:41:02 +000048#include "thread.h"
49
Guido van Rossum1d5735e1994-08-30 08:27:36 +000050#ifdef __ksr__
51#define _POSIX_THREADS
Guido van Rossumf9f2e821992-08-17 08:59:08 +000052#endif
53
Guido van Rossum1d5735e1994-08-30 08:27:36 +000054#ifndef _POSIX_THREADS
55
Guido van Rossum1984f1e1992-08-04 12:41:02 +000056#ifdef __sgi
Guido van Rossum1d5735e1994-08-30 08:27:36 +000057#define SGI_THREADS
Guido van Rossum1984f1e1992-08-04 12:41:02 +000058#endif
Guido van Rossum1984f1e1992-08-04 12:41:02 +000059
Guido van Rossum1d5735e1994-08-30 08:27:36 +000060#ifdef HAVE_THREAD_H
61#define SOLARIS_THREADS
62#endif
Guido van Rossum1984f1e1992-08-04 12:41:02 +000063
Guido van Rossum1d5735e1994-08-30 08:27:36 +000064#if defined(sun) && !defined(SOLARIS_THREADS)
65#define SUN_LWP
66#endif
67
Sjoerd Mullender66bca321993-12-03 16:54:45 +000068#endif /* _POSIX_THREADS */
Guido van Rossum1984f1e1992-08-04 12:41:02 +000069
70#ifdef __STDC__
71#define _P(args) args
72#define _P0() (void)
73#define _P1(v,t) (t)
74#define _P2(v1,t1,v2,t2) (t1,t2)
75#else
76#define _P(args) ()
77#define _P0() ()
78#define _P1(v,t) (v) t;
79#define _P2(v1,t1,v2,t2) (v1,v2) t1; t2;
Sjoerd Mullender66bca321993-12-03 16:54:45 +000080#endif /* __STDC__ */
Guido van Rossum1984f1e1992-08-04 12:41:02 +000081
Guido van Rossum1d5735e1994-08-30 08:27:36 +000082#ifdef DEBUG
83static int thread_debug = 0;
84#define dprintf(args) ((thread_debug & 1) && printf args)
85#define d2printf(args) ((thread_debug & 8) && printf args)
86#else
87#define dprintf(args)
88#define d2printf(args)
89#endif
90
Guido van Rossum1984f1e1992-08-04 12:41:02 +000091static int initialized;
92
Guido van Rossum1d5735e1994-08-30 08:27:36 +000093static void _init_thread(); /* Forward */
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +000094
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +000095void init_thread _P0()
96{
Sjoerd Mullenderd10d8291992-09-11 15:19:27 +000097#ifdef DEBUG
Sjoerd Mullender66bca321993-12-03 16:54:45 +000098 char *p = getenv("THREADDEBUG");
99
100 if (p) {
101 if (*p)
102 thread_debug = atoi(p);
103 else
104 thread_debug = 1;
105 }
106#endif /* DEBUG */
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000107 if (initialized)
108 return;
109 initialized = 1;
Sjoerd Mullendered59d201993-01-06 13:36:38 +0000110 dprintf(("init_thread called\n"));
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000111 _init_thread();
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000112}
113
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000114#ifdef SGI_THREADS
115#include "thread_sgi.h"
Sjoerd Mullender66bca321993-12-03 16:54:45 +0000116#endif
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000117
118#ifdef SOLARIS_THREADS
119#include "thread_solaris.h"
120#endif
121
122#ifdef SUN_LWP
123#include "thread_lwp.h"
124#endif
125
Sjoerd Mullender66bca321993-12-03 16:54:45 +0000126#ifdef _POSIX_THREADS
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000127#include "thread_pthread.h"
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000128#endif
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000129
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000130#ifdef C_THREADS
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000131#include "thread_cthread.h"
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000132#endif
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000133
Guido van Rossumc3f82b61995-01-17 16:29:31 +0000134#ifdef NT_THREADS
135#include "thread_nt.h"
136#endif
137
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000138/*
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000139#ifdef FOOBAR_THREADS
140#include "thread_foobar.h"
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000141#endif
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000142*/