annotate Python/thread_pth.h @ 49677:82ccc7e77ec5 2.6

Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ................ r66801 | andrew.kuchling | 2008-10-04 23:51:59 +0200 (Sat, 04 Oct 2008) | 1 line Punctuation fix; expand dict.update docstring to be clearer ................ r66803 | benjamin.peterson | 2008-10-05 00:15:31 +0200 (Sun, 05 Oct 2008) | 1 line fix typo ................ r66804 | andrew.kuchling | 2008-10-05 02:11:56 +0200 (Sun, 05 Oct 2008) | 1 line #1415508 from Rocky Bernstein: add docstrings for enable_interspersed_args(), disable_interspersed_args() ................ r66813 | andrew.kuchling | 2008-10-06 14:07:04 +0200 (Mon, 06 Oct 2008) | 3 lines Per Greg Ward, optparse is no longer being externally maintained. I'll look at the bugs in the Optik bug tracker and copy them to the Python bug tracker if they're still relevant. ................ r66854 | georg.brandl | 2008-10-08 19:20:20 +0200 (Wed, 08 Oct 2008) | 2 lines #4059: patch up some sqlite docs. ................ r66855 | georg.brandl | 2008-10-08 19:30:55 +0200 (Wed, 08 Oct 2008) | 2 lines #4058: fix some whatsnew markup. ................ r66856 | georg.brandl | 2008-10-08 20:47:17 +0200 (Wed, 08 Oct 2008) | 3 lines #3935: properly support list subclasses in the C impl. of bisect. Patch reviewed by Raymond. ................ r66866 | benjamin.peterson | 2008-10-09 22:54:43 +0200 (Thu, 09 Oct 2008) | 1 line update paragraph about __future__ for 2.6 ................ r66870 | armin.rigo | 2008-10-10 10:40:44 +0200 (Fri, 10 Oct 2008) | 2 lines Typo: "ThreadError" is the name in the C source. ................ r66871 | benjamin.peterson | 2008-10-10 22:38:49 +0200 (Fri, 10 Oct 2008) | 1 line fix a small typo ................ r66872 | benjamin.peterson | 2008-10-10 22:51:37 +0200 (Fri, 10 Oct 2008) | 1 line talk about how you can unzip with zip ................ r66874 | benjamin.peterson | 2008-10-11 00:23:41 +0200 (Sat, 11 Oct 2008) | 1 line PyGILState_Acquire -> PyGILState_Ensure ................ r66887 | benjamin.peterson | 2008-10-13 23:51:40 +0200 (Mon, 13 Oct 2008) | 1 line document how to disable fixers ................ r66903 | benjamin.peterson | 2008-10-15 22:34:09 +0200 (Wed, 15 Oct 2008) | 1 line don't recurse into directories that start with '.' ................ r66905 | benjamin.peterson | 2008-10-15 23:05:55 +0200 (Wed, 15 Oct 2008) | 1 line support the optional line argument for idle ................ r66911 | benjamin.peterson | 2008-10-16 01:10:28 +0200 (Thu, 16 Oct 2008) | 41 lines Merged revisions 66805,66841,66860,66884-66886,66893,66907,66910 via svnmerge from svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r66805 | benjamin.peterson | 2008-10-04 20:11:02 -0500 (Sat, 04 Oct 2008) | 1 line mention what the fixes directory is for ........ r66841 | benjamin.peterson | 2008-10-07 17:48:12 -0500 (Tue, 07 Oct 2008) | 1 line use assertFalse and assertTrue ........ r66860 | benjamin.peterson | 2008-10-08 16:05:07 -0500 (Wed, 08 Oct 2008) | 1 line instead of abusing the pattern matcher, use start_tree to find a next binding ........ r66884 | benjamin.peterson | 2008-10-13 15:50:30 -0500 (Mon, 13 Oct 2008) | 1 line don't print tokens to stdout when -v is given ........ r66885 | benjamin.peterson | 2008-10-13 16:28:57 -0500 (Mon, 13 Oct 2008) | 1 line add the -x option to disable fixers ........ r66886 | benjamin.peterson | 2008-10-13 16:33:53 -0500 (Mon, 13 Oct 2008) | 1 line cut down on some crud ........ r66893 | benjamin.peterson | 2008-10-14 17:16:54 -0500 (Tue, 14 Oct 2008) | 1 line add an optional set literal fixer ........ r66907 | benjamin.peterson | 2008-10-15 16:59:41 -0500 (Wed, 15 Oct 2008) | 1 line don't write backup files by default ........ r66910 | benjamin.peterson | 2008-10-15 17:43:10 -0500 (Wed, 15 Oct 2008) | 1 line add the -n option; it stops backupfiles from being written ........ ................ r66913 | benjamin.peterson | 2008-10-16 20:52:14 +0200 (Thu, 16 Oct 2008) | 1 line document that deque indexing is O(n) #4123 ................ r66927 | andrew.kuchling | 2008-10-16 22:15:47 +0200 (Thu, 16 Oct 2008) | 1 line Fix wording (2.6.1 backport candidate) ................ r66932 | benjamin.peterson | 2008-10-16 23:09:28 +0200 (Thu, 16 Oct 2008) | 1 line check for error conditions in _json #3623 ................ r66938 | benjamin.peterson | 2008-10-16 23:27:54 +0200 (Thu, 16 Oct 2008) | 1 line fix possible ref leak ................ r66942 | benjamin.peterson | 2008-10-16 23:48:06 +0200 (Thu, 16 Oct 2008) | 1 line fix more possible ref leaks in _json and use Py_CLEAR ................ r66962 | benjamin.peterson | 2008-10-17 22:01:01 +0200 (Fri, 17 Oct 2008) | 1 line clarify CALL_FUNCTION #4141 ................ r66964 | georg.brandl | 2008-10-17 23:41:49 +0200 (Fri, 17 Oct 2008) | 2 lines Fix duplicate word. ................ r66973 | armin.ronacher | 2008-10-19 10:27:43 +0200 (Sun, 19 Oct 2008) | 3 lines Fixed #4067 by implementing _attributes and _fields for the AST root node. ................ r66974 | benjamin.peterson | 2008-10-19 15:59:01 +0200 (Sun, 19 Oct 2008) | 1 line fix compiler warning ................ r66977 | benjamin.peterson | 2008-10-19 21:39:16 +0200 (Sun, 19 Oct 2008) | 1 line mention -n ................ r66992 | benjamin.peterson | 2008-10-21 22:51:13 +0200 (Tue, 21 Oct 2008) | 1 line make sure to call iteritems() ................ r66998 | benjamin.peterson | 2008-10-22 22:57:43 +0200 (Wed, 22 Oct 2008) | 1 line fix a few typos ................ r66999 | benjamin.peterson | 2008-10-22 23:05:30 +0200 (Wed, 22 Oct 2008) | 1 line and another typo... ................ r67002 | hirokazu.yamamoto | 2008-10-23 02:37:33 +0200 (Thu, 23 Oct 2008) | 1 line Issue #4183: Some tests didn't run with pickle.HIGHEST_PROTOCOL. ................ r67005 | walter.doerwald | 2008-10-23 15:11:39 +0200 (Thu, 23 Oct 2008) | 2 lines Use the correct names of the stateless codec functions (Fixes issue 4178). ................ r67007 | benjamin.peterson | 2008-10-23 23:43:48 +0200 (Thu, 23 Oct 2008) | 1 line only nonempty __slots__ don't work ................ r67028 | benjamin.peterson | 2008-10-26 01:27:07 +0200 (Sun, 26 Oct 2008) | 1 line don't use a catch-all ................ r67040 | armin.rigo | 2008-10-28 18:01:21 +0100 (Tue, 28 Oct 2008) | 5 lines Fix one of the tests: it relied on being present in an "output test" in order to actually test what it was supposed to test, i.e. that the code in the __del__ method did not crash. Use instead the new helper test_support.captured_output(). ................ r67041 | benjamin.peterson | 2008-10-29 21:33:00 +0100 (Wed, 29 Oct 2008) | 1 line mention the version gettempdir() was added ................ r67044 | amaury.forgeotdarc | 2008-10-30 00:15:57 +0100 (Thu, 30 Oct 2008) | 3 lines Correct error message in io.open(): closefd=True is the only accepted value with a file name. ................ r67070 | benjamin.peterson | 2008-10-31 21:41:44 +0100 (Fri, 31 Oct 2008) | 1 line rephrase has_key doc ................ r67089 | benjamin.peterson | 2008-11-03 21:43:20 +0100 (Mon, 03 Nov 2008) | 1 line clarify by splitting into multiple paragraphs ................ r67091 | benjamin.peterson | 2008-11-03 23:34:57 +0100 (Mon, 03 Nov 2008) | 1 line move a FileIO test to test_fileio ................ r67101 | georg.brandl | 2008-11-04 21:49:35 +0100 (Tue, 04 Nov 2008) | 2 lines #4167: fix markup glitches. ................ r67117 | georg.brandl | 2008-11-06 11:17:58 +0100 (Thu, 06 Nov 2008) | 2 lines #4268: Use correct module for two toplevel functions. ................ r67118 | georg.brandl | 2008-11-06 11:19:11 +0100 (Thu, 06 Nov 2008) | 2 lines #4267: small fixes in sqlite3 docs. ................ r67119 | georg.brandl | 2008-11-06 11:20:49 +0100 (Thu, 06 Nov 2008) | 2 lines #4245: move Thread section to the top. ................ r67123 | georg.brandl | 2008-11-06 19:49:15 +0100 (Thu, 06 Nov 2008) | 2 lines #4247: add "pass" examples to tutorial. ................ r67124 | andrew.kuchling | 2008-11-06 20:23:02 +0100 (Thu, 06 Nov 2008) | 1 line Fix grammar error; reword two paragraphs ................
author Georg Brandl <georg@python.org>
date Fri, 07 Nov 2008 08:56:27 +0000
parents 1a817694ecbd
children e38335d4df91 df5719c298db
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* GNU pth threads interface
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 http://www.gnu.org/software/pth
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 2000-05-03 Andy Dustman <andy@dustman.net>
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 Adapted from Posix threads interface
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 12 May 1997 -- david arnold <davida@pobox.com>
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 */
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 #include <stdlib.h>
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 #include <string.h>
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 #include <pth.h>
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 /* A pth mutex isn't sufficient to model the Python lock type
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 * because pth mutexes can be acquired multiple times by the
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 * same thread.
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 *
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 * The pth_lock struct implements a Python lock as a "locked?" bit
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 * and a <condition, mutex> pair. In general, if the bit can be acquired
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 * instantly, it is, else the pair is used to block the thread until the
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 * bit is cleared.
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 */
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 typedef struct {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 char locked; /* 0=unlocked, 1=locked */
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 /* a <cond, mutex> pair to handle an acquire of a locked lock */
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 pth_cond_t lock_released;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 pth_mutex_t mut;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 } pth_lock;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
30
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 #define CHECK_STATUS(name) if (status == -1) { printf("%d ", status); perror(name); error = 1; }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
32
30466
1a817694ecbd Patch #805613: Fix usage of the PTH library.
Martin v. Löwis <martin@v.loewis.de>
parents: 21766
diff changeset
33 pth_attr_t PyThread_attr;
1a817694ecbd Patch #805613: Fix usage of the PTH library.
Martin v. Löwis <martin@v.loewis.de>
parents: 21766
diff changeset
34
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 /*
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 * Initialization.
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 */
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
38
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
39 static void PyThread__init_thread(void)
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 pth_init();
30466
1a817694ecbd Patch #805613: Fix usage of the PTH library.
Martin v. Löwis <martin@v.loewis.de>
parents: 21766
diff changeset
42 PyThread_attr = pth_attr_new();
1a817694ecbd Patch #805613: Fix usage of the PTH library.
Martin v. Löwis <martin@v.loewis.de>
parents: 21766
diff changeset
43 pth_attr_set(PyThread_attr, PTH_ATTR_STACK_SIZE, 1<<18);
1a817694ecbd Patch #805613: Fix usage of the PTH library.
Martin v. Löwis <martin@v.loewis.de>
parents: 21766
diff changeset
44 pth_attr_set(PyThread_attr, PTH_ATTR_JOINABLE, FALSE);
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
46
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 /*
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 * Thread support.
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 */
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
50
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
51
20468
ebfd87e87884 Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents: 15187
diff changeset
52 long PyThread_start_new_thread(void (*func)(void *), void *arg)
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 pth_t th;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 dprintf(("PyThread_start_new_thread called\n"));
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 if (!initialized)
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 PyThread_init_thread();
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
58
30466
1a817694ecbd Patch #805613: Fix usage of the PTH library.
Martin v. Löwis <martin@v.loewis.de>
parents: 21766
diff changeset
59 th = pth_spawn(PyThread_attr,
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
60 (void* (*)(void *))func,
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 (void *)arg
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 );
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
63
20468
ebfd87e87884 Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents: 15187
diff changeset
64 return th;
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
66
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
67 long PyThread_get_thread_ident(void)
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 volatile pth_t threadid;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 if (!initialized)
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 PyThread_init_thread();
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 /* Jump through some hoops for Alpha OSF/1 */
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 threadid = pth_self();
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 return (long) *(long *) &threadid;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
76
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
77 static void do_PyThread_exit_thread(int no_cleanup)
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 dprintf(("PyThread_exit_thread called\n"));
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 if (!initialized) {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 if (no_cleanup)
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 _exit(0);
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 else
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 exit(0);
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
87
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
88 void PyThread_exit_thread(void)
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 do_PyThread_exit_thread(0);
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
92
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
93 void PyThread__exit_thread(void)
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 do_PyThread_exit_thread(1);
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
97
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 #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
99 static void do_PyThread_exit_prog(int status, int no_cleanup)
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 dprintf(("PyThread_exit_prog(%d) called\n", status));
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 if (!initialized)
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 if (no_cleanup)
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 _exit(status);
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 else
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 exit(status);
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
108
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
109 void PyThread_exit_prog(int status)
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 do_PyThread_exit_prog(status, 0);
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
113
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
114 void PyThread__exit_prog(int status)
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 do_PyThread_exit_prog(status, 1);
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 #endif /* NO_EXIT_PROG */
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
119
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 /*
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 * Lock support.
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 */
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
123 PyThread_type_lock PyThread_allocate_lock(void)
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 pth_lock *lock;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 int status, error = 0;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
127
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 dprintf(("PyThread_allocate_lock called\n"));
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 if (!initialized)
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 PyThread_init_thread();
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
131
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 lock = (pth_lock *) malloc(sizeof(pth_lock));
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 memset((void *)lock, '\0', sizeof(pth_lock));
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 if (lock) {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 lock->locked = 0;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 status = pth_mutex_init(&lock->mut);
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 CHECK_STATUS("pth_mutex_init");
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 status = pth_cond_init(&lock->lock_released);
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 CHECK_STATUS("pth_cond_init");
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 if (error) {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 free((void *)lock);
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 lock = NULL;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 }
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12611
diff changeset
145 dprintf(("PyThread_allocate_lock() -> %p\n", lock));
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 return (PyThread_type_lock) lock;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
148
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
149 void PyThread_free_lock(PyThread_type_lock lock)
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 pth_lock *thelock = (pth_lock *)lock;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
152
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12611
diff changeset
153 dprintf(("PyThread_free_lock(%p) called\n", lock));
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
154
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 free((void *)thelock);
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
157
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
158 int PyThread_acquire_lock(PyThread_type_lock lock, int waitflag)
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 int success;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 pth_lock *thelock = (pth_lock *)lock;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 int status, error = 0;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
163
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12611
diff changeset
164 dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag));
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
165
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 status = pth_mutex_acquire(&thelock->mut, !waitflag, NULL);
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 CHECK_STATUS("pth_mutex_acquire[1]");
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 success = thelock->locked == 0;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 if (success) thelock->locked = 1;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 status = pth_mutex_release( &thelock->mut );
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 CHECK_STATUS("pth_mutex_release[1]");
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
172
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 if ( !success && waitflag ) {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 /* continue trying until we get the lock */
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
175
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 /* mut must be locked by me -- part of the condition
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 * protocol */
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 status = pth_mutex_acquire( &thelock->mut, !waitflag, NULL );
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 CHECK_STATUS("pth_mutex_acquire[2]");
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 while ( thelock->locked ) {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 status = pth_cond_await(&thelock->lock_released,
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 &thelock->mut, NULL);
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
183 CHECK_STATUS("pth_cond_await");
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
184 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 thelock->locked = 1;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
186 status = pth_mutex_release( &thelock->mut );
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 CHECK_STATUS("pth_mutex_release[2]");
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
188 success = 1;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 if (error) success = 0;
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12611
diff changeset
191 dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success));
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 return success;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 }
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
194
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
195 void PyThread_release_lock(PyThread_type_lock lock)
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 {
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 pth_lock *thelock = (pth_lock *)lock;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
198 int status, error = 0;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
199
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 12611
diff changeset
200 dprintf(("PyThread_release_lock(%p) called\n", lock));
12611
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
201
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 status = pth_mutex_acquire( &thelock->mut, 0, NULL );
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
203 CHECK_STATUS("pth_mutex_acquire[3]");
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
204
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 thelock->locked = 0;
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
206
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 status = pth_mutex_release( &thelock->mut );
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 CHECK_STATUS("pth_mutex_release[3]");
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
209
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 /* wake up someone (anyone, if any) waiting on the lock */
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
211 status = pth_cond_notify( &thelock->lock_released, 0 );
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 CHECK_STATUS("pth_cond_notify");
b320cf3a98b9 Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
diff changeset
213 }