annotate Python/thread_cthread.h @ 59857:ec6a995ecfbf

Merged revisions 79205,79219,79228,79230,79232-79233,79235,79237 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r79205 | benjamin.peterson | 2010-03-21 12:34:54 -0500 (Sun, 21 Mar 2010) | 1 line rewrite a bit ........ r79219 | benjamin.peterson | 2010-03-21 14:24:08 -0500 (Sun, 21 Mar 2010) | 1 line flatten condition ........ r79228 | benjamin.peterson | 2010-03-21 14:35:39 -0500 (Sun, 21 Mar 2010) | 1 line remove pointless condition ........ r79230 | benjamin.peterson | 2010-03-21 14:39:52 -0500 (Sun, 21 Mar 2010) | 1 line co_varnames is certainly a tuple, so let's not waste time finding out ........ r79232 | benjamin.peterson | 2010-03-21 14:54:56 -0500 (Sun, 21 Mar 2010) | 1 line fix import ........ r79233 | benjamin.peterson | 2010-03-21 14:56:37 -0500 (Sun, 21 Mar 2010) | 1 line don't write duplicate tests ........ r79235 | benjamin.peterson | 2010-03-21 15:21:00 -0500 (Sun, 21 Mar 2010) | 4 lines improve error message from passing inadequate number of keyword arguments #6474 Note this removes the "non-keyword" or "keyword" phrases from these messages. ........ r79237 | benjamin.peterson | 2010-03-21 15:30:30 -0500 (Sun, 21 Mar 2010) | 1 line take into account keyword arguments when passing too many args ........
author Benjamin Peterson <benjamin@python.org>
date Sun, 21 Mar 2010 21:00:50 +0000
parents 798e0d0c7246
children fd25030223b0
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
21606
67da11293406 Patch #497098: build support for GNU/Hurd.
Martin v. Löwis <martin@v.loewis.de>
parents: 20468
diff changeset
2 #ifdef MACH_C_THREADS
3838
5aab3f668e84 Changes needed by NeXT (the only platform that seems to use this).
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
3 #include <mach/cthreads.h>
21606
67da11293406 Patch #497098: build support for GNU/Hurd.
Martin v. Löwis <martin@v.loewis.de>
parents: 20468
diff changeset
4 #endif
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
21606
67da11293406 Patch #497098: build support for GNU/Hurd.
Martin v. Löwis <martin@v.loewis.de>
parents: 20468
diff changeset
6 #ifdef HURD_C_THREADS
67da11293406 Patch #497098: build support for GNU/Hurd.
Martin v. Löwis <martin@v.loewis.de>
parents: 20468
diff changeset
7 #include <cthreads.h>
67da11293406 Patch #497098: build support for GNU/Hurd.
Martin v. Löwis <martin@v.loewis.de>
parents: 20468
diff changeset
8 #endif
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9
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 * Initialization.
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 */
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
13 static void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
14 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
15 {
21606
67da11293406 Patch #497098: build support for GNU/Hurd.
Martin v. Löwis <martin@v.loewis.de>
parents: 20468
diff changeset
16 #ifndef HURD_C_THREADS
67da11293406 Patch #497098: build support for GNU/Hurd.
Martin v. Löwis <martin@v.loewis.de>
parents: 20468
diff changeset
17 /* Roland McGrath said this should not be used since this is
67da11293406 Patch #497098: build support for GNU/Hurd.
Martin v. Löwis <martin@v.loewis.de>
parents: 20468
diff changeset
18 done while linking to threads */
67da11293406 Patch #497098: build support for GNU/Hurd.
Martin v. Löwis <martin@v.loewis.de>
parents: 20468
diff changeset
19 cthread_init();
67da11293406 Patch #497098: build support for GNU/Hurd.
Martin v. Löwis <martin@v.loewis.de>
parents: 20468
diff changeset
20 #else
67da11293406 Patch #497098: build support for GNU/Hurd.
Martin v. Löwis <martin@v.loewis.de>
parents: 20468
diff changeset
21 /* do nothing */
67da11293406 Patch #497098: build support for GNU/Hurd.
Martin v. Löwis <martin@v.loewis.de>
parents: 20468
diff changeset
22 ;
67da11293406 Patch #497098: build support for GNU/Hurd.
Martin v. Löwis <martin@v.loewis.de>
parents: 20468
diff changeset
23 #endif
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
25
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 /*
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 * Thread support.
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 */
20468
ebfd87e87884 Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents: 15403
diff changeset
29 long
15403
5b4abceff53d Fix syntax error. Submitted by Bill Bumgarner. Apparently this is
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
30 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
31 {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 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
33 /* C_THREADS implemented properly */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
34
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
35 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
36 if (!initialized)
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
37 PyThread_init_thread();
3838
5aab3f668e84 Changes needed by NeXT (the only platform that seems to use this).
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
38 /* looks like solaris detaches the thread to never rejoin
5aab3f668e84 Changes needed by NeXT (the only platform that seems to use this).
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
39 * so well do it here
5aab3f668e84 Changes needed by NeXT (the only platform that seems to use this).
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
40 */
5aab3f668e84 Changes needed by NeXT (the only platform that seems to use this).
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
41 cthread_detach(cthread_fork((cthread_fn_t) func, arg));
20468
ebfd87e87884 Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents: 15403
diff changeset
42 return success < 0 ? -1 : 0;
1628
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
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
45 long
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
46 PyThread_get_thread_ident(void)
1651
7e5f97bab1e6 ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents: 1629
diff changeset
47 {
7e5f97bab1e6 ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents: 1629
diff changeset
48 if (!initialized)
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
49 PyThread_init_thread();
3838
5aab3f668e84 Changes needed by NeXT (the only platform that seems to use this).
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
50 return (long) cthread_self();
1651
7e5f97bab1e6 ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents: 1629
diff changeset
51 }
7e5f97bab1e6 ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents: 1629
diff changeset
52
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
53 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
54 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
55 {
59089
798e0d0c7246 Merged revisions 78393 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 21766
diff changeset
56 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
57 if (!initialized)
59089
798e0d0c7246 Merged revisions 78393 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 21766
diff changeset
58 exit(0);
798e0d0c7246 Merged revisions 78393 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 21766
diff changeset
59 cthread_exit(0);
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
61
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 /*
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 * Lock support.
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 */
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
65 PyThread_type_lock
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
66 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
67 {
3838
5aab3f668e84 Changes needed by NeXT (the only platform that seems to use this).
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
68 mutex_t lock;
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
69
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
70 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
71 if (!initialized)
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
72 PyThread_init_thread();
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
73
3838
5aab3f668e84 Changes needed by NeXT (the only platform that seems to use this).
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
74 lock = mutex_alloc();
5aab3f668e84 Changes needed by NeXT (the only platform that seems to use this).
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
75 if (mutex_init(lock)) {
5aab3f668e84 Changes needed by NeXT (the only platform that seems to use this).
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
76 perror("mutex_init");
5aab3f668e84 Changes needed by NeXT (the only platform that seems to use this).
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
77 free((void *) lock);
5aab3f668e84 Changes needed by NeXT (the only platform that seems to use this).
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
78 lock = 0;
5aab3f668e84 Changes needed by NeXT (the only platform that seems to use this).
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
79 }
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
80 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: 4503
diff changeset
81 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
82 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
83
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
84 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
85 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
86 {
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
87 dprintf(("PyThread_free_lock(%p) called\n", lock));
3838
5aab3f668e84 Changes needed by NeXT (the only platform that seems to use this).
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
88 mutex_free(lock);
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
90
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
91 int
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
92 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
93 {
3838
5aab3f668e84 Changes needed by NeXT (the only platform that seems to use this).
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
94 int success = FALSE;
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
95
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
96 dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag));
3838
5aab3f668e84 Changes needed by NeXT (the only platform that seems to use this).
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
97 if (waitflag) { /* blocking */
21606
67da11293406 Patch #497098: build support for GNU/Hurd.
Martin v. Löwis <martin@v.loewis.de>
parents: 20468
diff changeset
98 mutex_lock((mutex_t)lock);
3838
5aab3f668e84 Changes needed by NeXT (the only platform that seems to use this).
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
99 success = TRUE;
5aab3f668e84 Changes needed by NeXT (the only platform that seems to use this).
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
100 } else { /* non blocking */
21606
67da11293406 Patch #497098: build support for GNU/Hurd.
Martin v. Löwis <martin@v.loewis.de>
parents: 20468
diff changeset
101 success = mutex_try_lock((mutex_t)lock);
3838
5aab3f668e84 Changes needed by NeXT (the only platform that seems to use this).
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
102 }
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
103 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
104 return success;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
106
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
107 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
108 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
109 {
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
110 dprintf(("PyThread_release_lock(%p) called\n", lock));
3838
5aab3f668e84 Changes needed by NeXT (the only platform that seems to use this).
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
111 mutex_unlock((mutex_t )lock);
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 }