Mercurial > cpython-lru_cache-weakref
annotate Python/thread_nt.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 | 1c1705bf36b8 |
| children | e38335d4df91 fdcca8793eb9 |
| rev | line source |
|---|---|
| 2152 | 1 |
| 2 /* This code implemented by Dag.Gruneau@elsa.preseco.comm.se */ | |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
3 /* Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru */ |
|
22092
7a3e03b541ff
SF patch 522961: Leak in Python/thread_nt.h, from Gerald S. Williams.
Tim Peters <tim.peters@gmail.com>
parents:
21766
diff
changeset
|
4 /* Eliminated some memory leaks, gsw@agere.com */ |
| 2152 | 5 |
|
6029
68f2d7704180
Use _beginthread() and _endthread() in favor of CreateThread() and
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
6 #include <windows.h> |
|
68f2d7704180
Use _beginthread() and _endthread() in favor of CreateThread() and
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
7 #include <limits.h> |
|
38716
42808526511c
Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents:
38592
diff
changeset
|
8 #ifdef HAVE_PROCESS_H |
|
6029
68f2d7704180
Use _beginthread() and _endthread() in favor of CreateThread() and
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
9 #include <process.h> |
|
38716
42808526511c
Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents:
38592
diff
changeset
|
10 #endif |
| 2152 | 11 |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
12 typedef struct NRMUTEX { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
13 LONG owned ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
14 DWORD thread_id ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
15 HANDLE hevent ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
16 } NRMUTEX, *PNRMUTEX ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
17 |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
18 |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
19 BOOL |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
20 InitializeNonRecursiveMutex(PNRMUTEX mutex) |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
21 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
22 mutex->owned = -1 ; /* No threads have entered NonRecursiveMutex */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
23 mutex->thread_id = 0 ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
24 mutex->hevent = CreateEvent(NULL, FALSE, FALSE, NULL) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
25 return mutex->hevent != NULL ; /* TRUE if the mutex is created */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
26 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
27 |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
28 VOID |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
29 DeleteNonRecursiveMutex(PNRMUTEX mutex) |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
30 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
31 /* No in-use check */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
32 CloseHandle(mutex->hevent) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
33 mutex->hevent = NULL ; /* Just in case */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
34 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
35 |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
36 DWORD |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
37 EnterNonRecursiveMutex(PNRMUTEX mutex, BOOL wait) |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
38 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
39 /* Assume that the thread waits successfully */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
40 DWORD ret ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
41 |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
42 /* InterlockedIncrement(&mutex->owned) == 0 means that no thread currently owns the mutex */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
43 if (!wait) |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
44 { |
|
41590
1c1705bf36b8
Fix problems in x64 build that were discovered by the testsuite:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
41525
diff
changeset
|
45 if (InterlockedCompareExchange(&mutex->owned, 0, -1) != -1) |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
46 return WAIT_TIMEOUT ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
47 ret = WAIT_OBJECT_0 ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
48 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
49 else |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
50 ret = InterlockedIncrement(&mutex->owned) ? |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
51 /* Some thread owns the mutex, let's wait... */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
52 WaitForSingleObject(mutex->hevent, INFINITE) : WAIT_OBJECT_0 ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
53 |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
54 mutex->thread_id = GetCurrentThreadId() ; /* We own it */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
55 return ret ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
56 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
57 |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
58 BOOL |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
59 LeaveNonRecursiveMutex(PNRMUTEX mutex) |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
60 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
61 /* We don't own the mutex */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
62 mutex->thread_id = 0 ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
63 return |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
64 InterlockedDecrement(&mutex->owned) < 0 || |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
65 SetEvent(mutex->hevent) ; /* Other threads are waiting, wake one on them up */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
66 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
67 |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
68 PNRMUTEX |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
69 AllocNonRecursiveMutex(void) |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
70 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
71 PNRMUTEX mutex = (PNRMUTEX)malloc(sizeof(NRMUTEX)) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
72 if (mutex && !InitializeNonRecursiveMutex(mutex)) |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
73 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
74 free(mutex) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
75 mutex = NULL ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
76 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
77 return mutex ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
78 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
79 |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
80 void |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
81 FreeNonRecursiveMutex(PNRMUTEX mutex) |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
82 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
83 if (mutex) |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
84 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
85 DeleteNonRecursiveMutex(mutex) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
86 free(mutex) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
87 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
88 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
89 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
90 long PyThread_get_thread_ident(void); |
| 2152 | 91 |
| 92 /* | |
| 93 * Initialization of the C package, should not be needed. | |
| 94 */ | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
95 static void |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
96 PyThread__init_thread(void) |
| 2152 | 97 { |
| 98 } | |
| 99 | |
| 100 /* | |
| 101 * Thread support. | |
| 102 */ | |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
103 |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
104 typedef struct { |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
105 void (*func)(void*); |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
106 void *arg; |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
107 long id; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
108 HANDLE done; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
109 } callobj; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
110 |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
111 static int |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
112 bootstrap(void *call) |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
113 { |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
114 callobj *obj = (callobj*)call; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
115 /* copy callobj since other thread might free it before we're done */ |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
116 void (*func)(void*) = obj->func; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
117 void *arg = obj->arg; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
118 |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
119 obj->id = PyThread_get_thread_ident(); |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
120 ReleaseSemaphore(obj->done, 1, NULL); |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
121 func(arg); |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
122 return 0; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
123 } |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
124 |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
125 long |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
126 PyThread_start_new_thread(void (*func)(void *), void *arg) |
| 2152 | 127 { |
|
38232
aa620856e8a3
Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
128 Py_uintptr_t rv; |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
129 callobj obj; |
| 2152 | 130 |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
131 dprintf(("%ld: PyThread_start_new_thread called\n", |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
132 PyThread_get_thread_ident())); |
| 2152 | 133 if (!initialized) |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
134 PyThread_init_thread(); |
| 2152 | 135 |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
136 obj.id = -1; /* guilty until proved innocent */ |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
137 obj.func = func; |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
138 obj.arg = arg; |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
139 obj.done = CreateSemaphore(NULL, 0, 1, NULL); |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
140 if (obj.done == NULL) |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
141 return -1; |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
19568
diff
changeset
|
142 |
|
41590
1c1705bf36b8
Fix problems in x64 build that were discovered by the testsuite:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
41525
diff
changeset
|
143 rv = _beginthread(bootstrap, |
|
1c1705bf36b8
Fix problems in x64 build that were discovered by the testsuite:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
41525
diff
changeset
|
144 Py_SAFE_DOWNCAST(_pythread_stacksize, |
|
1c1705bf36b8
Fix problems in x64 build that were discovered by the testsuite:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
41525
diff
changeset
|
145 Py_ssize_t, int), |
|
1c1705bf36b8
Fix problems in x64 build that were discovered by the testsuite:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
41525
diff
changeset
|
146 &obj); |
|
38232
aa620856e8a3
Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
147 if (rv == (Py_uintptr_t)-1) { |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
148 /* I've seen errno == EAGAIN here, which means "there are |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
149 * too many threads". |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
150 */ |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
151 dprintf(("%ld: PyThread_start_new_thread failed: %p errno %d\n", |
|
41525
b68272449df4
Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38794
diff
changeset
|
152 PyThread_get_thread_ident(), (void*)rv, errno)); |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
153 obj.id = -1; |
| 2152 | 154 } |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
155 else { |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
156 dprintf(("%ld: PyThread_start_new_thread succeeded: %p\n", |
|
41525
b68272449df4
Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38794
diff
changeset
|
157 PyThread_get_thread_ident(), (void*)rv)); |
|
29755
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
158 /* wait for thread to initialize, so we can get its id */ |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
159 WaitForSingleObject(obj.done, INFINITE); |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
160 assert(obj.id != -1); |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
161 } |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
162 CloseHandle((HANDLE)obj.done); |
|
59da5b57c61b
An Anonymous Coward on c.l.py posted a little program with bizarre
Tim Peters <tim.peters@gmail.com>
parents:
22092
diff
changeset
|
163 return obj.id; |
| 2152 | 164 } |
| 165 | |
| 166 /* | |
| 167 * Return the thread Id instead of an handle. The Id is said to uniquely identify the | |
| 168 * thread in the system | |
| 169 */ | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
170 long |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
171 PyThread_get_thread_ident(void) |
| 2152 | 172 { |
| 173 if (!initialized) | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
174 PyThread_init_thread(); |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
175 |
| 2152 | 176 return GetCurrentThreadId(); |
| 177 } | |
| 178 | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
179 static void |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
180 do_PyThread_exit_thread(int no_cleanup) |
| 2152 | 181 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
182 dprintf(("%ld: PyThread_exit_thread called\n", PyThread_get_thread_ident())); |
| 2152 | 183 if (!initialized) |
| 184 if (no_cleanup) | |
| 185 _exit(0); | |
| 186 else | |
| 187 exit(0); | |
|
6029
68f2d7704180
Use _beginthread() and _endthread() in favor of CreateThread() and
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
188 _endthread(); |
| 2152 | 189 } |
| 190 | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
191 void |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
192 PyThread_exit_thread(void) |
| 2152 | 193 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
194 do_PyThread_exit_thread(0); |
| 2152 | 195 } |
| 196 | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
197 void |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
198 PyThread__exit_thread(void) |
| 2152 | 199 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
200 do_PyThread_exit_thread(1); |
| 2152 | 201 } |
| 202 | |
| 203 #ifndef NO_EXIT_PROG | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
204 static void |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
205 do_PyThread_exit_prog(int status, int no_cleanup) |
| 2152 | 206 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
207 dprintf(("PyThread_exit_prog(%d) called\n", status)); |
| 2152 | 208 if (!initialized) |
| 209 if (no_cleanup) | |
| 210 _exit(status); | |
| 211 else | |
| 212 exit(status); | |
| 213 } | |
| 214 | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
215 void |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
216 PyThread_exit_prog(int status) |
| 2152 | 217 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
218 do_PyThread_exit_prog(status, 0); |
| 2152 | 219 } |
| 220 | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
221 void |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
222 PyThread__exit_prog(int status) |
| 2152 | 223 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
224 do_PyThread_exit_prog(status, 1); |
| 2152 | 225 } |
| 226 #endif /* NO_EXIT_PROG */ | |
| 227 | |
| 228 /* | |
| 229 * Lock support. It has too be implemented as semaphores. | |
| 230 * I [Dag] tried to implement it with mutex but I could find a way to | |
| 231 * tell whether a thread already own the lock or not. | |
| 232 */ | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
233 PyThread_type_lock |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
234 PyThread_allocate_lock(void) |
| 2152 | 235 { |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
236 PNRMUTEX aLock; |
| 2152 | 237 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
238 dprintf(("PyThread_allocate_lock called\n")); |
| 2152 | 239 if (!initialized) |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
240 PyThread_init_thread(); |
| 2152 | 241 |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
242 aLock = AllocNonRecursiveMutex() ; |
| 2152 | 243 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
244 dprintf(("%ld: PyThread_allocate_lock() -> %p\n", PyThread_get_thread_ident(), aLock)); |
| 2152 | 245 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
246 return (PyThread_type_lock) aLock; |
| 2152 | 247 } |
| 248 | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
249 void |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
250 PyThread_free_lock(PyThread_type_lock aLock) |
| 2152 | 251 { |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
252 dprintf(("%ld: PyThread_free_lock(%p) called\n", PyThread_get_thread_ident(),aLock)); |
| 2152 | 253 |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
254 FreeNonRecursiveMutex(aLock) ; |
| 2152 | 255 } |
| 256 | |
| 257 /* | |
| 258 * Return 1 on success if the lock was acquired | |
| 259 * | |
| 260 * and 0 if the lock was not acquired. This means a 0 is returned | |
| 261 * if the lock has already been acquired by this thread! | |
| 262 */ | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
263 int |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
264 PyThread_acquire_lock(PyThread_type_lock aLock, int waitflag) |
| 2152 | 265 { |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
266 int success ; |
| 2152 | 267 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
268 dprintf(("%ld: PyThread_acquire_lock(%p, %d) called\n", PyThread_get_thread_ident(),aLock, waitflag)); |
| 2152 | 269 |
|
35217
b86392f55b59
bug [ 1234979 ] Lock.acquire treats only 1 as True
Georg Brandl <georg@python.org>
parents:
29755
diff
changeset
|
270 success = aLock && EnterNonRecursiveMutex((PNRMUTEX) aLock, (waitflag ? INFINITE : 0)) == WAIT_OBJECT_0 ; |
| 2152 | 271 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
272 dprintf(("%ld: PyThread_acquire_lock(%p, %d) -> %d\n", PyThread_get_thread_ident(),aLock, waitflag, success)); |
| 2152 | 273 |
| 274 return success; | |
| 275 } | |
| 276 | |
|
38579
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
277 void |
|
19430cdff2bd
clean up function declarations to conform to PEP-7 style.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38578
diff
changeset
|
278 PyThread_release_lock(PyThread_type_lock aLock) |
| 2152 | 279 { |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
280 dprintf(("%ld: PyThread_release_lock(%p) called\n", PyThread_get_thread_ident(),aLock)); |
| 2152 | 281 |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
282 if (!(aLock && LeaveNonRecursiveMutex((PNRMUTEX) aLock))) |
|
41525
b68272449df4
Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
38794
diff
changeset
|
283 dprintf(("%ld: Could not PyThread_release_lock(%p) error: %ld\n", PyThread_get_thread_ident(), aLock, GetLastError())); |
| 2152 | 284 } |
|
38794
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
285 |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
286 /* minimum/maximum thread stack sizes supported */ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
287 #define THREAD_MIN_STACKSIZE 0x8000 /* 32kB */ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
288 #define THREAD_MAX_STACKSIZE 0x10000000 /* 256MB */ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
289 |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
290 /* set the thread stack size. |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
291 * Return 0 if size is valid, -1 otherwise. |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
292 */ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
293 static int |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
294 _pythread_nt_set_stacksize(size_t size) |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
295 { |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
296 /* set to default */ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
297 if (size == 0) { |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
298 _pythread_stacksize = 0; |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
299 return 0; |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
300 } |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
301 |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
302 /* valid range? */ |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
303 if (size >= THREAD_MIN_STACKSIZE && size < THREAD_MAX_STACKSIZE) { |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
304 _pythread_stacksize = size; |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
305 return 0; |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
306 } |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
307 |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
308 return -1; |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
309 } |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
310 |
|
f7d23bca599f
Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
38716
diff
changeset
|
311 #define THREAD_SET_STACKSIZE(x) _pythread_nt_set_stacksize(x) |
