Guido van Rossum | 34679b7 | 1993-01-26 13:33:44 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | 6d023c9 | 1995-01-04 19:12:13 +0000 | [diff] [blame] | 2 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 3 | The Netherlands. |
Guido van Rossum | 34679b7 | 1993-01-26 13:33:44 +0000 | [diff] [blame] | 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
| 9 | provided that the above copyright notice appear in all copies and that |
| 10 | both that copyright notice and this permission notice appear in |
| 11 | supporting documentation, and that the names of Stichting Mathematisch |
| 12 | Centrum or CWI not be used in advertising or publicity pertaining to |
| 13 | distribution of the software without specific, written prior permission. |
| 14 | |
| 15 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 16 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 18 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 19 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 20 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 21 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | |
| 23 | ******************************************************************/ |
| 24 | |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 25 | /* 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 Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 31 | #include "config.h" |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 32 | |
| 33 | #include <stdio.h> |
| 34 | |
| 35 | #ifdef HAVE_STDLIB_H |
| 36 | #include <stdlib.h> |
| 37 | #else |
| 38 | extern char *getenv(); |
| 39 | #endif |
| 40 | |
Guido van Rossum | 1984f1e | 1992-08-04 12:41:02 +0000 | [diff] [blame] | 41 | #include "thread.h" |
| 42 | |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 43 | #ifdef __ksr__ |
| 44 | #define _POSIX_THREADS |
Guido van Rossum | f9f2e82 | 1992-08-17 08:59:08 +0000 | [diff] [blame] | 45 | #endif |
| 46 | |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 47 | #ifndef _POSIX_THREADS |
| 48 | |
Guido van Rossum | 1984f1e | 1992-08-04 12:41:02 +0000 | [diff] [blame] | 49 | #ifdef __sgi |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 50 | #define SGI_THREADS |
Guido van Rossum | 1984f1e | 1992-08-04 12:41:02 +0000 | [diff] [blame] | 51 | #endif |
Guido van Rossum | 1984f1e | 1992-08-04 12:41:02 +0000 | [diff] [blame] | 52 | |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 53 | #ifdef HAVE_THREAD_H |
| 54 | #define SOLARIS_THREADS |
| 55 | #endif |
Guido van Rossum | 1984f1e | 1992-08-04 12:41:02 +0000 | [diff] [blame] | 56 | |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 57 | #if defined(sun) && !defined(SOLARIS_THREADS) |
| 58 | #define SUN_LWP |
| 59 | #endif |
| 60 | |
Sjoerd Mullender | 66bca32 | 1993-12-03 16:54:45 +0000 | [diff] [blame] | 61 | #endif /* _POSIX_THREADS */ |
Guido van Rossum | 1984f1e | 1992-08-04 12:41:02 +0000 | [diff] [blame] | 62 | |
| 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 Mullender | 66bca32 | 1993-12-03 16:54:45 +0000 | [diff] [blame] | 73 | #endif /* __STDC__ */ |
Guido van Rossum | 1984f1e | 1992-08-04 12:41:02 +0000 | [diff] [blame] | 74 | |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 75 | #ifdef DEBUG |
| 76 | static 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 Rossum | 1984f1e | 1992-08-04 12:41:02 +0000 | [diff] [blame] | 84 | static int initialized; |
| 85 | |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 86 | static void _init_thread(); /* Forward */ |
Sjoerd Mullender | aee8bc1 | 1992-09-02 11:25:37 +0000 | [diff] [blame] | 87 | |
Sjoerd Mullender | aee8bc1 | 1992-09-02 11:25:37 +0000 | [diff] [blame] | 88 | void init_thread _P0() |
| 89 | { |
Sjoerd Mullender | d10d829 | 1992-09-11 15:19:27 +0000 | [diff] [blame] | 90 | #ifdef DEBUG |
Sjoerd Mullender | 66bca32 | 1993-12-03 16:54:45 +0000 | [diff] [blame] | 91 | 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 Mullender | aee8bc1 | 1992-09-02 11:25:37 +0000 | [diff] [blame] | 100 | if (initialized) |
| 101 | return; |
| 102 | initialized = 1; |
Sjoerd Mullender | ed59d20 | 1993-01-06 13:36:38 +0000 | [diff] [blame] | 103 | dprintf(("init_thread called\n")); |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 104 | _init_thread(); |
Sjoerd Mullender | aee8bc1 | 1992-09-02 11:25:37 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 107 | #ifdef SGI_THREADS |
| 108 | #include "thread_sgi.h" |
Sjoerd Mullender | 66bca32 | 1993-12-03 16:54:45 +0000 | [diff] [blame] | 109 | #endif |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 110 | |
| 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 Mullender | 66bca32 | 1993-12-03 16:54:45 +0000 | [diff] [blame] | 119 | #ifdef _POSIX_THREADS |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 120 | #include "thread_pthread.h" |
Sjoerd Mullender | e893412 | 1993-01-13 12:08:48 +0000 | [diff] [blame] | 121 | #endif |
Guido van Rossum | f9f2e82 | 1992-08-17 08:59:08 +0000 | [diff] [blame] | 122 | |
Guido van Rossum | 1984f1e | 1992-08-04 12:41:02 +0000 | [diff] [blame] | 123 | #ifdef C_THREADS |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 124 | #include "thread_cthread.h" |
Guido van Rossum | 1984f1e | 1992-08-04 12:41:02 +0000 | [diff] [blame] | 125 | #endif |
Guido van Rossum | f9f2e82 | 1992-08-17 08:59:08 +0000 | [diff] [blame] | 126 | |
Guido van Rossum | c3f82b6 | 1995-01-17 16:29:31 +0000 | [diff] [blame] | 127 | #ifdef NT_THREADS |
| 128 | #include "thread_nt.h" |
| 129 | #endif |
| 130 | |
Guido van Rossum | f9f2e82 | 1992-08-17 08:59:08 +0000 | [diff] [blame] | 131 | /* |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 132 | #ifdef FOOBAR_THREADS |
| 133 | #include "thread_foobar.h" |
Guido van Rossum | 1984f1e | 1992-08-04 12:41:02 +0000 | [diff] [blame] | 134 | #endif |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 135 | */ |