annotate Python/thread.c @ 1184:cf8ddb29e26e legacy-trunk

Added error checking. Improved coexistance with dl module.
author Sjoerd Mullender <sjoerd@acm.org>
date Wed, 13 Jan 1993 12:08:48 +0000
parents 9ae65ee09735
children 947f8a347c4f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 #include "thread.h"
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
3 #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
4 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
5 #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
6 #else
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
7 #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
8 #endif
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
9
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 #include <stdlib.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 #include <stdio.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 #include <signal.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 #include <sys/types.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 #include <sys/prctl.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 #include <ulocks.h>
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
17 #include <errno.h>
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
18
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
19 #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
20
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 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
22 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
23 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
24 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
25 static int nthreads; /* protected by count_lock */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 static int exit_status;
1179
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
27 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
28 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
29 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
30 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
31 static int maxpidindex; /* # of PIDs in pidlist */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 #include <lwp/lwp.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 #include <lwp/stackdep.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
36
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
37 #define STACKSIZE 1000 /* stacksize for a thread */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 #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
39
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 struct lock {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 int lock_locked;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 cv_t lock_condvar;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 mon_t lock_monitor;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 };
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 #ifdef C_THREADS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 #include <cthreads.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
49
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 #ifdef __STDC__
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 #define _P(args) args
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 #define _P0() (void)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 #define _P1(v,t) (t)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 #define _P2(v1,t1,v2,t2) (t1,t2)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 #else
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 #define _P(args) ()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 #define _P0() ()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 #define _P1(v,t) (v) t;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 #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
60 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
61
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 static int initialized;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
63
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
64 #ifdef __sgi
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
65 /*
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
66 * 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
67 * 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
68 * 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
69 */
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
70 static void exit_sig _P0()
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
71 {
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
72 dprintf(("exit_sig called\n"));
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
73 if (exiting && getpid() == my_pid) {
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
74 dprintf(("already exiting\n"));
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
75 return;
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
76 }
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
77 if (do_exit) {
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
78 dprintf(("exiting in exit_sig\n"));
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
79 exit_thread();
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
80 }
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
81 }
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
82
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
83 /*
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
84 * 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
85 * 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
86 */
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
87 static void maybe_exit _P0()
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
88 {
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
89 dprintf(("maybe_exit called\n"));
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
90 if (exiting) {
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
91 dprintf(("already exiting\n"));
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
92 return;
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
93 }
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
94 exit_prog(0);
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
95 }
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
96 #endif
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
97
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
98 /*
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
99 * Initialization.
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
100 */
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
101 void init_thread _P0()
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
102 {
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
103 #ifdef __sgi
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
104 struct sigaction s;
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
105 #ifdef USE_DL
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
106 long addr, size;
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
107 #endif
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
108 #endif
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
109
1047
6b5a34db21fe Added C++ support in thread.h; don't use signals if not strictly
Sjoerd Mullender <sjoerd@acm.org>
parents: 1005
diff changeset
110 #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
111 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
112 #endif
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
113 if (initialized)
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
114 return;
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
115 initialized = 1;
1179
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
116 dprintf(("init_thread called\n"));
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
117
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
118 #ifdef __sgi
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
119 #ifdef USE_DL
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
120 if ((size = usconfig(CONF_INITSIZE, 64*1024)) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
121 perror("usconfig - CONF_INITSIZE (check)");
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
122 if (usconfig(CONF_INITSIZE, size) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
123 perror("usconfig - CONF_INITSIZE (reset)");
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
124 addr = (long) dl_getrange(size + sizeof(ushdr_t));
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
125 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
126 errno = 0;
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
127 if ((addr = usconfig(CONF_ATTACHADDR, addr)) < 0 && errno != 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
128 perror("usconfig - CONF_ATTACHADDR (set)");
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
129 #endif
1179
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
130 if (usconfig(CONF_INITUSERS, 16) < 0)
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
131 perror("usconfig - CONF_INITUSERS");
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
132 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
133 atexit(maybe_exit);
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
134 s.sa_handler = exit_sig;
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
135 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
136 /*sigaddset(&s.sa_mask, SIGUSR1);*/
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
137 s.sa_flags = 0;
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
138 sigaction(SIGUSR1, &s, 0);
1179
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
139 if (prctl(PR_SETEXITSIG, SIGUSR1) < 0)
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
140 perror("prctl - PR_SETEXITSIG");
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
141 if (usconfig(CONF_ARENATYPE, US_SHAREDONLY) < 0)
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
142 perror("usconfig - CONF_ARENATYPE");
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
143 /*usconfig(CONF_LOCKTYPE, US_DEBUGPLUS);*/
1179
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
144 if ((shared_arena = usinit(tmpnam(0))) == 0)
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
145 perror("usinit");
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
146 #ifdef USE_DL
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
147 if (usconfig(CONF_ATTACHADDR, addr) < 0) /* reset address */
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
148 perror("usconfig - CONF_ATTACHADDR (reset)");
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
149 #endif
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
150 if ((count_lock = usnewlock(shared_arena)) == NULL)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
151 perror("usnewlock (count_lock)");
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
152 (void) usinitlock(count_lock);
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
153 if ((wait_lock = usnewlock(shared_arena)) == NULL)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
154 perror("usnewlock (wait_lock)");
1179
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
155 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
156 #endif
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
157 #ifdef sun
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
158 lwp_setstkcache(STACKSIZE, NSTACKS);
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
159 #endif
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
160 #ifdef C_THREADS
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
161 cthread_init();
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
162 #endif
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
163 }
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
164
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
165 /*
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
166 * Thread support.
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
167 */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 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
169 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 thread_t tid;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 #endif
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
173 #if defined(__sgi) && defined(USE_DL)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
174 long addr, size;
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
175 static int local_initialized = 0;
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
176 #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
177 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
178 /* 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
179
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
180 dprintf(("start_new_thread called\n"));
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 if (!initialized)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 init_thread();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
183 #ifdef __sgi
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
184 switch (ussetlock(count_lock)) {
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
185 case 0: return 0;
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
186 case -1: perror("ussetlock (count_lock)");
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
187 }
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
188 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
189 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
190 else {
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
191 #ifdef USE_DL
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
192 if (!local_initialized) {
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
193 if ((size = usconfig(CONF_INITSIZE, 64*1024)) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
194 perror("usconfig - CONF_INITSIZE (check)");
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
195 if (usconfig(CONF_INITSIZE, size) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
196 perror("usconfig - CONF_INITSIZE (reset)");
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
197 addr = (long) dl_getrange(size + sizeof(ushdr_t));
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
198 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
199 errno = 0;
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
200 if ((addr = usconfig(CONF_ATTACHADDR, addr)) < 0 && errno != 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
201 perror("usconfig - CONF_ATTACHADDR (set)");
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
202 }
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
203 #endif
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
204 if ((success = sproc(func, PR_SALL, arg)) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
205 perror("sproc");
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
206 #ifdef USE_DL
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
207 if (!local_initialized) {
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
208 if (usconfig(CONF_ATTACHADDR, addr) < 0) /* reset address */
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
209 perror("usconfig - CONF_ATTACHADDR (reset)");
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
210 local_initialized = 1;
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
211 }
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
212 #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
213 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
214 nthreads++;
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
215 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
216 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
217 }
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
218 if (usunsetlock(count_lock) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
219 perror("usunsetlock (count_lock)");
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
220 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 #ifdef SOLARIS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
222 (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
223 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
224 #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
225 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
226 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
227 #ifdef C_THREADS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 (void) cthread_fork(func, arg);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
229 #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
230 return success < 0 ? 0 : 1;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
232
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
233 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
234 {
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
235 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
236 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
237 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
238 _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
239 else
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
240 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
241 #ifdef __sgi
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
242 if (ussetlock(count_lock) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
243 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
244 nthreads--;
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
245 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
246 /* 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
247 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
248 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
249 int i;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
250
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
251 /* 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
252 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
253 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
254 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
255 (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
256 _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
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 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
259 waiting_for_threads = 1;
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
260 if (ussetlock(wait_lock) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
261 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
262 for (;;) {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
263 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
264 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
265 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
266 _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
267 else
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
268 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
269 }
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
270 if (usunsetlock(count_lock) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
271 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
272 dprintf(("waiting for other threads (%d)\n", nthreads));
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
273 if (ussetlock(wait_lock) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
274 perror("ussetlock (wait_lock)");
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
275 if (ussetlock(count_lock) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
276 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
277 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
278 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
279 /* 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
280 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
281 dprintf(("main thread is waiting\n"));
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
282 if (usunsetlock(wait_lock) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
283 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
284 } 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
285 (void) kill(my_pid, SIGUSR1);
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
286 if (usunsetlock(count_lock) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
287 perror("usunsetlock (count_lock)");
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
288 _exit(0);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
289 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
290 #ifdef SOLARIS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
291 thread_exit();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
292 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
293 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
294 lwp_destroy(SELF);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
295 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
296 #ifdef C_THREADS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
297 cthread_exit(0);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
298 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
299 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
300
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
301 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
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 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
304 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
305
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
306 void _exit_thread _P0()
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
307 {
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
308 do_exit_thread(1);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
309 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
310
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
311 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
312 {
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
313 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
314 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
315 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
316 _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
317 else
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
318 exit(status);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
319 #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
320 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
321 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
322 do_exit_thread(no_cleanup);
923
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 #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
325 pod_exit(status);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
326 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
327 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
328
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
329 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
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 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
332 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
333
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
334 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
335 {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
336 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
337 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
338
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
339 /*
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
340 * 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
341 */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
342 type_lock allocate_lock _P0()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
343 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
344 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
345 ulock_t lock;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
346 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
347 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
348 struct lock *lock;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
349 extern char *malloc();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
350 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
351
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
352 dprintf(("allocate_lock called\n"));
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
353 if (!initialized)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
354 init_thread();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
355
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
356 #ifdef __sgi
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
357 if ((lock = usnewlock(shared_arena)) == NULL)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
358 perror("usnewlock");
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
359 (void) usinitlock(lock);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
360 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
361 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
362 lock = (struct lock *) malloc(sizeof(struct lock));
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
363 lock->lock_locked = 0;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
364 (void) mon_create(&lock->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
365 (void) cv_create(&lock->lock_condvar, lock->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
366 #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
367 dprintf(("allocate_lock() -> %lx\n", (long)lock));
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
368 return (type_lock) lock;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
369 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
370
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
371 void free_lock _P1(lock, type_lock lock)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
372 {
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
373 dprintf(("free_lock(%lx) called\n", (long)lock));
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
374 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
375 usfreelock((ulock_t) lock, shared_arena);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
376 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
377 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
378 mon_destroy(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
379 free((char *) lock);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
380 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
381 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
382
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
383 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
384 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
385 int success;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
386
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
387 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
388 #ifdef __sgi
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
389 errno = 0; /* clear it just in case */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
390 if (waitflag)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
391 success = ussetlock((ulock_t) lock);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
392 else
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
393 success = uscsetlock((ulock_t) lock, 1); /* Try it once */
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
394 if (success < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
395 perror(waitflag ? "ussetlock" : "uscsetlock");
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
396 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
397 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
398 success = 0;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
399
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
400 (void) mon_enter(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
401 if (waitflag)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
402 while (((struct lock *) lock)->lock_locked)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
403 cv_wait(((struct lock *) lock)->lock_condvar);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
404 if (!((struct lock *) lock)->lock_locked) {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
405 success = 1;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
406 ((struct lock *) lock)->lock_locked = 1;
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 cv_broadcast(((struct lock *) lock)->lock_condvar);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
409 mon_exit(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
410 #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
411 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
412 return success;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
413 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
414
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
415 void release_lock _P1(lock, type_lock lock)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
416 {
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
417 dprintf(("release_lock(%lx) called\n", (long)lock));
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
418 #ifdef __sgi
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
419 if (usunsetlock((ulock_t) lock) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
420 perror("usunsetlock");
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 (void) mon_enter(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
424 ((struct lock *) lock)->lock_locked = 0;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
425 cv_broadcast(((struct lock *) lock)->lock_condvar);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
426 mon_exit(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
427 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
428 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
429
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
430 /*
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
431 * 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
432 */
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
433 type_sema allocate_sema _P1(value, int value)
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
434 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
435 #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
436 usema_t *sema;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
437 #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
438
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
439 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
440 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
441 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
442
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
443 #ifdef __sgi
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
444 if ((sema = usnewsema(shared_arena, value)) == NULL)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
445 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
446 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
447 return (type_sema) sema;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
448 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
449 }
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
450
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
451 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
452 {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
453 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
454 #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
455 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
456 #endif
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
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
459 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
460 {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
461 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
462 #ifdef __sgi
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
463 if (uspsema((usema_t *) sema) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
464 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
465 #endif
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
466 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
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
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
469 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
470 {
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(("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
472 #ifdef __sgi
1184
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
473 if (usvsema((usema_t *) sema) < 0)
cf8ddb29e26e Added error checking.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1179
diff changeset
474 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
475 #endif
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
476 }