blob: 3ee71aafcee2ab3a09cfbadc70b7533daeccbbcc [file] [log] [blame]
Guido van Rossum34679b71993-01-26 13:33:44 +00001/***********************************************************
Guido van Rossum1d5735e1994-08-30 08:27:36 +00002Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Guido van Rossum34679b71993-01-26 13:33:44 +00003Amsterdam, The Netherlands.
4
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
31#ifdef HAVE_CONFIG_H
32#include "config.h"
33#endif
34
35#include <stdio.h>
36
37#ifdef HAVE_STDLIB_H
38#include <stdlib.h>
39#else
40extern char *getenv();
41#endif
42
Guido van Rossum1984f1e1992-08-04 12:41:02 +000043#include "thread.h"
44
Guido van Rossum1d5735e1994-08-30 08:27:36 +000045#ifdef __ksr__
46#define _POSIX_THREADS
Guido van Rossumf9f2e821992-08-17 08:59:08 +000047#endif
48
Guido van Rossum1d5735e1994-08-30 08:27:36 +000049#ifndef _POSIX_THREADS
50
Guido van Rossum1984f1e1992-08-04 12:41:02 +000051#ifdef __sgi
Guido van Rossum1d5735e1994-08-30 08:27:36 +000052#define SGI_THREADS
Guido van Rossum1984f1e1992-08-04 12:41:02 +000053#endif
Guido van Rossum1984f1e1992-08-04 12:41:02 +000054
Guido van Rossum1d5735e1994-08-30 08:27:36 +000055#ifdef HAVE_THREAD_H
56#define SOLARIS_THREADS
57#endif
Guido van Rossum1984f1e1992-08-04 12:41:02 +000058
Guido van Rossum1d5735e1994-08-30 08:27:36 +000059#if defined(sun) && !defined(SOLARIS_THREADS)
60#define SUN_LWP
61#endif
62
Sjoerd Mullender66bca321993-12-03 16:54:45 +000063#endif /* _POSIX_THREADS */
Guido van Rossum1984f1e1992-08-04 12:41:02 +000064
65#ifdef __STDC__
66#define _P(args) args
67#define _P0() (void)
68#define _P1(v,t) (t)
69#define _P2(v1,t1,v2,t2) (t1,t2)
70#else
71#define _P(args) ()
72#define _P0() ()
73#define _P1(v,t) (v) t;
74#define _P2(v1,t1,v2,t2) (v1,v2) t1; t2;
Sjoerd Mullender66bca321993-12-03 16:54:45 +000075#endif /* __STDC__ */
Guido van Rossum1984f1e1992-08-04 12:41:02 +000076
Guido van Rossum1d5735e1994-08-30 08:27:36 +000077#ifdef DEBUG
78static int thread_debug = 0;
79#define dprintf(args) ((thread_debug & 1) && printf args)
80#define d2printf(args) ((thread_debug & 8) && printf args)
81#else
82#define dprintf(args)
83#define d2printf(args)
84#endif
85
Guido van Rossum1984f1e1992-08-04 12:41:02 +000086static int initialized;
87
Guido van Rossum1d5735e1994-08-30 08:27:36 +000088static void _init_thread(); /* Forward */
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +000089
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +000090void init_thread _P0()
91{
Sjoerd Mullenderd10d8291992-09-11 15:19:27 +000092#ifdef DEBUG
Sjoerd Mullender66bca321993-12-03 16:54:45 +000093 char *p = getenv("THREADDEBUG");
94
95 if (p) {
96 if (*p)
97 thread_debug = atoi(p);
98 else
99 thread_debug = 1;
100 }
101#endif /* DEBUG */
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000102 if (initialized)
103 return;
104 initialized = 1;
Sjoerd Mullendered59d201993-01-06 13:36:38 +0000105 dprintf(("init_thread called\n"));
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000106 _init_thread();
Sjoerd Mullenderaee8bc11992-09-02 11:25:37 +0000107}
108
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000109#ifdef SGI_THREADS
110#include "thread_sgi.h"
Sjoerd Mullender66bca321993-12-03 16:54:45 +0000111#endif
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000112
113#ifdef SOLARIS_THREADS
114#include "thread_solaris.h"
115#endif
116
117#ifdef SUN_LWP
118#include "thread_lwp.h"
119#endif
120
Sjoerd Mullender66bca321993-12-03 16:54:45 +0000121#ifdef _POSIX_THREADS
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000122#include "thread_pthread.h"
Sjoerd Mullendere8934121993-01-13 12:08:48 +0000123#endif
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000124
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000125#ifdef C_THREADS
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000126#include "thread_cthread.h"
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000127#endif
Guido van Rossumf9f2e821992-08-17 08:59:08 +0000128
129/*
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000130#ifdef FOOBAR_THREADS
131#include "thread_foobar.h"
Guido van Rossum1984f1e1992-08-04 12:41:02 +0000132#endif
Guido van Rossum1d5735e1994-08-30 08:27:36 +0000133*/