blob: c6f8c51e75714436579937e1ce7466d692cc1743 [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
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
Guido van Rossum1d5735e1994-08-30 08:27:36 +000025/* Thread package.
26 This is intended to be usable independently from Python.
27 The implementation for system foobar is in a file thread_foobar.h
28 which is included by this file dependent on config settings.
29 Stuff shared by all thread_*.h files is collected here. */
30
Guido van Rossum1d5735e1994-08-30 08:27:36 +000031#include "config.h"
Guido van Rossum1d5735e1994-08-30 08:27:36 +000032
33#include <stdio.h>
34
35#ifdef HAVE_STDLIB_H
36#include <stdlib.h>
37#else
38extern char *getenv();
39#endif
40
Guido van Rossum1984f1e1992-08-04 12:41:02 +000041#include "thread.h"
42
Guido van Rossum1d5735e1994-08-30 08:27:36 +000043#ifdef __ksr__
44#define _POSIX_THREADS
Guido van Rossumf9f2e821992-08-17 08:59:08 +000045#endif
46
Guido van Rossum1d5735e1994-08-30 08:27:36 +000047#ifndef _POSIX_THREADS
48
Guido van Rossum1984f1e1992-08-04 12:41:02 +000049#ifdef __sgi
Guido van Rossum1d5735e1994-08-30 08:27:36 +000050#define SGI_THREADS
Guido van Rossum1984f1e1992-08-04 12:41:02 +000051#endif
Guido van Rossum1984f1e1992-08-04 12:41:02 +000052
Guido van Rossum1d5735e1994-08-30 08:27:36 +000053#ifdef HAVE_THREAD_H
54#define SOLARIS_THREADS
55#endif
Guido van Rossum1984f1e1992-08-04 12:41:02 +000056
Guido van Rossum1d5735e1994-08-30 08:27:36 +000057#if defined(sun) && !defined(SOLARIS_THREADS)
58#define SUN_LWP
59#endif
60
Sjoerd Mullender66bca321993-12-03 16:54:45 +000061#endif /* _POSIX_THREADS */
Guido van Rossum1984f1e1992-08-04 12:41:02 +000062
63#ifdef __STDC__
64#define _P(args) args
65#define _P0() (void)
66#define _P1(v,t) (t)
67#define _P2(v1,t1,v2,t2) (t1,t2)
68#else
69#define _P(args) ()
70#define _P0() ()
71#define _P1(v,t) (v) t;
72#define _P2(v1,t1,v2,t2) (v1,v2) t1; t2;
Sjoerd Mullender66bca321993-12-03 16:54:45 +000073#endif /* __STDC__ */
Guido van Rossum1984f1e1992-08-04 12:41:02 +000074
Guido van Rossum1d5735e1994-08-30 08:27:36 +000075#ifdef DEBUG
76static int thread_debug = 0;
77#define dprintf(args) ((thread_debug & 1) && printf args)
78#define d2printf(args) ((thread_debug & 8) && printf args)
79#else
80#define dprintf(args)
81#define d2printf(args)
82#endif
83
Guido van Rossum1984f1e1992-08-04 12:41:02 +000084static int initialized;
85
Guido van Rossum1d5735e1994-08-30 08:27:36 +000086static void _init_thread(); /* Forward */
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +000087
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +000088void init_thread _P0()
89{
Sjoerd Mullenderd10d8291992-09-11 15:19:27 +000090#ifdef DEBUG
Sjoerd Mullender66bca321993-12-03 16:54:45 +000091 char *p = getenv("THREADDEBUG");
92
93 if (p) {
94 if (*p)
95 thread_debug = atoi(p);
96 else
97 thread_debug = 1;
98 }
99#endif /* DEBUG */
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000100 if (initialized)
101 return;
102 initialized = 1;
Sjoerd Mullendered59d201993-01-06 13:36:38 +0000103 dprintf(("init_thread called\n"));
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000104 _init_thread();
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000105}
106
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000107#ifdef SGI_THREADS
108#include "thread_sgi.h"
Sjoerd Mullender66bca321993-12-03 16:54:45 +0000109#endif
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000110
111#ifdef SOLARIS_THREADS
112#include "thread_solaris.h"
113#endif
114
115#ifdef SUN_LWP
116#include "thread_lwp.h"
117#endif
118
Sjoerd Mullender66bca321993-12-03 16:54:45 +0000119#ifdef _POSIX_THREADS
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000120#include "thread_pthread.h"
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000121#endif
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000122
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000123#ifdef C_THREADS
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000124#include "thread_cthread.h"
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000125#endif
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000126
Guido van Rossumc3f82b61995-01-17 16:29:31 +0000127#ifdef NT_THREADS
128#include "thread_nt.h"
129#endif
130
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000131/*
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000132#ifdef FOOBAR_THREADS
133#include "thread_foobar.h"
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000134#endif
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000135*/