thread.c 2.2 KB
Newer Older
1

2 3 4 5 6
/* Thread package.
   This is intended to be usable independently from Python.
   The implementation for system foobar is in a file thread_foobar.h
   which is included by this file dependent on config settings.
   Stuff shared by all thread_*.h files is collected here. */
7

8
#include "Python.h"
9

10
#ifndef DONT_HAVE_STDIO_H
11
#include <stdio.h>
12
#endif
13

14
#ifdef HAVE_STDLIB_H
Sjoerd Mullender's avatar
Sjoerd Mullender committed
15
#include <stdlib.h>
16
#else
17
#ifdef Py_DEBUG
18
extern char *getenv(const char *);
19
#endif
20
#endif
21

22 23 24 25
#ifdef __DGUX
#define _USING_POSIX4A_DRAFT6
#endif

26 27 28 29 30 31
#ifdef __sgi
#ifndef HAVE_PTHREAD_H /* XXX Need to check in configure.in */
#undef _POSIX_THREADS
#endif
#endif

32
#include "pythread.h"
33 34 35 36 37 38 39 40 41 42 43 44 45 46

#ifndef _POSIX_THREADS

#ifdef __sgi
#define SGI_THREADS
#endif

#ifdef HAVE_THREAD_H
#define SOLARIS_THREADS
#endif

#if defined(sun) && !defined(SOLARIS_THREADS)
#define SUN_LWP
#endif
47

48
#if defined(__MWERKS__) && !defined(__BEOS__)
49 50 51
#define _POSIX_THREADS
#endif

Sjoerd Mullender's avatar
Sjoerd Mullender committed
52
#endif /* _POSIX_THREADS */
53 54


55
#ifdef Py_DEBUG
56
static int thread_debug = 0;
Jeremy Hylton's avatar
Jeremy Hylton committed
57
#define dprintf(args)	(void)((thread_debug & 1) && printf args)
58 59 60 61
#define d2printf(args)	((thread_debug & 8) && printf args)
#else
#define dprintf(args)
#define d2printf(args)
Sjoerd Mullender's avatar
Sjoerd Mullender committed
62
#endif
63

64 65
static int initialized;

66
static void PyThread__init_thread(void); /* Forward */
67

68
void PyThread_init_thread(void)
69
{
70
#ifdef Py_DEBUG
Sjoerd Mullender's avatar
Sjoerd Mullender committed
71 72 73 74 75 76 77 78
	char *p = getenv("THREADDEBUG");

	if (p) {
		if (*p)
			thread_debug = atoi(p);
		else
			thread_debug = 1;
	}
79
#endif /* Py_DEBUG */
80 81 82
	if (initialized)
		return;
	initialized = 1;
83 84
	dprintf(("PyThread_init_thread called\n"));
	PyThread__init_thread();
85 86
}

87 88
#ifdef SGI_THREADS
#include "thread_sgi.h"
89
#endif
90

91 92
#ifdef SOLARIS_THREADS
#include "thread_solaris.h"
93 94
#endif

95 96
#ifdef SUN_LWP
#include "thread_lwp.h"
Sjoerd Mullender's avatar
Sjoerd Mullender committed
97
#endif
98

99
#ifdef HAVE_PTH
100
#include "thread_pth.h"
101 102
#endif

103 104
#ifdef _POSIX_THREADS
#include "thread_pthread.h"
105 106
#endif

107 108
#ifdef C_THREADS
#include "thread_cthread.h"
109 110
#endif

Guido van Rossum's avatar
Guido van Rossum committed
111 112 113 114
#ifdef NT_THREADS
#include "thread_nt.h"
#endif

115 116 117 118
#ifdef OS2_THREADS
#include "thread_os2.h"
#endif

119 120 121 122
#ifdef BEOS_THREADS
#include "thread_beos.h"
#endif

123 124 125 126
#ifdef WINCE_THREADS
#include "thread_wince.h"
#endif

127 128 129 130
#ifdef PLAN9_THREADS
#include "thread_plan9.h"
#endif

131 132 133 134
#ifdef ATHEOS_THREADS
#include "thread_atheos.h"
#endif

135
/*
136 137
#ifdef FOOBAR_THREADS
#include "thread_foobar.h"
138
#endif
139
*/