annotate Python/thread.c @ 926:c156d4960c2b legacy-trunk

* Makefile: cosmetics * socketmodule.c: get rid of makepair(); fix makesocketaddr to fix broken recvfrom() * socketmodule: get rid of getStrarg() * ceval.h: move eval_code() to new file eval.h, so compile.h is no longer needed. * ceval.c: move thread comments to ceval.h; always make save/restore thread functions available (for dynloaded modules) * cdmodule.c, listobject.c: don't include compile.h * flmodule.c: include ceval.h * import.c: include eval.h instead of ceval.h * cgen.py: add forground(); noport(); winopen(""); to initgl(). * bltinmodule.c, socketmodule.c, fileobject.c, posixmodule.c, selectmodule.c: adapt to threads (add BGN/END SAVE macros) * stdwinmodule.c: adapt to threads and use a special stdwin lock. * pythonmain.c: don't include getpythonpath(). * pythonrun.c: use BGN/END SAVE instead of direct calls; also more BGN/END SAVE calls etc. * thread.c: bigger stack size for sun; change exit() to _exit() * threadmodule.c: use BGN/END SAVE macros where possible * timemodule.c: adapt better to threads; use BGN/END SAVE; add longsleep internal function if BSD_TIME; cosmetics
author Guido van Rossum <guido@python.org>
date Wed, 05 Aug 1992 19:58:53 +0000
parents 72aceed365d4
children a31e07847063
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
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 #include <stdlib.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 #include <stdio.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 #include <signal.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 #include <sys/types.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 #include <sys/prctl.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 #include <ulocks.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 static usptr_t *shared_arena;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 static int exit_status;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 static int do_exit;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 static int exiting;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 #include <lwp/lwp.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 #include <lwp/stackdep.h>
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
20 #define STACKSIZE 16000 /* stacksize for a thread */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 #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
22
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 struct lock {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 int lock_locked;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 cv_t lock_condvar;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 mon_t lock_monitor;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 };
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 #ifdef C_THREADS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 #include <cthreads.h>
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
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 #ifdef __STDC__
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 #define _P(args) args
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 #define _P0() (void)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 #define _P1(v,t) (t)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 #define _P2(v1,t1,v2,t2) (t1,t2)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 #else
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 #define _P(args) ()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 #define _P0() ()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 #define _P1(v,t) (v) t;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 #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
43 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
44
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 static int initialized;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
46
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 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
48 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 thread_t tid;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 #ifdef DEBUG
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 printf("start_new_thread called\n");
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 if (!initialized)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 init_thread();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 if (sproc(func, PR_SALL, arg) < 0)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 return 0;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 return 1;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 #ifdef SOLARIS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 (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
64 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 if (lwp_create(&tid, func, MINPRIO, 0, lwp_newstk(), 1, arg) < 0)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 return 0;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 return 1;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 #ifdef C_THREADS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 (void) cthread_fork(func, arg);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
74
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 void maybe_exit _P0()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 if (exiting)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 return;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 exit_prog(0);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
83
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 void exit_thread _P0()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 #ifdef DEBUG
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 printf("exit_thread called\n");
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 if (!initialized)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 exit(0);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 exiting = 1;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
93 _exit(0);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 #ifdef SOLARIS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 thread_exit();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 lwp_destroy(SELF);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 #ifdef C_THREADS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 cthread_exit(0);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
105
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 static void exit_sig _P0()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 #ifdef DEBUG
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 printf("exit_sig called\n");
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 if (do_exit) {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 #ifdef DEBUG
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 printf("exiting in exit_sig\n");
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 #endif
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
116 _exit(exit_status);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
120
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 void init_thread _P0()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 struct sigaction s;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
126
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 #ifdef DEBUG
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 printf("init_thread called\n");
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 initialized = 1;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
131
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 atexit(maybe_exit);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 s.sa_handler = exit_sig;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 sigemptyset(&s.sa_mask);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 sigaddset(&s.sa_mask, SIGUSR1);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 s.sa_flags = 0;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 sigaction(SIGUSR1, &s, 0);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 prctl(PR_SETEXITSIG, SIGUSR1);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 usconfig(CONF_ARENATYPE, US_SHAREDONLY);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 /*usconfig(CONF_LOCKTYPE, US_DEBUGPLUS);*/
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 shared_arena = usinit(tmpnam(0));
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 lwp_setstkcache(STACKSIZE, NSTACKS);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 #ifdef C_THREADS
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 cthread_init();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 }
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 type_lock allocate_lock _P0()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 ulock_t lock;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 struct lock *lock;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 extern char *malloc();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
161
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 #ifdef DEBUG
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 printf("allocate_lock called\n");
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 if (!initialized)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 init_thread();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
167
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 lock = usnewlock(shared_arena);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 (void) usinitlock(lock);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 lock = (struct lock *) malloc(sizeof(struct lock));
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 lock->lock_locked = 0;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 (void) mon_create(&lock->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 (void) cv_create(&lock->lock_condvar, lock->lock_monitor);
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 DEBUG
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 printf("allocate_lock() -> %lx\n", (long)lock);
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 return (type_lock) lock;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
183
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
184 void free_lock _P1(lock, type_lock lock)
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 #ifdef DEBUG
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 printf("free_lock(%lx) called\n", (long)lock);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
188 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 usfreelock((ulock_t) lock, shared_arena);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 mon_destroy(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 free((char *) lock);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
197
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
198 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
199 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 int success;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
201
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 #ifdef DEBUG
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
203 printf("acquire_lock(%lx, %d) called\n", (long)lock, waitflag);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 if (waitflag)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 success = ussetlock((ulock_t) lock);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 else
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
209 success = uscsetlock((ulock_t) lock, 1); /* Try it once */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
211 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 success = 0;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
213
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
214 (void) mon_enter(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 if (waitflag)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
216 while (((struct lock *) lock)->lock_locked)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 cv_wait(((struct lock *) lock)->lock_condvar);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 if (!((struct lock *) lock)->lock_locked) {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 success = 1;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
220 ((struct lock *) lock)->lock_locked = 1;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
222 cv_broadcast(((struct lock *) lock)->lock_condvar);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
223 mon_exit(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
224 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 #ifdef DEBUG
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
226 printf("acquire_lock(%lx, %d) -> %d\n", (long)lock, waitflag, success);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
227 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 return success;
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
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 void release_lock _P1(lock, type_lock lock)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
232 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 #ifdef DEBUG
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
234 printf("release lock(%lx) called\n", (long)lock);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
235 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 (void) usunsetlock((ulock_t) lock);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 (void) mon_enter(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 ((struct lock *) lock)->lock_locked = 0;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
242 cv_broadcast(((struct lock *) lock)->lock_condvar);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 mon_exit(((struct lock *) lock)->lock_monitor);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
245 }
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 void exit_prog _P1(status, int status)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
248 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 #ifdef DEBUG
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
250 printf("exit_prog(%d) called\n", status);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
251 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
252 if (!initialized)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
253 exit(status);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
254 #ifdef __sgi
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
255 exiting = 1;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
256 do_exit = 1;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
257 exit_status = status;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
258 _exit(status);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
259 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 #ifdef sun
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
261 pod_exit(status);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
262 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
263 }