annotate Python/thread.c @ 1350:d9cb55ef34e2 legacy-trunk

Added widget methods {Height,Width}{,MM}OfScreen.
author Sjoerd Mullender <sjoerd@acm.org>
date Tue, 12 Oct 1993 14:10:58 +0000
parents 2937897a7d8b
children b1bb74a2b593
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1198
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
1 /***********************************************************
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
2 Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
3 Amsterdam, The Netherlands.
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
4
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
5 All Rights Reserved
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
6
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
8 documentation for any purpose and without fee is hereby granted,
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
9 provided that the above copyright notice appear in all copies and that
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
10 both that copyright notice and this permission notice appear in
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
12 Centrum or CWI not be used in advertising or publicity pertaining to
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
13 distribution of the software without specific, written prior permission.
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
14
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
22
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
23 ******************************************************************/
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1186
diff changeset
24
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 #include "thread.h"
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
27 #ifdef DEBUG
1047
6b5a34db21fe Added C++ support in thread.h; don't use signals if not strictly
Sjoerd Mullender <sjoerd@acm.org>
parents: 1005
diff changeset
28 static int thread_debug = 0;
6b5a34db21fe Added C++ support in thread.h; don't use signals if not strictly
Sjoerd Mullender <sjoerd@acm.org>
parents: 1005
diff changeset
29 #define dprintf(args) (thread_debug && printf args)
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
30 #else
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
31 #define dprintf(args)
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
32 #endif
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
33
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 #include <stdlib.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 #include <stdio.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 #include <signal.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 #include <sys/types.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 #include <sys/prctl.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 #include <ulocks.h>
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
41 #include <errno.h>
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
42
1186
947f8a347c4f ushdr_t was not defined so fill in its size instead of using sizeof.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1184
diff changeset
43 #define HDR_SIZE 2680 /* sizeof(ushdr_t) */
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
44 #define MAXPROC 100 /* max # of threads that can be started */
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
45
1350
d9cb55ef34e2 Added widget methods {Height,Width}{,MM}OfScreen.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1198
diff changeset
46 /*static*/ usptr_t *shared_arena;
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
47 static ulock_t count_lock; /* protection for some variables */
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
48 static ulock_t wait_lock; /* lock used to wait for other threads */
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
49 static int waiting_for_threads; /* protected by count_lock */
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
50 static int nthreads; /* protected by count_lock */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 static int exit_status;
1179
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
52 static int do_exit; /* indicates that the program is to exit */
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
53 static int exiting; /* we're already exiting (for maybe_exit) */
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
54 static pid_t my_pid; /* PID of main thread */
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
55 static pid_t pidlist[MAXPROC]; /* PIDs of other threads */
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
56 static int maxpidindex; /* # of PIDs in pidlist */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 #include <lwp/lwp.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 #include <lwp/stackdep.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
61
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
62 #define STACKSIZE 1000 /* stacksize for a thread */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 #define NSTACKS 2 /* # stacks to be put in cache initialy */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
64
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 struct lock {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 int lock_locked;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 cv_t lock_condvar;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 mon_t lock_monitor;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 };
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 #ifdef C_THREADS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 #include <cthreads.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
74
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 #ifdef __STDC__
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 #define _P(args) args
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 #define _P0() (void)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 #define _P1(v,t) (t)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 #define _P2(v1,t1,v2,t2) (t1,t2)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 #else
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 #define _P(args) ()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 #define _P0() ()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 #define _P1(v,t) (v) t;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 #define _P2(v1,t1,v2,t2) (v1,v2) t1; t2;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
86
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 static int initialized;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
88
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
89 #ifdef __sgi
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
90 /*
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
91 * This routine is called as a signal handler when another thread
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
92 * exits. When that happens, we must see whether we have to exit as
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
93 * well (because of an exit_prog()) or whether we should continue on.
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
94 */
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
95 static void exit_sig _P0()
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
96 {
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
97 dprintf(("exit_sig called\n"));
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
98 if (exiting && getpid() == my_pid) {
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
99 dprintf(("already exiting\n"));
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
100 return;
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
101 }
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
102 if (do_exit) {
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
103 dprintf(("exiting in exit_sig\n"));
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
104 exit_thread();
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
105 }
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
106 }
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
107
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
108 /*
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
109 * This routine is called when a process calls exit(). If that wasn't
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
110 * done from the library, we do as if an exit_prog() was intended.
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
111 */
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
112 static void maybe_exit _P0()
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
113 {
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
114 dprintf(("maybe_exit called\n"));
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
115 if (exiting) {
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
116 dprintf(("already exiting\n"));
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
117 return;
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
118 }
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
119 exit_prog(0);
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
120 }
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
121 #endif
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
122
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
123 /*
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
124 * Initialization.
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
125 */
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
126 void init_thread _P0()
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
127 {
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
128 #ifdef __sgi
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
129 struct sigaction s;
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
130 #ifdef USE_DL
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
131 long addr, size;
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
132 #endif
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
133 #endif
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
134
1047
6b5a34db21fe Added C++ support in thread.h; don't use signals if not strictly
Sjoerd Mullender <sjoerd@acm.org>
parents: 1005
diff changeset
135 #ifdef DEBUG
6b5a34db21fe Added C++ support in thread.h; don't use signals if not strictly
Sjoerd Mullender <sjoerd@acm.org>
parents: 1005
diff changeset
136 thread_debug = getenv("THREADDEBUG") != 0;
6b5a34db21fe Added C++ support in thread.h; don't use signals if not strictly
Sjoerd Mullender <sjoerd@acm.org>
parents: 1005
diff changeset
137 #endif
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
138 if (initialized)
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
139 return;
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
140 initialized = 1;
1179
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
141 dprintf(("init_thread called\n"));
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
142
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
143 #ifdef __sgi
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
144 #ifdef USE_DL
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
145 if ((size = usconfig(CONF_INITSIZE, 64*1024)) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
146 perror("usconfig - CONF_INITSIZE (check)");
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
147 if (usconfig(CONF_INITSIZE, size) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
148 perror("usconfig - CONF_INITSIZE (reset)");
1186
947f8a347c4f ushdr_t was not defined so fill in its size instead of using sizeof.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1184
diff changeset
149 addr = (long) dl_getrange(size + HDR_SIZE);
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
150 dprintf(("trying to use addr %lx-%lx for shared arena\n", addr, addr+size));
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
151 errno = 0;
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
152 if ((addr = usconfig(CONF_ATTACHADDR, addr)) < 0 && errno != 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
153 perror("usconfig - CONF_ATTACHADDR (set)");
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
154 #endif
1179
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
155 if (usconfig(CONF_INITUSERS, 16) < 0)
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
156 perror("usconfig - CONF_INITUSERS");
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
157 my_pid = getpid(); /* so that we know which is the main thread */
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
158 atexit(maybe_exit);
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
159 s.sa_handler = exit_sig;
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
160 sigemptyset(&s.sa_mask);
1047
6b5a34db21fe Added C++ support in thread.h; don't use signals if not strictly
Sjoerd Mullender <sjoerd@acm.org>
parents: 1005
diff changeset
161 /*sigaddset(&s.sa_mask, SIGUSR1);*/
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
162 s.sa_flags = 0;
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
163 sigaction(SIGUSR1, &s, 0);
1179
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
164 if (prctl(PR_SETEXITSIG, SIGUSR1) < 0)
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
165 perror("prctl - PR_SETEXITSIG");
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
166 if (usconfig(CONF_ARENATYPE, US_SHAREDONLY) < 0)
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
167 perror("usconfig - CONF_ARENATYPE");
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
168 /*usconfig(CONF_LOCKTYPE, US_DEBUGPLUS);*/
1179
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
169 if ((shared_arena = usinit(tmpnam(0))) == 0)
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
170 perror("usinit");
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
171 #ifdef USE_DL
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
172 if (usconfig(CONF_ATTACHADDR, addr) < 0) /* reset address */
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
173 perror("usconfig - CONF_ATTACHADDR (reset)");
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
174 #endif
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
175 if ((count_lock = usnewlock(shared_arena)) == NULL)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
176 perror("usnewlock (count_lock)");
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
177 (void) usinitlock(count_lock);
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
178 if ((wait_lock = usnewlock(shared_arena)) == NULL)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
179 perror("usnewlock (wait_lock)");
1179
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
180 dprintf(("arena start: %lx, arena size: %ld\n", (long) shared_arena, (long) usconfig(CONF_GETSIZE, shared_arena)));
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
181 #endif
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
182 #ifdef sun
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
183 lwp_setstkcache(STACKSIZE, NSTACKS);
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
184 #endif
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
185 #ifdef C_THREADS
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
186 cthread_init();
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
187 #endif
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
188 }
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
189
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
190 /*
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
191 * Thread support.
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
192 */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 int start_new_thread _P2(func, void (*func) _P((void *)), arg, void *arg)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 thread_t tid;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 #endif
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
198 #if defined(__sgi) && defined(USE_DL)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
199 long addr, size;
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
200 static int local_initialized = 0;
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
201 #endif
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
202 int success = 0; /* init not needed when SOLARIS and */
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
203 /* C_THREADS implemented properly */
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
204
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
205 dprintf(("start_new_thread called\n"));
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 if (!initialized)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 init_thread();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 #ifdef __sgi
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
209 switch (ussetlock(count_lock)) {
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
210 case 0: return 0;
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
211 case -1: perror("ussetlock (count_lock)");
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
212 }
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
213 if (maxpidindex >= MAXPROC)
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
214 success = -1;
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
215 else {
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
216 #ifdef USE_DL
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
217 if (!local_initialized) {
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
218 if ((size = usconfig(CONF_INITSIZE, 64*1024)) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
219 perror("usconfig - CONF_INITSIZE (check)");
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
220 if (usconfig(CONF_INITSIZE, size) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
221 perror("usconfig - CONF_INITSIZE (reset)");
1186
947f8a347c4f ushdr_t was not defined so fill in its size instead of using sizeof.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1184
diff changeset
222 addr = (long) dl_getrange(size + HDR_SIZE);
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
223 dprintf(("trying to use addr %lx-%lx for sproc\n", addr, addr+size));
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
224 errno = 0;
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
225 if ((addr = usconfig(CONF_ATTACHADDR, addr)) < 0 && errno != 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
226 perror("usconfig - CONF_ATTACHADDR (set)");
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
227 }
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
228 #endif
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
229 if ((success = sproc(func, PR_SALL, arg)) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
230 perror("sproc");
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
231 #ifdef USE_DL
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
232 if (!local_initialized) {
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
233 if (usconfig(CONF_ATTACHADDR, addr) < 0) /* reset address */
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
234 perror("usconfig - CONF_ATTACHADDR (reset)");
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
235 local_initialized = 1;
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
236 }
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
237 #endif
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
238 if (success >= 0) {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
239 nthreads++;
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
240 pidlist[maxpidindex++] = success;
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
241 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
242 }
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
243 if (usunsetlock(count_lock) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
244 perror("usunsetlock (count_lock)");
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
245 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
246 #ifdef SOLARIS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
247 (void) thread_create(0, 0, func, arg, THREAD_NEW_LWP);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
248 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 #ifdef sun
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
250 success = lwp_create(&tid, func, MINPRIO, 0, lwp_newstk(), 1, arg);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
251 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
252 #ifdef C_THREADS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
253 (void) cthread_fork(func, arg);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
254 #endif
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
255 return success < 0 ? 0 : 1;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
256 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
257
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
258 static void do_exit_thread _P1(no_cleanup, int no_cleanup)
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
259 {
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
260 dprintf(("exit_thread called\n"));
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
261 if (!initialized)
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
262 if (no_cleanup)
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
263 _exit(0);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
264 else
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
265 exit(0);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
266 #ifdef __sgi
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
267 if (ussetlock(count_lock) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
268 perror("ussetlock (count_lock)");
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
269 nthreads--;
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
270 if (getpid() == my_pid) {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
271 /* main thread; wait for other threads to exit */
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
272 exiting = 1;
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
273 if (do_exit) {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
274 int i;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
275
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
276 /* notify other threads */
1047
6b5a34db21fe Added C++ support in thread.h; don't use signals if not strictly
Sjoerd Mullender <sjoerd@acm.org>
parents: 1005
diff changeset
277 if (nthreads >= 0) {
6b5a34db21fe Added C++ support in thread.h; don't use signals if not strictly
Sjoerd Mullender <sjoerd@acm.org>
parents: 1005
diff changeset
278 dprintf(("kill other threads\n"));
6b5a34db21fe Added C++ support in thread.h; don't use signals if not strictly
Sjoerd Mullender <sjoerd@acm.org>
parents: 1005
diff changeset
279 for (i = 0; i < maxpidindex; i++)
6b5a34db21fe Added C++ support in thread.h; don't use signals if not strictly
Sjoerd Mullender <sjoerd@acm.org>
parents: 1005
diff changeset
280 (void) kill(pidlist[i], SIGKILL);
6b5a34db21fe Added C++ support in thread.h; don't use signals if not strictly
Sjoerd Mullender <sjoerd@acm.org>
parents: 1005
diff changeset
281 _exit(exit_status);
6b5a34db21fe Added C++ support in thread.h; don't use signals if not strictly
Sjoerd Mullender <sjoerd@acm.org>
parents: 1005
diff changeset
282 }
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
283 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
284 waiting_for_threads = 1;
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
285 if (ussetlock(wait_lock) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
286 perror("ussetlock (wait_lock)");
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
287 for (;;) {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
288 if (nthreads < 0) {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
289 dprintf(("really exit (%d)\n", exit_status));
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
290 if (no_cleanup)
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
291 _exit(exit_status);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
292 else
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
293 exit(exit_status);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
294 }
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
295 if (usunsetlock(count_lock) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
296 perror("usunsetlock (count_lock)");
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
297 dprintf(("waiting for other threads (%d)\n", nthreads));
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
298 if (ussetlock(wait_lock) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
299 perror("ussetlock (wait_lock)");
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
300 if (ussetlock(count_lock) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
301 perror("ussetlock (count_lock)");
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
302 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
303 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
304 /* not the main thread */
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
305 if (waiting_for_threads) {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
306 dprintf(("main thread is waiting\n"));
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
307 if (usunsetlock(wait_lock) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
308 perror("usunsetlock (wait_lock)");
1047
6b5a34db21fe Added C++ support in thread.h; don't use signals if not strictly
Sjoerd Mullender <sjoerd@acm.org>
parents: 1005
diff changeset
309 } else if (do_exit)
6b5a34db21fe Added C++ support in thread.h; don't use signals if not strictly
Sjoerd Mullender <sjoerd@acm.org>
parents: 1005
diff changeset
310 (void) kill(my_pid, SIGUSR1);
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
311 if (usunsetlock(count_lock) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
312 perror("usunsetlock (count_lock)");
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
313 _exit(0);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
314 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
315 #ifdef SOLARIS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
316 thread_exit();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
317 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
318 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
319 lwp_destroy(SELF);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
320 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
321 #ifdef C_THREADS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
322 cthread_exit(0);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
323 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
324 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
325
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
326 void exit_thread _P0()
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
327 {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
328 do_exit_thread(0);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
329 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
330
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
331 void _exit_thread _P0()
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
332 {
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
333 do_exit_thread(1);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
334 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
335
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
336 static void do_exit_prog _P2(status, int status, no_cleanup, int no_cleanup)
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
337 {
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
338 dprintf(("exit_prog(%d) called\n", status));
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
339 if (!initialized)
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
340 if (no_cleanup)
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
341 _exit(status);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
342 else
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
343 exit(status);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
344 #ifdef __sgi
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
345 do_exit = 1;
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
346 exit_status = status;
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
347 do_exit_thread(no_cleanup);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
348 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
349 #ifdef sun
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
350 pod_exit(status);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
351 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
352 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
353
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
354 void exit_prog _P1(status, int status)
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
355 {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
356 do_exit_prog(status, 0);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
357 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
358
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
359 void _exit_prog _P1(status, int status)
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
360 {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
361 do_exit_prog(status, 1);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
362 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
363
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
364 /*
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
365 * Lock support.
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
366 */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
367 type_lock allocate_lock _P0()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
368 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
369 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
370 ulock_t lock;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
371 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
372 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
373 struct lock *lock;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
374 extern char *malloc();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
375 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
376
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
377 dprintf(("allocate_lock called\n"));
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
378 if (!initialized)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
379 init_thread();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
380
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
381 #ifdef __sgi
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
382 if ((lock = usnewlock(shared_arena)) == NULL)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
383 perror("usnewlock");
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
384 (void) usinitlock(lock);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
385 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
386 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
387 lock = (struct lock *) malloc(sizeof(struct lock));
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
388 lock->lock_locked = 0;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
389 (void) mon_create(&lock->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
390 (void) cv_create(&lock->lock_condvar, lock->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
391 #endif
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
392 dprintf(("allocate_lock() -> %lx\n", (long)lock));
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
393 return (type_lock) lock;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
394 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
395
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
396 void free_lock _P1(lock, type_lock lock)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
397 {
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
398 dprintf(("free_lock(%lx) called\n", (long)lock));
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
399 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
400 usfreelock((ulock_t) lock, shared_arena);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
401 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
402 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
403 mon_destroy(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
404 free((char *) lock);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
405 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
406 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
407
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
408 int acquire_lock _P2(lock, type_lock lock, waitflag, int waitflag)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
409 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
410 int success;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
411
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
412 dprintf(("acquire_lock(%lx, %d) called\n", (long)lock, waitflag));
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
413 #ifdef __sgi
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
414 errno = 0; /* clear it just in case */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
415 if (waitflag)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
416 success = ussetlock((ulock_t) lock);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
417 else
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
418 success = uscsetlock((ulock_t) lock, 1); /* Try it once */
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
419 if (success < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
420 perror(waitflag ? "ussetlock" : "uscsetlock");
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
421 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
422 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
423 success = 0;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
424
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
425 (void) mon_enter(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
426 if (waitflag)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
427 while (((struct lock *) lock)->lock_locked)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
428 cv_wait(((struct lock *) lock)->lock_condvar);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
429 if (!((struct lock *) lock)->lock_locked) {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
430 success = 1;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
431 ((struct lock *) lock)->lock_locked = 1;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
432 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
433 cv_broadcast(((struct lock *) lock)->lock_condvar);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
434 mon_exit(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
435 #endif
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
436 dprintf(("acquire_lock(%lx, %d) -> %d\n", (long)lock, waitflag, success));
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
437 return success;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
438 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
439
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
440 void release_lock _P1(lock, type_lock lock)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
441 {
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
442 dprintf(("release_lock(%lx) called\n", (long)lock));
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
443 #ifdef __sgi
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
444 if (usunsetlock((ulock_t) lock) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
445 perror("usunsetlock");
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
446 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
447 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
448 (void) mon_enter(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
449 ((struct lock *) lock)->lock_locked = 0;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
450 cv_broadcast(((struct lock *) lock)->lock_condvar);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
451 mon_exit(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
452 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
453 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
454
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
455 /*
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
456 * Semaphore support.
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
457 */
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
458 type_sema allocate_sema _P1(value, int value)
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
459 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
460 #ifdef __sgi
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
461 usema_t *sema;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
462 #endif
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
463
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
464 dprintf(("allocate_sema called\n"));
1047
6b5a34db21fe Added C++ support in thread.h; don't use signals if not strictly
Sjoerd Mullender <sjoerd@acm.org>
parents: 1005
diff changeset
465 if (!initialized)
6b5a34db21fe Added C++ support in thread.h; don't use signals if not strictly
Sjoerd Mullender <sjoerd@acm.org>
parents: 1005
diff changeset
466 init_thread();
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
467
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
468 #ifdef __sgi
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
469 if ((sema = usnewsema(shared_arena, value)) == NULL)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
470 perror("usnewsema");
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
471 dprintf(("allocate_sema() -> %lx\n", (long) sema));
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
472 return (type_sema) sema;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
473 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
474 }
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
475
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
476 void free_sema _P1(sema, type_sema sema)
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
477 {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
478 dprintf(("free_sema(%lx) called\n", (long) sema));
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
479 #ifdef __sgi
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
480 usfreesema((usema_t *) sema, shared_arena);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
481 #endif
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
482 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
483
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
484 void down_sema _P1(sema, type_sema sema)
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
485 {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
486 dprintf(("down_sema(%lx) called\n", (long) sema));
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
487 #ifdef __sgi
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
488 if (uspsema((usema_t *) sema) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
489 perror("uspsema");
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
490 #endif
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
491 dprintf(("down_sema(%lx) return\n", (long) sema));
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
492 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
493
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
494 void up_sema _P1(sema, type_sema sema)
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
495 {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
496 dprintf(("up_sema(%lx)\n", (long) sema));
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
497 #ifdef __sgi
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
498 if (usvsema((usema_t *) sema) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
499 perror("usvsema");
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
500 #endif
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
501 }