annotate Python/thread_sgi.h @ 58664:993f703a61ba

Merged revisions 77484,77487,77561,77570,77593,77603,77608,77667,77702-77703,77739,77858,77887,77889 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r77484 | skip.montanaro | 2010-01-13 19:12:34 -0600 (Wed, 13 Jan 2010) | 4 lines Update PyEval_EvalFrame to PyEval_EvalFrameEx. This looks to have been done partially before. Also add a comment describing how this might have to work with different versions of the interpreter. ........ r77487 | ezio.melotti | 2010-01-14 05:34:10 -0600 (Thu, 14 Jan 2010) | 1 line Fixed typo ........ r77561 | georg.brandl | 2010-01-17 02:42:30 -0600 (Sun, 17 Jan 2010) | 1 line #7699: improve datetime docs: straightforward linking to strftime/strptime section, mark classmethods as such. ........ r77570 | georg.brandl | 2010-01-17 06:14:42 -0600 (Sun, 17 Jan 2010) | 1 line Add note about usage of STRINGLIB_EMPTY. ........ r77593 | georg.brandl | 2010-01-17 17:33:53 -0600 (Sun, 17 Jan 2010) | 1 line Fix internal reference. ........ r77603 | benjamin.peterson | 2010-01-18 17:07:56 -0600 (Mon, 18 Jan 2010) | 8 lines data descriptors do not override the class dictionary if __get__ is not defined Adjust documentation and add a test to verify this behavior. See http://mail.python.org/pipermail/python-dev/2010-January/095637.html for discussion. ........ r77608 | gregory.p.smith | 2010-01-19 02:19:03 -0600 (Tue, 19 Jan 2010) | 6 lines Do not compile stubs for the sha2 series hashes in the openssl hashlib module when the openssl version is too old to support them. That leads both compiled code bloat and to unittests attempting to test implementations that don't exist for comparison purposes on such platforms. ........ r77667 | mark.dickinson | 2010-01-21 12:32:27 -0600 (Thu, 21 Jan 2010) | 1 line Add two more test_strtod test values. ........ r77702 | georg.brandl | 2010-01-23 02:43:31 -0600 (Sat, 23 Jan 2010) | 1 line #7762: fix refcount annotation of PyUnicode_Tailmatch(). ........ r77703 | georg.brandl | 2010-01-23 02:47:54 -0600 (Sat, 23 Jan 2010) | 1 line #7725: fix referencing issue. ........ r77739 | benjamin.peterson | 2010-01-24 21:52:52 -0600 (Sun, 24 Jan 2010) | 1 line mention from_float() in error message ........ r77858 | georg.brandl | 2010-01-30 11:57:48 -0600 (Sat, 30 Jan 2010) | 1 line #7802: fix invalid example (heh). ........ r77887 | georg.brandl | 2010-01-31 12:51:49 -0600 (Sun, 31 Jan 2010) | 5 lines Fix-up ftplib documentation: move exception descriptions to toplevel, not inside a class remove attribution in "versionadded" spell and grammar check docstring of FTP_TLS ........ r77889 | michael.foord | 2010-01-31 13:59:26 -0600 (Sun, 31 Jan 2010) | 1 line Minor modification to unittest documentation. ........
author Benjamin Peterson <benjamin@python.org>
date Wed, 03 Feb 2010 02:35:45 +0000
parents e20fc1b80205
children e38335d4df91 df5719c298db
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 #include <stdlib.h>
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 #include <stdio.h>
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 #include <signal.h>
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 #include <sys/types.h>
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 #include <sys/wait.h>
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 #include <sys/prctl.h>
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 #include <ulocks.h>
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 #include <errno.h>
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 #define HDR_SIZE 2680 /* sizeof(ushdr_t) */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 #define MAXPROC 100 /* max # of threads that can be started */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 static usptr_t *shared_arena;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 static ulock_t count_lock; /* protection for some variables */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 static ulock_t wait_lock; /* lock used to wait for other threads */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 static int waiting_for_threads; /* protected by count_lock */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 static int nthreads; /* protected by count_lock */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 static int exit_status;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 #ifndef NO_EXIT_PROG
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 static int do_exit; /* indicates that the program is to exit */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 #endif
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 static int exiting; /* we're already exiting (for maybe_exit) */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 static pid_t my_pid; /* PID of main thread */
1655
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
25 static struct pidlist {
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
26 pid_t parent;
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
27 pid_t child;
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
28 } pidlist[MAXPROC]; /* PIDs of other threads; protected by count_lock */
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 static int maxpidindex; /* # of PIDs in pidlist */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
30
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 #ifndef NO_EXIT_PROG
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 /*
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 * This routine is called as a signal handler when another thread
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 * exits. When that happens, we must see whether we have to exit as
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
35 * well (because of an PyThread_exit_prog()) or whether we should continue on.
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 */
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
37 static void exit_sig(void)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 d2printf(("exit_sig called\n"));
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 if (exiting && getpid() == my_pid) {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 d2printf(("already exiting\n"));
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 return;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 if (do_exit) {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 d2printf(("exiting in exit_sig\n"));
4839
4567e158d20c Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
46 #ifdef Py_DEBUG
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 if ((thread_debug & 8) == 0)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 thread_debug &= ~1; /* don't produce debug messages */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 #endif
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
50 PyThread_exit_thread();
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
53
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 /*
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 * This routine is called when a process calls exit(). If that wasn't
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
56 * done from the library, we do as if an PyThread_exit_prog() was intended.
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 */
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
58 static void maybe_exit(void)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 dprintf(("maybe_exit called\n"));
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 if (exiting) {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 dprintf(("already exiting\n"));
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 return;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 }
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
65 PyThread_exit_prog(0);
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 #endif /* NO_EXIT_PROG */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
68
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 /*
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 * Initialization.
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 */
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
72 static void PyThread__init_thread(void)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 #ifndef NO_EXIT_PROG
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 struct sigaction s;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 #endif /* NO_EXIT_PROG */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 #ifdef USE_DL
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 long addr, size;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 #endif /* USE_DL */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
80
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
81
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 #ifdef USE_DL
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 if ((size = usconfig(CONF_INITSIZE, 64*1024)) < 0)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 perror("usconfig - CONF_INITSIZE (check)");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 if (usconfig(CONF_INITSIZE, size) < 0)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 perror("usconfig - CONF_INITSIZE (reset)");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 addr = (long) dl_getrange(size + HDR_SIZE);
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
88 dprintf(("trying to use addr %p-%p for shared arena\n", addr, addr+size));
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 errno = 0;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 if ((addr = usconfig(CONF_ATTACHADDR, addr)) < 0 && errno != 0)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 perror("usconfig - CONF_ATTACHADDR (set)");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 #endif /* USE_DL */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 if (usconfig(CONF_INITUSERS, 16) < 0)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 perror("usconfig - CONF_INITUSERS");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 my_pid = getpid(); /* so that we know which is the main thread */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 #ifndef NO_EXIT_PROG
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 atexit(maybe_exit);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 s.sa_handler = exit_sig;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 sigemptyset(&s.sa_mask);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 /*sigaddset(&s.sa_mask, SIGUSR1);*/
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 s.sa_flags = 0;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 sigaction(SIGUSR1, &s, 0);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 if (prctl(PR_SETEXITSIG, SIGUSR1) < 0)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 perror("prctl - PR_SETEXITSIG");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 #endif /* NO_EXIT_PROG */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 if (usconfig(CONF_ARENATYPE, US_SHAREDONLY) < 0)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 perror("usconfig - CONF_ARENATYPE");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 usconfig(CONF_LOCKTYPE, US_DEBUG); /* XXX */
4839
4567e158d20c Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
109 #ifdef Py_DEBUG
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 if (thread_debug & 4)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 usconfig(CONF_LOCKTYPE, US_DEBUGPLUS);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 else if (thread_debug & 2)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 usconfig(CONF_LOCKTYPE, US_DEBUG);
4839
4567e158d20c Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
114 #endif /* Py_DEBUG */
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 if ((shared_arena = usinit(tmpnam(0))) == 0)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 perror("usinit");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 #ifdef USE_DL
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 if (usconfig(CONF_ATTACHADDR, addr) < 0) /* reset address */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 perror("usconfig - CONF_ATTACHADDR (reset)");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 #endif /* USE_DL */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 if ((count_lock = usnewlock(shared_arena)) == NULL)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 perror("usnewlock (count_lock)");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 (void) usinitlock(count_lock);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 if ((wait_lock = usnewlock(shared_arena)) == NULL)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 perror("usnewlock (wait_lock)");
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
126 dprintf(("arena start: %p, arena size: %ld\n", shared_arena, (long) usconfig(CONF_GETSIZE, shared_arena)));
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
128
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 /*
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 * Thread support.
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
132
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
133 static void clean_threads(void)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 {
1655
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
135 int i, j;
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
136 pid_t mypid, pid;
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
137
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 /* clean up any exited threads */
1655
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
139 mypid = getpid();
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 i = 0;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 while (i < maxpidindex) {
1655
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
142 if (pidlist[i].parent == mypid && (pid = pidlist[i].child) > 0) {
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 pid = waitpid(pid, 0, WNOHANG);
1655
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
144 if (pid > 0) {
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 /* a thread has exited */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 pidlist[i] = pidlist[--maxpidindex];
1655
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
147 /* remove references to children of dead proc */
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
148 for (j = 0; j < maxpidindex; j++)
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
149 if (pidlist[j].parent == pid)
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
150 pidlist[j].child = -1;
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 continue; /* don't increment i */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 i++;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 }
1655
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
156 /* clean up the list */
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
157 i = 0;
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
158 while (i < maxpidindex) {
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
159 if (pidlist[i].child == -1) {
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
160 pidlist[i] = pidlist[--maxpidindex];
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
161 continue; /* don't increment i */
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
162 }
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
163 i++;
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
164 }
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
166
20468
ebfd87e87884 Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
167 long PyThread_start_new_thread(void (*func)(void *), void *arg)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 #ifdef USE_DL
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 long addr, size;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 static int local_initialized = 0;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 #endif /* USE_DL */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 int success = 0; /* init not needed when SOLARIS_THREADS and */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 /* C_THREADS implemented properly */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
175
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
176 dprintf(("PyThread_start_new_thread called\n"));
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 if (!initialized)
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
178 PyThread_init_thread();
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 switch (ussetlock(count_lock)) {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 case 0: return 0;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 case -1: perror("ussetlock (count_lock)");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
183 if (maxpidindex >= MAXPROC)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
184 success = -1;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 else {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
186 #ifdef USE_DL
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 if (!local_initialized) {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
188 if ((size = usconfig(CONF_INITSIZE, 64*1024)) < 0)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 perror("usconfig - CONF_INITSIZE (check)");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 if (usconfig(CONF_INITSIZE, size) < 0)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 perror("usconfig - CONF_INITSIZE (reset)");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 addr = (long) dl_getrange(size + HDR_SIZE);
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
193 dprintf(("trying to use addr %p-%p for sproc\n",
1655
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
194 addr, addr+size));
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 errno = 0;
1655
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
196 if ((addr = usconfig(CONF_ATTACHADDR, addr)) < 0 &&
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
197 errno != 0)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
198 perror("usconfig - CONF_ATTACHADDR (set)");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 #endif /* USE_DL */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
201 clean_threads();
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 if ((success = sproc(func, PR_SALL, arg)) < 0)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
203 perror("sproc");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 #ifdef USE_DL
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 if (!local_initialized) {
1655
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
206 if (usconfig(CONF_ATTACHADDR, addr) < 0)
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
207 /* reset address */
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 perror("usconfig - CONF_ATTACHADDR (reset)");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
209 local_initialized = 1;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
211 #endif /* USE_DL */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 if (success >= 0) {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
213 nthreads++;
1655
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
214 pidlist[maxpidindex].parent = getpid();
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
215 pidlist[maxpidindex++].child = success;
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
216 dprintf(("pidlist[%d] = %d\n",
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
217 maxpidindex-1, success));
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
220 if (usunsetlock(count_lock) < 0)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 perror("usunsetlock (count_lock)");
20468
ebfd87e87884 Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
222 return success;
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
223 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
224
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
225 long PyThread_get_thread_ident(void)
1651
7e5f97bab1e6 ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
226 {
7e5f97bab1e6 ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
227 return getpid();
7e5f97bab1e6 ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
228 }
7e5f97bab1e6 ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
229
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
230 static void do_PyThread_exit_thread(int no_cleanup)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
232 dprintf(("PyThread_exit_thread called\n"));
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 if (!initialized)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
234 if (no_cleanup)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
235 _exit(0);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 else
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 exit(0);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 if (ussetlock(count_lock) < 0)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 perror("ussetlock (count_lock)");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 nthreads--;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 if (getpid() == my_pid) {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
242 /* main thread; wait for other threads to exit */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 exiting = 1;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 #ifndef NO_EXIT_PROG
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
245 if (do_exit) {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
246 int i;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
247
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
248 /* notify other threads */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 clean_threads();
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
250 if (nthreads >= 0) {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
251 dprintf(("kill other threads\n"));
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
252 for (i = 0; i < maxpidindex; i++)
1655
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
253 if (pidlist[i].child > 0)
90ee71a3a13e Fix waiting for children -- save ppid in pidlist as well.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
254 (void) kill(pidlist[i].child,
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
255 SIGKILL);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
256 _exit(exit_status);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
257 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
258 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
259 #endif /* NO_EXIT_PROG */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 waiting_for_threads = 1;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
261 if (ussetlock(wait_lock) < 0)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
262 perror("ussetlock (wait_lock)");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
263 for (;;) {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
264 if (nthreads < 0) {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
265 dprintf(("really exit (%d)\n", exit_status));
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
266 if (no_cleanup)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
267 _exit(exit_status);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
268 else
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
269 exit(exit_status);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
270 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
271 if (usunsetlock(count_lock) < 0)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
272 perror("usunsetlock (count_lock)");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
273 dprintf(("waiting for other threads (%d)\n", nthreads));
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
274 if (ussetlock(wait_lock) < 0)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
275 perror("ussetlock (wait_lock)");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
276 if (ussetlock(count_lock) < 0)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
277 perror("ussetlock (count_lock)");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
278 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
279 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
280 /* not the main thread */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
281 if (waiting_for_threads) {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
282 dprintf(("main thread is waiting\n"));
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
283 if (usunsetlock(wait_lock) < 0)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
284 perror("usunsetlock (wait_lock)");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
285 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
286 #ifndef NO_EXIT_PROG
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
287 else if (do_exit)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
288 (void) kill(my_pid, SIGUSR1);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
289 #endif /* NO_EXIT_PROG */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
290 if (usunsetlock(count_lock) < 0)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
291 perror("usunsetlock (count_lock)");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
292 _exit(0);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
293 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
294
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
295 void PyThread_exit_thread(void)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
296 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
297 do_PyThread_exit_thread(0);
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
298 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
299
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
300 void PyThread__exit_thread(void)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
301 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
302 do_PyThread_exit_thread(1);
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
303 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
304
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
305 #ifndef NO_EXIT_PROG
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
306 static void do_PyThread_exit_prog(int status, int no_cleanup)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
307 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
308 dprintf(("PyThread_exit_prog(%d) called\n", status));
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
309 if (!initialized)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
310 if (no_cleanup)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
311 _exit(status);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
312 else
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
313 exit(status);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
314 do_exit = 1;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
315 exit_status = status;
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
316 do_PyThread_exit_thread(no_cleanup);
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
317 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
318
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
319 void PyThread_exit_prog(int status)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
320 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
321 do_PyThread_exit_prog(status, 0);
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
322 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
323
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
324 void PyThread__exit_prog(int status)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
325 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
326 do_PyThread_exit_prog(status, 1);
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
327 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
328 #endif /* NO_EXIT_PROG */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
329
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
330 /*
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
331 * Lock support.
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
332 */
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
333 PyThread_type_lock PyThread_allocate_lock(void)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
334 {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
335 ulock_t lock;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
336
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
337 dprintf(("PyThread_allocate_lock called\n"));
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
338 if (!initialized)
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
339 PyThread_init_thread();
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
340
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
341 if ((lock = usnewlock(shared_arena)) == NULL)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
342 perror("usnewlock");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
343 (void) usinitlock(lock);
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
344 dprintf(("PyThread_allocate_lock() -> %p\n", lock));
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
345 return (PyThread_type_lock) lock;
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
346 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
347
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
348 void PyThread_free_lock(PyThread_type_lock lock)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
349 {
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
350 dprintf(("PyThread_free_lock(%p) called\n", lock));
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
351 usfreelock((ulock_t) lock, shared_arena);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
352 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
353
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
354 int PyThread_acquire_lock(PyThread_type_lock lock, int waitflag)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
355 {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
356 int success;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
357
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
358 dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag));
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
359 errno = 0; /* clear it just in case */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
360 if (waitflag)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
361 success = ussetlock((ulock_t) lock);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
362 else
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
363 success = uscsetlock((ulock_t) lock, 1); /* Try it once */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
364 if (success < 0)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
365 perror(waitflag ? "ussetlock" : "uscsetlock");
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
366 dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success));
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
367 return success;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
368 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
369
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
370 void PyThread_release_lock(PyThread_type_lock lock)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
371 {
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
372 dprintf(("PyThread_release_lock(%p) called\n", lock));
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
373 if (usunsetlock((ulock_t) lock) < 0)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
374 perror("usunsetlock");
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
375 }