annotate Python/thread.c @ 1004:5d7142ea01b7 legacy-trunk

adapted SV module to the new svideo library. update thread package.
author Sjoerd Mullender <sjoerd@acm.org>
date Wed, 02 Sep 1992 11:25:37 +0000
parents a31e07847063
children b33228e3c2c2
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
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
3 <<<<<<< thread.c
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
4 #ifndef DEBUG
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
5 #define DEBUG
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
6 #endif
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
7
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
8 #ifdef DEBUG
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
9 #define dprintf(args) printf args
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
10 #else
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
11 #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
12 #endif
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
13
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
14 =======
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
15 #ifdef DEBUG
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
16 #define dprintf(args) printf args
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
17 #else
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
18 #define dprintf(args)
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
19 #endif
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
20
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
21 >>>>>>> 2.3
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 #include <stdlib.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 #include <stdio.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 #include <signal.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 #include <sys/types.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 #include <sys/prctl.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 #include <ulocks.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
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 #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
31
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 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
33 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
34 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
35 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
36 static int nthreads; /* protected by count_lock */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 static int exit_status;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 static int do_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
39 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
40 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
41 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
42 static int maxpidindex; /* # of PIDs in pidlist */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 #include <lwp/lwp.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 #include <lwp/stackdep.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
47
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
48 #define STACKSIZE 1000 /* stacksize for a thread */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 #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
50
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 struct lock {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 int lock_locked;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 cv_t lock_condvar;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 mon_t lock_monitor;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 };
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 #ifdef C_THREADS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 #include <cthreads.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
60
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 #ifdef __STDC__
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 #define _P(args) args
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 #define _P0() (void)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 #define _P1(v,t) (t)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 #define _P2(v1,t1,v2,t2) (t1,t2)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 #else
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 #define _P(args) ()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 #define _P0() ()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 #define _P1(v,t) (v) t;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 #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
71 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
72
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 static int initialized;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
74
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
75 <<<<<<< thread.c
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
76 #ifdef __sgi
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
77 /*
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
78 * 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
79 * 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
80 * 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
81 */
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
82 static void exit_sig _P0()
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 dprintf(("exit_sig called\n"));
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
85 if (exiting && getpid() == my_pid) {
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
86 dprintf(("already exiting\n"));
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
87 return;
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 if (do_exit) {
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
90 dprintf(("exiting in exit_sig\n"));
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
91 exit_thread();
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
92 }
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
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 * 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
97 * 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
98 */
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
99 static void maybe_exit _P0()
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 dprintf(("maybe_exit called\n"));
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
102 if (exiting) {
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
103 dprintf(("already exiting\n"));
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
104 return;
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 exit_prog(0);
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 #endif
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
109
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
110 /*
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
111 * Initialization.
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
112 */
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
113 void init_thread _P0()
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
114 {
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
115 #ifdef __sgi
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
116 struct sigaction s;
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
117 #endif
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 dprintf(("init_thread called\n"));
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
120 if (initialized)
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
121 return;
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
122 initialized = 1;
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 #ifdef __sgi
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
125 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
126 atexit(maybe_exit);
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
127 s.sa_handler = exit_sig;
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
128 sigemptyset(&s.sa_mask);
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
129 sigaddset(&s.sa_mask, SIGUSR1);
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
130 s.sa_flags = 0;
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
131 sigaction(SIGUSR1, &s, 0);
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
132 prctl(PR_SETEXITSIG, SIGUSR1);
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
133 usconfig(CONF_ARENATYPE, US_SHAREDONLY);
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
134 /*usconfig(CONF_LOCKTYPE, US_DEBUGPLUS);*/
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
135 shared_arena = usinit(tmpnam(0));
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
136 count_lock = usnewlock(shared_arena);
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
137 (void) usinitlock(count_lock);
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
138 wait_lock = usnewlock(shared_arena);
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
139 #endif
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
140 #ifdef sun
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
141 lwp_setstkcache(STACKSIZE, NSTACKS);
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
142 #endif
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
143 #ifdef C_THREADS
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
144 cthread_init();
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
145 #endif
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
146 }
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
147
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
148 /*
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
149 * Thread support.
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
150 */
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
151 =======
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
152 #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
153 /*
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
154 * This routine is called as a signal handler when another thread
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
155 * exits. When that happens, we must see whether we have to exit as
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
156 * well (because of an exit_prog()) or whether we should continue on.
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
157 */
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
158 static void exit_sig _P0()
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
159 {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
160 dprintf(("exit_sig 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
161 if (exiting && 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
162 dprintf(("already exiting\n"));
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
163 return;
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
164 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
165 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
166 dprintf(("exiting in exit_sig\n"));
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
167 exit_thread();
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
168 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
169 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
170
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
171 /*
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
172 * This routune is called when a process calls exit(). If that wasn't
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
173 * done from the library, we do as if an exit_prog() was intended.
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
174 */
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
175 static void maybe_exit _P0()
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
176 {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
177 dprintf(("maybe_exit 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
178 if (exiting) {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
179 dprintf(("already exiting\n"));
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
180 return;
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
181 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
182 exit_prog(0);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
183 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
184 #endif
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
185
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
186 /*
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
187 * Initialization.
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
188 */
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
189 void init_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
190 {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
191 #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
192 struct sigaction s;
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
193 #endif
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
194
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
195 dprintf(("init_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
196 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
197 return;
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
198 initialized = 1;
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
199
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
200 #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
201 my_pid = getpid(); /* so that we know which is 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
202 atexit(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
203 s.sa_handler = exit_sig;
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
204 sigemptyset(&s.sa_mask);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
205 sigaddset(&s.sa_mask, SIGUSR1);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
206 s.sa_flags = 0;
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
207 sigaction(SIGUSR1, &s, 0);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
208 prctl(PR_SETEXITSIG, SIGUSR1);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
209 usconfig(CONF_ARENATYPE, US_SHAREDONLY);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
210 /*usconfig(CONF_LOCKTYPE, US_DEBUGPLUS);*/
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
211 shared_arena = usinit(tmpnam(0));
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
212 count_lock = usnewlock(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
213 (void) usinitlock(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
214 wait_lock = usnewlock(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
215 #endif
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
216 #ifdef sun
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
217 lwp_setstkcache(STACKSIZE, NSTACKS);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
218 #endif
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
219 #ifdef C_THREADS
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
220 cthread_init();
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
221 #endif
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
222 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
223
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
224 /*
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
225 * Thread support.
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
226 */
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
227 >>>>>>> 2.3
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 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
229 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 thread_t tid;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
232 #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
233 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
234 /* 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
235
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
236 dprintf(("start_new_thread called\n"));
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 if (!initialized)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 init_thread();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 #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
240 if (ussetlock(count_lock) == 0)
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 return 0;
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
242 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
243 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
244 else {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
245 success = sproc(func, PR_SALL, arg);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
246 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
247 nthreads++;
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
248 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
249 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
250 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
251 (void) usunsetlock(count_lock);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
252 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
253 #ifdef SOLARIS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
254 (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
255 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
256 #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
257 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
258 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
259 #ifdef C_THREADS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 (void) cthread_fork(func, arg);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
261 #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
262 return success < 0 ? 0 : 1;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
263 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
264
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
265 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
266 {
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
267 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
268 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
269 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
270 _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
271 else
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
272 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
273 #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
274 (void) ussetlock(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
275 nthreads--;
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
276 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
277 /* 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
278 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
279 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
280 int i;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
281
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
282 /* notify 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
283 for (i = 0; i < maxpidindex; i++)
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
284 (void) kill(pidlist[i], SIGUSR1);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
285 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
286 waiting_for_threads = 1;
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
287 ussetlock(wait_lock);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
288 for (;;) {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
289 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
290 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
291 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
292 _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
293 else
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
294 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
295 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
296 usunsetlock(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
297 dprintf(("waiting for other threads (%d)\n", nthreads));
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
298 ussetlock(wait_lock);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
299 ussetlock(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
300 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
301 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
302 /* 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
303 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
304 dprintf(("main thread is waiting\n"));
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
305 usunsetlock(wait_lock);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
306 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
307 (void) usunsetlock(count_lock);
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
308 _exit(0);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
309 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
310 #ifdef SOLARIS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
311 thread_exit();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
312 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
313 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
314 lwp_destroy(SELF);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
315 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
316 #ifdef C_THREADS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
317 cthread_exit(0);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
318 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
319 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
320
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
321 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
322 {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
323 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
324 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
325
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()
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
327 {
961
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(1);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
329 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
330
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
331 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
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 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
334 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
335 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
336 _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
337 else
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
338 exit(status);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
339 #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
340 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
341 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
342 do_exit_thread(no_cleanup);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
343 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
344 #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
345 pod_exit(status);
923
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 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
348
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
349 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
350 {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
351 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
352 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
353
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, 1);
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 /*
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
360 * 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
361 */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
362 type_lock allocate_lock _P0()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
363 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
364 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
365 ulock_t lock;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
366 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
367 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
368 struct lock *lock;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
369 extern char *malloc();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
370 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
371
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
372 dprintf(("allocate_lock called\n"));
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
373 if (!initialized)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
374 init_thread();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
375
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
376 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
377 lock = usnewlock(shared_arena);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
378 (void) usinitlock(lock);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
379 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
380 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
381 lock = (struct lock *) malloc(sizeof(struct lock));
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
382 lock->lock_locked = 0;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
383 (void) mon_create(&lock->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
384 (void) cv_create(&lock->lock_condvar, lock->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
385 #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
386 dprintf(("allocate_lock() -> %lx\n", (long)lock));
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
387 return (type_lock) lock;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
388 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
389
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
390 void free_lock _P1(lock, type_lock lock)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
391 {
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(("free_lock(%lx) called\n", (long)lock));
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
393 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
394 usfreelock((ulock_t) lock, shared_arena);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
395 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
396 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
397 mon_destroy(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
398 free((char *) lock);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
399 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
400 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
401
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
402 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
403 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
404 int success;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
405
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
406 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
407 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
408 if (waitflag)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
409 success = ussetlock((ulock_t) lock);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
410 else
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
411 success = uscsetlock((ulock_t) lock, 1); /* Try it once */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
412 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
413 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
414 success = 0;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
415
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
416 (void) mon_enter(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
417 if (waitflag)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
418 while (((struct lock *) lock)->lock_locked)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
419 cv_wait(((struct lock *) lock)->lock_condvar);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
420 if (!((struct lock *) lock)->lock_locked) {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
421 success = 1;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
422 ((struct lock *) lock)->lock_locked = 1;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
423 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
424 cv_broadcast(((struct lock *) lock)->lock_condvar);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
425 mon_exit(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
426 #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
427 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
428 return success;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
429 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
430
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
431 void release_lock _P1(lock, type_lock lock)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
432 {
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
433 dprintf(("release_lock(%lx) called\n", (long)lock));
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
434 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
435 (void) usunsetlock((ulock_t) lock);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
436 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
437 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
438 (void) mon_enter(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
439 ((struct lock *) lock)->lock_locked = 0;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
440 cv_broadcast(((struct lock *) lock)->lock_condvar);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
441 mon_exit(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
442 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
443 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
444
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
445 /*
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
446 * 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
447 */
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
448 type_sema allocate_sema _P1(value, int value)
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
449 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
450 #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
451 usema_t *sema;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
452 #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
453
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
454 dprintf(("allocate_sema 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
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 #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
457 sema = usnewsema(shared_arena, value);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
458 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
459 return (type_sema) sema;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
460 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
461 }
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
462
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
463 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
464 {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
465 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
466 #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
467 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
468 #endif
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
469 }
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 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
472 {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
473 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
474 #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
475 (void) uspsema((usema_t *) sema);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
476 #endif
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
477 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
478 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
479
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
480 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
481 {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
482 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
483 #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
484 (void) usvsema((usema_t *) 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 #endif
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
486 }