annotate Python/thread.c @ 1179:9ae65ee09735 legacy-trunk

Various changes. * Makefile: svmodule.c.proto and svgen.py are gone, svmodule.c came in their stead. Also, pass -DUSE_DL flag to thread.c and give the user a possibility to add the -DDEBUG to just thread.c. * ceval.c: init_save_thread() can be called more than once now. * svgen.py, svmodule.c.proto, svmodule.c: Removed prototype file and replaced it by the generated file. * thread.c: Added some more checks; added call to DL library when it is also used to tell it where the shared arena is so that DL can use some other area. * threadmodule.c: Call init_save_thread from another place. Also, added new function getlocklock() which does to lock objects what getfilefile does to file objects.
author Sjoerd Mullender <sjoerd@acm.org>
date Wed, 06 Jan 1993 13:36:38 +0000
parents 6b5a34db21fe
children cf8ddb29e26e
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>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
18 #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
19
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 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
21 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
22 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
23 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
24 static int nthreads; /* protected by count_lock */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 static int exit_status;
1179
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
26 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
27 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
28 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
29 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
30 static int maxpidindex; /* # of PIDs in pidlist */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 #include <lwp/lwp.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 #include <lwp/stackdep.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
36 #define STACKSIZE 1000 /* stacksize for a thread */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 #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
38
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 struct lock {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 int lock_locked;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 cv_t lock_condvar;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 mon_t lock_monitor;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 };
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 #ifdef C_THREADS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 #include <cthreads.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
48
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 #ifdef __STDC__
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 #define _P(args) args
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 #define _P0() (void)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 #define _P1(v,t) (t)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 #define _P2(v1,t1,v2,t2) (t1,t2)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 #else
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 #define _P(args) ()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 #define _P0() ()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 #define _P1(v,t) (v) t;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 #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
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 static int initialized;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
62
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
63 #ifdef __sgi
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
64 /*
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
65 * 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
66 * 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
67 * 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
68 */
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
69 static void exit_sig _P0()
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
70 {
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
71 dprintf(("exit_sig called\n"));
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
72 if (exiting && getpid() == my_pid) {
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
73 dprintf(("already exiting\n"));
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
74 return;
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
75 }
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
76 if (do_exit) {
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
77 dprintf(("exiting in exit_sig\n"));
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
78 exit_thread();
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
79 }
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 * 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
84 * 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
85 */
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
86 static void maybe_exit _P0()
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
87 {
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
88 dprintf(("maybe_exit called\n"));
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
89 if (exiting) {
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
90 dprintf(("already exiting\n"));
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
91 return;
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 exit_prog(0);
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 #endif
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
96
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
97 /*
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
98 * Initialization.
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
99 */
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
100 void init_thread _P0()
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
101 {
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
102 #ifdef __sgi
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
103 struct sigaction s;
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
104 #endif
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
105
1047
6b5a34db21fe Added C++ support in thread.h; don't use signals if not strictly
Sjoerd Mullender <sjoerd@acm.org>
parents: 1005
diff changeset
106 #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
107 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
108 #endif
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
109 if (initialized)
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
110 return;
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
111 initialized = 1;
1179
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
112 dprintf(("init_thread called\n"));
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
113
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
114 #ifdef __sgi
1179
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
115 if (usconfig(CONF_INITUSERS, 16) < 0)
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
116 perror("usconfig - CONF_INITUSERS");
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
117 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
118 atexit(maybe_exit);
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
119 s.sa_handler = exit_sig;
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
120 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
121 /*sigaddset(&s.sa_mask, SIGUSR1);*/
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
122 s.sa_flags = 0;
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
123 sigaction(SIGUSR1, &s, 0);
1179
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
124 if (prctl(PR_SETEXITSIG, SIGUSR1) < 0)
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
125 perror("prctl - PR_SETEXITSIG");
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
126 if (usconfig(CONF_ARENATYPE, US_SHAREDONLY) < 0)
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
127 perror("usconfig - CONF_ARENATYPE");
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
128 /*usconfig(CONF_LOCKTYPE, US_DEBUGPLUS);*/
1179
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
129 if ((shared_arena = usinit(tmpnam(0))) == 0)
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
130 perror("usinit");
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
131 count_lock = usnewlock(shared_arena);
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
132 (void) usinitlock(count_lock);
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
133 wait_lock = usnewlock(shared_arena);
1179
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
134 dprintf(("arena start: %lx, arena size: %ld\n", (long) shared_arena, (long) usconfig(CONF_GETSIZE, shared_arena)));
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
135 #ifdef USE_DL /* for python */
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
136 dl_setrange((long) shared_arena, (long) shared_arena + 64 * 1024);
9ae65ee09735 Various changes.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1047
diff changeset
137 #endif
1004
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
138 #endif
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
139 #ifdef sun
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
140 lwp_setstkcache(STACKSIZE, NSTACKS);
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
141 #endif
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
142 #ifdef C_THREADS
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
143 cthread_init();
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
144 #endif
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
145 }
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 * Thread support.
5d7142ea01b7 adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents: 961
diff changeset
149 */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 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
151 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 thread_t tid;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 #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
155 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
156 /* 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
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 dprintf(("start_new_thread called\n"));
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 if (!initialized)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 init_thread();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 #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
162 if (ussetlock(count_lock) == 0)
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 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
164 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
165 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
166 else {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
167 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
168 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
169 nthreads++;
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
170 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
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 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
173 (void) usunsetlock(count_lock);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 #ifdef SOLARIS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 (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
177 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 #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
179 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
180 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 #ifdef C_THREADS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 (void) cthread_fork(func, arg);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
183 #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
184 return success < 0 ? 0 : 1;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
186
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
187 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
188 {
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
189 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
190 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
191 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
192 _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
193 else
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
194 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
195 #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
196 (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
197 nthreads--;
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
198 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
199 /* 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
200 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
201 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
202 int i;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
203
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
204 /* 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
205 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
206 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
207 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
208 (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
209 _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
210 }
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
211 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
212 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
213 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
214 for (;;) {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
215 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
216 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
217 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
218 _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
219 else
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
220 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
221 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
222 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
223 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
224 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
225 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
226 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
227 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
228 /* 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
229 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
230 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
231 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
232 } 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
233 (void) kill(my_pid, SIGUSR1);
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
234 (void) usunsetlock(count_lock);
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
235 _exit(0);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 #ifdef SOLARIS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 thread_exit();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 lwp_destroy(SELF);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
242 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 #ifdef C_THREADS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 cthread_exit(0);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
245 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
246 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
247
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
248 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
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 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
251 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
252
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
253 void _exit_thread _P0()
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
254 {
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
255 do_exit_thread(1);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
256 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
257
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
258 static void do_exit_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
259 {
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
260 dprintf(("exit_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
261 if (!initialized)
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
262 if (no_cleanup)
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
263 _exit(status);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
264 else
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
265 exit(status);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
266 #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
267 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
268 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
269 do_exit_thread(no_cleanup);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
270 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
271 #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
272 pod_exit(status);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
273 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
274 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
275
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
276 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
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 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
279 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
280
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
281 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
282 {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
283 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
284 }
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 /*
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
287 * 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
288 */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
289 type_lock allocate_lock _P0()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
290 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
291 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
292 ulock_t lock;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
293 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
294 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
295 struct lock *lock;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
296 extern char *malloc();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
297 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
298
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
299 dprintf(("allocate_lock called\n"));
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
300 if (!initialized)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
301 init_thread();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
302
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
303 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
304 lock = usnewlock(shared_arena);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
305 (void) usinitlock(lock);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
306 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
307 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
308 lock = (struct lock *) malloc(sizeof(struct lock));
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
309 lock->lock_locked = 0;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
310 (void) mon_create(&lock->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
311 (void) cv_create(&lock->lock_condvar, lock->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
312 #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
313 dprintf(("allocate_lock() -> %lx\n", (long)lock));
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
314 return (type_lock) lock;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
315 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
316
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
317 void free_lock _P1(lock, type_lock lock)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
318 {
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
319 dprintf(("free_lock(%lx) called\n", (long)lock));
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
320 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
321 usfreelock((ulock_t) lock, shared_arena);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
322 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
323 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
324 mon_destroy(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
325 free((char *) lock);
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
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
329 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
330 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
331 int success;
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(("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
334 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
335 if (waitflag)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
336 success = ussetlock((ulock_t) lock);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
337 else
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
338 success = uscsetlock((ulock_t) lock, 1); /* Try it once */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
339 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
340 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
341 success = 0;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
342
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
343 (void) mon_enter(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
344 if (waitflag)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
345 while (((struct lock *) lock)->lock_locked)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
346 cv_wait(((struct lock *) lock)->lock_condvar);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
347 if (!((struct lock *) lock)->lock_locked) {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
348 success = 1;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
349 ((struct lock *) lock)->lock_locked = 1;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
350 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
351 cv_broadcast(((struct lock *) lock)->lock_condvar);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
352 mon_exit(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
353 #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
354 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
355 return success;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
356 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
357
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
358 void release_lock _P1(lock, type_lock lock)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
359 {
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
360 dprintf(("release_lock(%lx) called\n", (long)lock));
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
361 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
362 (void) usunsetlock((ulock_t) lock);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
363 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
364 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
365 (void) mon_enter(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
366 ((struct lock *) lock)->lock_locked = 0;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
367 cv_broadcast(((struct lock *) lock)->lock_condvar);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
368 mon_exit(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
369 #endif
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
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 /*
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
373 * 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
374 */
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
375 type_sema allocate_sema _P1(value, int value)
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
376 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
377 #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
378 usema_t *sema;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
379 #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
380
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
381 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
382 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
383 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
384
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
385 #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
386 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
387 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
388 return (type_sema) sema;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
389 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
390 }
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
391
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
392 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
393 {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
394 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
395 #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
396 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
397 #endif
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
398 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
399
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
400 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
401 {
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
402 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
403 #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
404 (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
405 #endif
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(("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
407 }
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
408
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
409 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
410 {
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(("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
412 #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
413 (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
414 #endif
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
415 }