Mercurial > cpython-lru_cache-weakref
annotate Python/thread.c @ 46664:031dfe455585
Merged revisions 62425-62429,62434-62436,62441,62444,62446-62448,62450-62455,62463,62465-62466,62469,62474,62476-62478,62480,62485,62492,62497-62498,62500,62507,62513-62514,62516,62521,62531,62535,62545-62546,62548-62551,62553-62559,62569,62574,62577,62593,62595,62604-62606,62608,62616,62626-62627,62636,62638,62644-62645,62647-62648,62651-62653,62656,62661,62663,62680,62686-62687,62696,62699-62703,62711 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r62425 | andrew.kuchling | 2008-04-21 03:45:57 +0200 (Mon, 21 Apr 2008) | 1 line
Comment typo
................
r62426 | mark.dickinson | 2008-04-21 03:55:50 +0200 (Mon, 21 Apr 2008) | 2 lines
Silence 'r may be used uninitialized' compiler warning.
................
r62427 | andrew.kuchling | 2008-04-21 04:08:00 +0200 (Mon, 21 Apr 2008) | 1 line
Markup fix
................
r62428 | andrew.kuchling | 2008-04-21 04:08:13 +0200 (Mon, 21 Apr 2008) | 1 line
Wording changes
................
r62429 | andrew.kuchling | 2008-04-21 04:14:24 +0200 (Mon, 21 Apr 2008) | 1 line
Add various items
................
r62434 | thomas.heller | 2008-04-21 15:46:55 +0200 (Mon, 21 Apr 2008) | 1 line
Fix typo.
................
r62435 | david.goodger | 2008-04-21 16:40:22 +0200 (Mon, 21 Apr 2008) | 1 line
corrections ("reStructuredText" is one word)
................
r62436 | david.goodger | 2008-04-21 16:43:33 +0200 (Mon, 21 Apr 2008) | 1 line
capitalization
................
r62441 | gregory.p.smith | 2008-04-21 19:46:40 +0200 (Mon, 21 Apr 2008) | 2 lines
explicitly flush after the ... since there wasn't a newline
................
r62444 | jeroen.ruigrok | 2008-04-21 22:15:39 +0200 (Mon, 21 Apr 2008) | 2 lines
Windows x64 also falls under VER_PLATFORM_WIN32_NT.
................
r62446 | gregory.p.smith | 2008-04-21 23:31:08 +0200 (Mon, 21 Apr 2008) | 3 lines
If sys.stdin is not a tty, fall back to default_getpass after printing
a warning instead of failing with a termios.error.
................
r62447 | mark.dickinson | 2008-04-22 00:32:24 +0200 (Tue, 22 Apr 2008) | 8 lines
test_math and test_cmath are failing on the FreeBSD 6.2 trunk buildbot,
apparently because tanh(-0.) loses the sign of zero on that platform.
If true, this is a bug in FreeBSD.
Added a configure test to verify this. I still need to figure out
how best to deal with this failure.
................
r62448 | amaury.forgeotdarc | 2008-04-22 00:35:30 +0200 (Tue, 22 Apr 2008) | 7 lines
Issue 2665: On Windows, sys.stderr does not contain a valid file when running without a console.
It seems to work, but will fail at the first flush.
This causes IDLE to crash when too many warnings are printed.
Will backport.
................
r62450 | benjamin.peterson | 2008-04-22 00:57:00 +0200 (Tue, 22 Apr 2008) | 2 lines
Fix Sphinx warnings
................
r62451 | mark.dickinson | 2008-04-22 02:54:27 +0200 (Tue, 22 Apr 2008) | 3 lines
Make configure test for tanh(-0.) == -0. committed in r62447 actually
work. (The test wasn't properly linked with libm. Sigh.)
................
r62452 | benjamin.peterson | 2008-04-22 04:16:03 +0200 (Tue, 22 Apr 2008) | 2 lines
Various io doc updates
................
r62453 | neal.norwitz | 2008-04-22 07:07:47 +0200 (Tue, 22 Apr 2008) | 1 line
Add Thomas Lee
................
r62454 | gregory.p.smith | 2008-04-22 10:08:41 +0200 (Tue, 22 Apr 2008) | 8 lines
Major improvements:
* Default to using /dev/tty for the password prompt and input before
falling back to sys.stdin and sys.stderr.
* Use sys.stderr instead of sys.stdout.
* print the 'password may be echoed' warning to stream used to display
the prompt rather than always sys.stderr.
* warn() with GetPassWarning when input may be echoed.
................
r62455 | gregory.p.smith | 2008-04-22 10:11:33 +0200 (Tue, 22 Apr 2008) | 2 lines
update the getpass entry
................
r62463 | amaury.forgeotdarc | 2008-04-22 23:14:41 +0200 (Tue, 22 Apr 2008) | 5 lines
Issue #2670: urllib2.build_opener() failed when two handlers
derive the same default base class.
Will backport.
................
r62465 | skip.montanaro | 2008-04-23 00:45:09 +0200 (Wed, 23 Apr 2008) | 3 lines
Factor in documentation changes from issue 1753732.
................
r62466 | gregory.p.smith | 2008-04-23 03:06:42 +0200 (Wed, 23 Apr 2008) | 2 lines
syntax fixup
................
r62469 | benjamin.peterson | 2008-04-23 22:38:06 +0200 (Wed, 23 Apr 2008) | 2 lines
#2673 Fix example typo in optparse docs
................
r62474 | martin.v.loewis | 2008-04-24 11:50:50 +0200 (Thu, 24 Apr 2008) | 2 lines
Add Guilherme Polo.
................
r62476 | martin.v.loewis | 2008-04-24 15:16:36 +0200 (Thu, 24 Apr 2008) | 3 lines
Remove Py_Refcnt, Py_Type, Py_Size, as they were added only
for backwards compatibility, yet 2.5 did not have them at all.
................
r62477 | martin.v.loewis | 2008-04-24 15:17:24 +0200 (Thu, 24 Apr 2008) | 2 lines
Fix typo.
................
r62478 | martin.v.loewis | 2008-04-24 15:18:03 +0200 (Thu, 24 Apr 2008) | 2 lines
Add Jesus Cea.
................
r62480 | amaury.forgeotdarc | 2008-04-24 20:07:05 +0200 (Thu, 24 Apr 2008) | 4 lines
Issue2681: the literal 0o8 was wrongly accepted, and evaluated as float(0.0).
This happened only when 8 is the first digit.
Credits go to Lukas Meuser.
................
r62485 | amaury.forgeotdarc | 2008-04-24 22:10:26 +0200 (Thu, 24 Apr 2008) | 5 lines
Disable gc when running test_trace, or we may record the __del__ of collected objects.
See http://mail.python.org/pipermail/python-checkins/2008-April/068633.html
the extra events perfectly match several calls to socket._fileobject.__del__()
................
r62492 | neal.norwitz | 2008-04-25 05:40:17 +0200 (Fri, 25 Apr 2008) | 1 line
Fix typo (now -> no)
................
r62497 | armin.rigo | 2008-04-25 11:35:18 +0200 (Fri, 25 Apr 2008) | 2 lines
A new crasher.
................
r62498 | thomas.heller | 2008-04-25 17:44:16 +0200 (Fri, 25 Apr 2008) | 1 line
Add from_buffer and from_buffer_copy class methods to ctypes types.
................
r62500 | mark.dickinson | 2008-04-25 18:59:09 +0200 (Fri, 25 Apr 2008) | 3 lines
Issue 2635: fix bug in the fix_sentence_endings option to textwrap.fill.
................
r62507 | benjamin.peterson | 2008-04-25 23:43:56 +0200 (Fri, 25 Apr 2008) | 2 lines
Allow test_import to work when it is invoked directly
................
r62513 | georg.brandl | 2008-04-26 20:31:07 +0200 (Sat, 26 Apr 2008) | 2 lines
#2691: document PyLong (s)size_t APIs, patch by Alexander Belopolsky.
................
r62514 | georg.brandl | 2008-04-26 20:32:17 +0200 (Sat, 26 Apr 2008) | 2 lines
Add missing return type to dealloc.
................
r62516 | alexandre.vassalotti | 2008-04-27 02:52:24 +0200 (Sun, 27 Apr 2008) | 2 lines
Fixed URL of PEP 205 in weakref's module docstring.
................
r62521 | georg.brandl | 2008-04-27 11:39:59 +0200 (Sun, 27 Apr 2008) | 2 lines
#2677: add note that not all functions may accept keyword args.
................
r62531 | georg.brandl | 2008-04-27 19:38:55 +0200 (Sun, 27 Apr 2008) | 2 lines
Use correct XHTML tags.
................
r62535 | benjamin.peterson | 2008-04-27 20:14:39 +0200 (Sun, 27 Apr 2008) | 2 lines
#2700 Document PyNumber_ToBase
................
r62545 | skip.montanaro | 2008-04-27 22:53:57 +0200 (Sun, 27 Apr 2008) | 1 line
minor wording changes, rewrap a few lines
................
r62546 | kurt.kaiser | 2008-04-27 23:07:41 +0200 (Sun, 27 Apr 2008) | 7 lines
Home / Control-A toggles between left margin and end of leading white
space. Patch 1196903 Jeff Shute.
M idlelib/PyShell.py
M idlelib/EditorWindow.py
M idlelib/NEWS.txt
................
r62548 | kurt.kaiser | 2008-04-27 23:38:05 +0200 (Sun, 27 Apr 2008) | 2 lines
Improved AutoCompleteWindow logic. Patch 2062 Tal Einat.
................
r62549 | kurt.kaiser | 2008-04-27 23:52:19 +0200 (Sun, 27 Apr 2008) | 4 lines
Autocompletion of filenames now support alternate separators, e.g. the
'/' char on Windows. Patch 2061 Tal Einat.
................
r62550 | skip.montanaro | 2008-04-28 00:49:56 +0200 (Mon, 28 Apr 2008) | 6 lines
A few small changes:
* The only exception we should catch when trying to import cStringIO is an
ImportError.
* Delete the function signatures embedded in the mk*temp docstrings.
* The tempdir global variable was initialized twice.
................
r62551 | skip.montanaro | 2008-04-28 00:52:02 +0200 (Mon, 28 Apr 2008) | 4 lines
Wrap some long paragraphs and include the default values for optional
function parameters.
................
r62553 | skip.montanaro | 2008-04-28 04:57:23 +0200 (Mon, 28 Apr 2008) | 7 lines
Minor cleanups:
* Avoid creating unused local variables where we can. Where we can't prefix
the unused variables with '_'.
* Avoid shadowing builtins where it won't change the external interface of a
function.
* Use None as default path arg to readmodule and readmodule_ex.
................
r62554 | skip.montanaro | 2008-04-28 04:59:45 +0200 (Mon, 28 Apr 2008) | 6 lines
Correct documentation to match implementation: "Class" instead of
"class_descriptor", "Function" instead of "function_descriptor". Note
default path value for readmodule*. Wrap some long paragraphs. Don't
mention 'inpackage' which isn't part of the public API.
................
r62555 | brett.cannon | 2008-04-28 05:23:50 +0200 (Mon, 28 Apr 2008) | 5 lines
Fix a bug introduced by the warnings rewrite where tracebacks were being
improperly indented.
Closes issue #2699.
................
r62556 | skip.montanaro | 2008-04-28 05:25:37 +0200 (Mon, 28 Apr 2008) | 2 lines
Wrap some long lines.
................
r62557 | skip.montanaro | 2008-04-28 05:27:53 +0200 (Mon, 28 Apr 2008) | 6 lines
Get rid of _test(), _main(), _debug() and _check(). Tests are no longer
needed (better set available in Lib/test/test_robotparser.py). Clean up a
few PEP 8 nits (compound statements on a single line, whitespace around
operators).
................
r62558 | brett.cannon | 2008-04-28 06:50:06 +0200 (Mon, 28 Apr 2008) | 3 lines
Rename the test_traceback_print() function to traceback_print() to prevent
test_capi from automatically calling the function.
................
r62559 | georg.brandl | 2008-04-28 07:16:30 +0200 (Mon, 28 Apr 2008) | 2 lines
Fix markup.
................
r62569 | amaury.forgeotdarc | 2008-04-28 23:07:06 +0200 (Mon, 28 Apr 2008) | 5 lines
test_sundry performs minimal tests (a simple import...) on modules that are not tested otherwise.
Some of them now have tests and can be removed.
Only 70 to go...
................
r62574 | andrew.kuchling | 2008-04-29 04:03:54 +0200 (Tue, 29 Apr 2008) | 1 line
Strip down SSL docs; I'm not managing to get test programs working, so I'll just give a minimal description
................
r62577 | martin.v.loewis | 2008-04-29 08:10:53 +0200 (Tue, 29 Apr 2008) | 2 lines
Add Rodrigo and Heiko.
................
r62593 | nick.coghlan | 2008-04-30 16:23:36 +0200 (Wed, 30 Apr 2008) | 1 line
Update command line usage documentation to reflect 2.6 changes (also includes some minor cleanups). Addresses TODO list issue 2258
................
r62595 | andrew.kuchling | 2008-04-30 18:19:55 +0200 (Wed, 30 Apr 2008) | 1 line
Typo fix
................
r62604 | benjamin.peterson | 2008-04-30 23:03:58 +0200 (Wed, 30 Apr 2008) | 2 lines
make test_support's captured_output a bit more robust when exceptions happen
................
r62605 | georg.brandl | 2008-04-30 23:08:42 +0200 (Wed, 30 Apr 2008) | 2 lines
#1748: use functools.wraps instead of rolling own metadata update.
................
r62606 | benjamin.peterson | 2008-04-30 23:25:55 +0200 (Wed, 30 Apr 2008) | 2 lines
Remove some from __future__ import with_statements
................
r62608 | benjamin.peterson | 2008-05-01 00:03:36 +0200 (Thu, 01 May 2008) | 2 lines
Fix typo in whatsnew
................
r62616 | georg.brandl | 2008-05-01 20:24:32 +0200 (Thu, 01 May 2008) | 2 lines
Fix synopsis.
................
r62626 | brett.cannon | 2008-05-02 04:25:09 +0200 (Fri, 02 May 2008) | 6 lines
Fix a backwards-compatibility mistake where a new optional argument for
warnings.showwarning() was being used. This broke pre-existing replacements for
the function since they didn't support the extra argument.
Closes issue 2705.
................
r62627 | gregory.p.smith | 2008-05-02 09:26:52 +0200 (Fri, 02 May 2008) | 20 lines
This should fix issue2632. A long description of the two competing
problems is in the bug report (one old, one recently introduced trying
to fix the old one). In short:
buffer data during socket._fileobject.read() and readlines() within a
cStringIO object instead of a [] of str()s returned from the recv()
call.
This prevents excessive memory use due to the size parameter being
passed to recv() being grossly larger than the actual size of the data
returned *and* prevents excessive cpu usage due to looping in python
calling recv() with a very tiny size value if min() is used as the
previous memory-use bug "fix" did.
It also documents what the socket._fileobject._rbufsize member is
actually used for.
This is a candidate for back porting to 2.5.
................
r62636 | mark.hammond | 2008-05-02 14:48:15 +0200 (Fri, 02 May 2008) | 2 lines
#2581: Vista UAC/elevation support for bdist_wininst
................
r62638 | facundo.batista | 2008-05-02 19:39:00 +0200 (Fri, 02 May 2008) | 3 lines
Fixed some test structures. Thanks Mark Dickinson.
................
r62644 | ronald.oussoren | 2008-05-02 21:45:11 +0200 (Fri, 02 May 2008) | 7 lines
Fix for issue #2573: Can't change the framework name on OS X builds
This introduces a new configure option: --with-framework-name=NAME
(defaulting to 'Python'). This allows you to install several copies
of the Python framework with different names (such as a normal build
and a debug build).
................
r62645 | ronald.oussoren | 2008-05-02 21:58:56 +0200 (Fri, 02 May 2008) | 2 lines
Finish fix for issue2573, previous patch was incomplete.
................
r62647 | martin.v.loewis | 2008-05-02 23:30:20 +0200 (Fri, 02 May 2008) | 13 lines
Merged revisions 62263-62646 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r62470 | david.wolever | 2008-04-24 02:11:07 +0200 (Do, 24 Apr 2008) | 3 lines
Fixed up and applied the patch for #2431 -- speeding up 2to3 with a lookup table.
........
r62646 | martin.v.loewis | 2008-05-02 23:29:27 +0200 (Fr, 02 Mai 2008) | 2 lines
Fix whitespace.
........
................
r62648 | ronald.oussoren | 2008-05-02 23:42:35 +0200 (Fri, 02 May 2008) | 4 lines
Fix for #1905: PythonLauncher not working correctly on OSX 10.5/Leopard
This fixes both Python Launchar and the terminalcommand module.
................
r62651 | ronald.oussoren | 2008-05-02 23:54:56 +0200 (Fri, 02 May 2008) | 2 lines
Fix for issue #2520 (cannot import macerrors)
................
r62652 | benjamin.peterson | 2008-05-03 00:12:58 +0200 (Sat, 03 May 2008) | 2 lines
capitalization nit for reStructuredText
................
r62653 | brett.cannon | 2008-05-03 03:02:41 +0200 (Sat, 03 May 2008) | 2 lines
Fix some indentation errors.
................
r62656 | brett.cannon | 2008-05-03 05:19:39 +0200 (Sat, 03 May 2008) | 6 lines
Fix the C implementation of 'warnings' to infer the filename of the module that
raised an exception properly when __file__ is not set, __name__ == '__main__',
and sys.argv[0] is a false value.
Closes issue2743.
................
r62661 | amaury.forgeotdarc | 2008-05-03 14:21:13 +0200 (Sat, 03 May 2008) | 8 lines
In test_io, StatefulIncrementalDecoderTest was not part of the test suite.
And of course, the test failed:
a bytearray was used without reason in io.TextIOWrapper.tell().
The difference is that iterating over bytes (i.e. str in python2.6) returns 1-char bytes,
whereas bytearrays yield integers.
This code should still work with python3.0
................
r62663 | benjamin.peterson | 2008-05-03 17:56:42 +0200 (Sat, 03 May 2008) | 2 lines
The compiling struct is now passed around to all AST helpers (see issue 2720)
................
r62680 | benjamin.peterson | 2008-05-03 23:35:18 +0200 (Sat, 03 May 2008) | 2 lines
Moved testing of builtin types out of test_builtin and into type specific modules
................
r62686 | mark.dickinson | 2008-05-04 04:25:46 +0200 (Sun, 04 May 2008) | 4 lines
Make sure that Context traps and flags dictionaries have values 0 and 1
(as documented) rather than True and False.
................
r62687 | benjamin.peterson | 2008-05-04 05:05:49 +0200 (Sun, 04 May 2008) | 2 lines
Fix typo in whatsnew
................
r62696 | georg.brandl | 2008-05-04 11:15:04 +0200 (Sun, 04 May 2008) | 2 lines
#2752: wrong meaning of '' for socket host.
................
r62699 | christian.heimes | 2008-05-04 13:50:53 +0200 (Sun, 04 May 2008) | 1 line
Added note that Python requires at least Win2k SP4
................
r62700 | gerhard.haering | 2008-05-04 14:59:57 +0200 (Sun, 04 May 2008) | 3 lines
SQLite requires 64-bit integers in order to build. So the whole HAVE_LONG_LONG
#ifdefing was useless.
................
r62701 | gerhard.haering | 2008-05-04 15:15:12 +0200 (Sun, 04 May 2008) | 3 lines
Applied sqliterow-richcmp.diff patch from Thomas Heller in Issue2152. The
sqlite3.Row type is now correctly hashable.
................
r62702 | gerhard.haering | 2008-05-04 15:42:44 +0200 (Sun, 04 May 2008) | 5 lines
Implemented feature request 2157: Converter names are cut off at '('
characters. This avoids the common case of something like 'NUMBER(10)' not
being parsed as 'NUMBER', like expected. Also corrected the docs about
converter names being case-sensitive. They aren't any longer.
................
r62703 | georg.brandl | 2008-05-04 17:45:05 +0200 (Sun, 04 May 2008) | 2 lines
#2757: Remove spare newline.
................
r62711 | benjamin.peterson | 2008-05-04 21:10:02 +0200 (Sun, 04 May 2008) | 2 lines
Fix typo in bugs.rst
................
| author | Christian Heimes <christian@cheimes.de> |
|---|---|
| date | Sun, 04 May 2008 22:42:01 +0000 |
| parents | fb5a6330f71b |
| children | 71cb7ea4f110 |
| rev | line source |
|---|---|
|
1198
2937897a7d8b
* Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents:
1186
diff
changeset
|
1 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
2 /* Thread package. |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
3 This is intended to be usable independently from Python. |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
4 The implementation for system foobar is in a file thread_foobar.h |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
5 which is included by this file dependent on config settings. |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
6 Stuff shared by all thread_*.h files is collected here. */ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
7 |
|
21712
c64fc56f6072
Include <unistd.h> in Python.h. Fixes #500924.
Martin v. Löwis <martin@v.loewis.de>
parents:
20468
diff
changeset
|
8 #include "Python.h" |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
9 |
|
33145
28a205ecb4dd
The attached patch fixes FTBFS on GNU/k*BSD. The problem happens on GNU/k*BSD
Matthias Klose <doko@ubuntu.com>
parents:
31504
diff
changeset
|
10 |
|
28a205ecb4dd
The attached patch fixes FTBFS on GNU/k*BSD. The problem happens on GNU/k*BSD
Matthias Klose <doko@ubuntu.com>
parents:
31504
diff
changeset
|
11 #ifndef _POSIX_THREADS |
|
28a205ecb4dd
The attached patch fixes FTBFS on GNU/k*BSD. The problem happens on GNU/k*BSD
Matthias Klose <doko@ubuntu.com>
parents:
31504
diff
changeset
|
12 /* This means pthreads are not implemented in libc headers, hence the macro |
|
28a205ecb4dd
The attached patch fixes FTBFS on GNU/k*BSD. The problem happens on GNU/k*BSD
Matthias Klose <doko@ubuntu.com>
parents:
31504
diff
changeset
|
13 not present in unistd.h. But they still can be implemented as an external |
|
28a205ecb4dd
The attached patch fixes FTBFS on GNU/k*BSD. The problem happens on GNU/k*BSD
Matthias Klose <doko@ubuntu.com>
parents:
31504
diff
changeset
|
14 library (e.g. gnu pth in pthread emulation) */ |
|
28a205ecb4dd
The attached patch fixes FTBFS on GNU/k*BSD. The problem happens on GNU/k*BSD
Matthias Klose <doko@ubuntu.com>
parents:
31504
diff
changeset
|
15 # ifdef HAVE_PTHREAD_H |
|
28a205ecb4dd
The attached patch fixes FTBFS on GNU/k*BSD. The problem happens on GNU/k*BSD
Matthias Klose <doko@ubuntu.com>
parents:
31504
diff
changeset
|
16 # include <pthread.h> /* _POSIX_THREADS */ |
|
28a205ecb4dd
The attached patch fixes FTBFS on GNU/k*BSD. The problem happens on GNU/k*BSD
Matthias Klose <doko@ubuntu.com>
parents:
31504
diff
changeset
|
17 # endif |
|
28a205ecb4dd
The attached patch fixes FTBFS on GNU/k*BSD. The problem happens on GNU/k*BSD
Matthias Klose <doko@ubuntu.com>
parents:
31504
diff
changeset
|
18 #endif |
|
28a205ecb4dd
The attached patch fixes FTBFS on GNU/k*BSD. The problem happens on GNU/k*BSD
Matthias Klose <doko@ubuntu.com>
parents:
31504
diff
changeset
|
19 |
|
10530
d834ecdf8c26
Changes by Mark Hammond for Windows CE. Mostly of the form
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
20 #ifndef DONT_HAVE_STDIO_H |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
21 #include <stdio.h> |
|
10530
d834ecdf8c26
Changes by Mark Hammond for Windows CE. Mostly of the form
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
22 #endif |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
23 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
24 #include <stdlib.h> |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
25 |
|
5381
339d4129d3f7
Ugly hack for SGI IRIX 6.2. Apparently _POSIX_THREADS is defined even
Guido van Rossum <guido@python.org>
parents:
4839
diff
changeset
|
26 #ifdef __sgi |
|
339d4129d3f7
Ugly hack for SGI IRIX 6.2. Apparently _POSIX_THREADS is defined even
Guido van Rossum <guido@python.org>
parents:
4839
diff
changeset
|
27 #ifndef HAVE_PTHREAD_H /* XXX Need to check in configure.in */ |
|
339d4129d3f7
Ugly hack for SGI IRIX 6.2. Apparently _POSIX_THREADS is defined even
Guido van Rossum <guido@python.org>
parents:
4839
diff
changeset
|
28 #undef _POSIX_THREADS |
|
339d4129d3f7
Ugly hack for SGI IRIX 6.2. Apparently _POSIX_THREADS is defined even
Guido van Rossum <guido@python.org>
parents:
4839
diff
changeset
|
29 #endif |
|
339d4129d3f7
Ugly hack for SGI IRIX 6.2. Apparently _POSIX_THREADS is defined even
Guido van Rossum <guido@python.org>
parents:
4839
diff
changeset
|
30 #endif |
|
339d4129d3f7
Ugly hack for SGI IRIX 6.2. Apparently _POSIX_THREADS is defined even
Guido van Rossum <guido@python.org>
parents:
4839
diff
changeset
|
31 |
|
9203
07dae6fdae79
Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
32 #include "pythread.h" |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
34 #ifndef _POSIX_THREADS |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
35 |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 #ifdef __sgi |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
37 #define SGI_THREADS |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
38 #endif |
|
961
a31e07847063
New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
39 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
40 #ifdef HAVE_THREAD_H |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
41 #define SOLARIS_THREADS |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 #endif |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
44 #if defined(sun) && !defined(SOLARIS_THREADS) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
45 #define SUN_LWP |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
46 #endif |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
47 |
| 35549 | 48 /* Check if we're running on HP-UX and _SC_THREADS is defined. If so, then |
| 49 enough of the Posix threads package is implimented to support python | |
| 50 threads. | |
| 51 | |
| 52 This is valid for HP-UX 11.23 running on an ia64 system. If needed, add | |
| 53 a check of __ia64 to verify that we're running on a ia64 system instead | |
| 54 of a pa-risc system. | |
| 55 */ | |
| 56 #ifdef __hpux | |
| 57 #ifdef _SC_THREADS | |
| 58 #define _POSIX_THREADS | |
| 59 #endif | |
| 60 #endif | |
| 61 | |
| 1418 | 62 #endif /* _POSIX_THREADS */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
63 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 |
|
4839
4567e158d20c
Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
65 #ifdef Py_DEBUG |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
66 static int thread_debug = 0; |
|
23992
95da99187c57
Silence compiler warning
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23777
diff
changeset
|
67 #define dprintf(args) (void)((thread_debug & 1) && printf args) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
68 #define d2printf(args) ((thread_debug & 8) && printf args) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
69 #else |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
70 #define dprintf(args) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
71 #define d2printf(args) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
72 #endif |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
73 |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 static int initialized; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 |
|
13689
9db86b27278f
Prototype yet another forward declaration.
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
76 static void PyThread__init_thread(void); /* Forward */ |
|
1004
5d7142ea01b7
adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents:
961
diff
changeset
|
77 |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
35549
diff
changeset
|
78 void |
|
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
35549
diff
changeset
|
79 PyThread_init_thread(void) |
|
1004
5d7142ea01b7
adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents:
961
diff
changeset
|
80 { |
|
4839
4567e158d20c
Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
81 #ifdef Py_DEBUG |
|
44587
fb5a6330f71b
Merged revisions 59822-59841 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
42645
diff
changeset
|
82 char *p = Py_GETENV("PYTHONTHREADDEBUG"); |
| 1418 | 83 |
| 84 if (p) { | |
| 85 if (*p) | |
| 86 thread_debug = atoi(p); | |
| 87 else | |
| 88 thread_debug = 1; | |
| 89 } | |
|
4839
4567e158d20c
Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
90 #endif /* Py_DEBUG */ |
|
1004
5d7142ea01b7
adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents:
961
diff
changeset
|
91 if (initialized) |
|
5d7142ea01b7
adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents:
961
diff
changeset
|
92 return; |
|
5d7142ea01b7
adapted SV module to the new svideo library.
Sjoerd Mullender <sjoerd@acm.org>
parents:
961
diff
changeset
|
93 initialized = 1; |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9589
diff
changeset
|
94 dprintf(("PyThread_init_thread called\n")); |
|
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9589
diff
changeset
|
95 PyThread__init_thread(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
97 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
98 /* Support for runtime thread stack size tuning. |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
99 A value of 0 means using the platform's default stack size |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
100 or the size specified by the THREAD_STACK_SIZE macro. */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
101 static size_t _pythread_stacksize = 0; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
102 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
103 #ifdef SGI_THREADS |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
104 #include "thread_sgi.h" |
| 1418 | 105 #endif |
|
961
a31e07847063
New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
106 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
107 #ifdef SOLARIS_THREADS |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
108 #include "thread_solaris.h" |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 #endif |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
110 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
111 #ifdef SUN_LWP |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
112 #include "thread_lwp.h" |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 #endif |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
114 |
|
14674
756c8c6535fe
Make better use of GNU Pth -- patch by Andy Dustman.
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
115 #ifdef HAVE_PTH |
|
12611
b320cf3a98b9
Andy Dustman: add GNU pth user-space thread support.
Guido van Rossum <guido@python.org>
parents:
12475
diff
changeset
|
116 #include "thread_pth.h" |
|
30466
1a817694ecbd
Patch #805613: Fix usage of the PTH library.
Martin v. Löwis <martin@v.loewis.de>
parents:
28694
diff
changeset
|
117 #undef _POSIX_THREADS |
|
14674
756c8c6535fe
Make better use of GNU Pth -- patch by Andy Dustman.
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
118 #endif |
|
756c8c6535fe
Make better use of GNU Pth -- patch by Andy Dustman.
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
119 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
120 #ifdef _POSIX_THREADS |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
121 #include "thread_pthread.h" |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
122 #endif |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
123 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
124 #ifdef C_THREADS |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
125 #include "thread_cthread.h" |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
126 #endif |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
127 |
| 2152 | 128 #ifdef NT_THREADS |
| 129 #include "thread_nt.h" | |
| 130 #endif | |
| 131 | |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
5599
diff
changeset
|
132 #ifdef OS2_THREADS |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
5599
diff
changeset
|
133 #include "thread_os2.h" |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
5599
diff
changeset
|
134 #endif |
|
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
5599
diff
changeset
|
135 |
|
10530
d834ecdf8c26
Changes by Mark Hammond for Windows CE. Mostly of the form
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
136 #ifdef WINCE_THREADS |
|
d834ecdf8c26
Changes by Mark Hammond for Windows CE. Mostly of the form
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
137 #include "thread_wince.h" |
|
d834ecdf8c26
Changes by Mark Hammond for Windows CE. Mostly of the form
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
138 #endif |
|
d834ecdf8c26
Changes by Mark Hammond for Windows CE. Mostly of the form
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
139 |
|
22206
b898c0feb754
Patch #504224: add plan9 threads include to thread.c.
Martin v. Löwis <martin@v.loewis.de>
parents:
21712
diff
changeset
|
140 #ifdef PLAN9_THREADS |
|
b898c0feb754
Patch #504224: add plan9 threads include to thread.c.
Martin v. Löwis <martin@v.loewis.de>
parents:
21712
diff
changeset
|
141 #include "thread_plan9.h" |
|
b898c0feb754
Patch #504224: add plan9 threads include to thread.c.
Martin v. Löwis <martin@v.loewis.de>
parents:
21712
diff
changeset
|
142 #endif |
|
b898c0feb754
Patch #504224: add plan9 threads include to thread.c.
Martin v. Löwis <martin@v.loewis.de>
parents:
21712
diff
changeset
|
143 |
|
23777
bec1b942e0bc
Patch #488073: AtheOS port.
Martin v. Löwis <martin@v.loewis.de>
parents:
22509
diff
changeset
|
144 #ifdef ATHEOS_THREADS |
|
bec1b942e0bc
Patch #488073: AtheOS port.
Martin v. Löwis <martin@v.loewis.de>
parents:
22509
diff
changeset
|
145 #include "thread_atheos.h" |
|
bec1b942e0bc
Patch #488073: AtheOS port.
Martin v. Löwis <martin@v.loewis.de>
parents:
22509
diff
changeset
|
146 #endif |
|
bec1b942e0bc
Patch #488073: AtheOS port.
Martin v. Löwis <martin@v.loewis.de>
parents:
22509
diff
changeset
|
147 |
|
961
a31e07847063
New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
148 /* |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
149 #ifdef FOOBAR_THREADS |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
150 #include "thread_foobar.h" |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
151 #endif |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
152 */ |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
153 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
154 /* return the current thread stack size */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
155 size_t |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
156 PyThread_get_stacksize(void) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
157 { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
158 return _pythread_stacksize; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
159 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
160 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
161 /* Only platforms defining a THREAD_SET_STACKSIZE() macro |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
162 in thread_<platform>.h support changing the stack size. |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
163 Return 0 if stack size is valid, |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
164 -1 if stack size value is invalid, |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
165 -2 if setting stack size is not supported. */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
166 int |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
167 PyThread_set_stacksize(size_t size) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
168 { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
169 #if defined(THREAD_SET_STACKSIZE) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
170 return THREAD_SET_STACKSIZE(size); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
171 #else |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
172 return -2; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
173 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
174 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
175 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
176 #ifndef Py_HAVE_NATIVE_TLS |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
177 /* If the platform has not supplied a platform specific |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
178 TLS implementation, provide our own. |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
179 |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
180 This code stolen from "thread_sgi.h", where it was the only |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
181 implementation of an existing Python TLS API. |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
182 */ |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
183 /* ------------------------------------------------------------------------ |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
184 Per-thread data ("key") support. |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
185 |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
186 Use PyThread_create_key() to create a new key. This is typically shared |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
187 across threads. |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
188 |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
189 Use PyThread_set_key_value(thekey, value) to associate void* value with |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
190 thekey in the current thread. Each thread has a distinct mapping of thekey |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
191 to a void* value. Caution: if the current thread already has a mapping |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
192 for thekey, value is ignored. |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
193 |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
194 Use PyThread_get_key_value(thekey) to retrieve the void* value associated |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
195 with thekey in the current thread. This returns NULL if no value is |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
196 associated with thekey in the current thread. |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
197 |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
198 Use PyThread_delete_key_value(thekey) to forget the current thread's associated |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
199 value for thekey. PyThread_delete_key(thekey) forgets the values associated |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
200 with thekey across *all* threads. |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
201 |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
202 While some of these functions have error-return values, none set any |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
203 Python exception. |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
204 |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
205 None of the functions does memory management on behalf of the void* values. |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
206 You need to allocate and deallocate them yourself. If the void* values |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
207 happen to be PyObject*, these functions don't do refcount operations on |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
208 them either. |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
209 |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
210 The GIL does not need to be held when calling these functions; they supply |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
211 their own locking. This isn't true of PyThread_create_key(), though (see |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
212 next paragraph). |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
213 |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
214 There's a hidden assumption that PyThread_create_key() will be called before |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
215 any of the other functions are called. There's also a hidden assumption |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
216 that calls to PyThread_create_key() are serialized externally. |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
217 ------------------------------------------------------------------------ */ |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
218 |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
219 /* A singly-linked list of struct key objects remembers all the key->value |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
220 * associations. File static keyhead heads the list. keymutex is used |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
221 * to enforce exclusion internally. |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
222 */ |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
223 struct key { |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
224 /* Next record in the list, or NULL if this is the last record. */ |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
225 struct key *next; |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
226 |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
227 /* The thread id, according to PyThread_get_thread_ident(). */ |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
228 long id; |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
229 |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
230 /* The key and its associated value. */ |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
231 int key; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
232 void *value; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
233 }; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
234 |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
235 static struct key *keyhead = NULL; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
236 static PyThread_type_lock keymutex = NULL; |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
237 static int nkeys = 0; /* PyThread_create_key() hands out nkeys+1 next */ |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
238 |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
239 /* Internal helper. |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
240 * If the current thread has a mapping for key, the appropriate struct key* |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
241 * is returned. NB: value is ignored in this case! |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
242 * If there is no mapping for key in the current thread, then: |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
243 * If value is NULL, NULL is returned. |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
244 * Else a mapping of key to value is created for the current thread, |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
245 * and a pointer to a new struct key* is returned; except that if |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
246 * malloc() can't find room for a new struct key*, NULL is returned. |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
247 * So when value==NULL, this acts like a pure lookup routine, and when |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
248 * value!=NULL, this acts like dict.setdefault(), returning an existing |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
249 * mapping if one exists, else creating a new mapping. |
|
33712
baa2653f7a76
find_key(): This routine wasn't thread-correct, and accounts for the
Tim Peters <tim.peters@gmail.com>
parents:
33705
diff
changeset
|
250 * |
|
baa2653f7a76
find_key(): This routine wasn't thread-correct, and accounts for the
Tim Peters <tim.peters@gmail.com>
parents:
33705
diff
changeset
|
251 * Caution: this used to be too clever, trying to hold keymutex only |
|
baa2653f7a76
find_key(): This routine wasn't thread-correct, and accounts for the
Tim Peters <tim.peters@gmail.com>
parents:
33705
diff
changeset
|
252 * around the "p->next = keyhead; keyhead = p" pair. That allowed |
|
baa2653f7a76
find_key(): This routine wasn't thread-correct, and accounts for the
Tim Peters <tim.peters@gmail.com>
parents:
33705
diff
changeset
|
253 * another thread to mutate the list, via key deletion, concurrent with |
|
baa2653f7a76
find_key(): This routine wasn't thread-correct, and accounts for the
Tim Peters <tim.peters@gmail.com>
parents:
33705
diff
changeset
|
254 * find_key() crawling over the list. Hilarity ensued. For example, when |
|
baa2653f7a76
find_key(): This routine wasn't thread-correct, and accounts for the
Tim Peters <tim.peters@gmail.com>
parents:
33705
diff
changeset
|
255 * the for-loop here does "p = p->next", p could end up pointing at a |
|
baa2653f7a76
find_key(): This routine wasn't thread-correct, and accounts for the
Tim Peters <tim.peters@gmail.com>
parents:
33705
diff
changeset
|
256 * record that PyThread_delete_key_value() was concurrently free()'ing. |
|
baa2653f7a76
find_key(): This routine wasn't thread-correct, and accounts for the
Tim Peters <tim.peters@gmail.com>
parents:
33705
diff
changeset
|
257 * That could lead to anything, from failing to find a key that exists, to |
|
baa2653f7a76
find_key(): This routine wasn't thread-correct, and accounts for the
Tim Peters <tim.peters@gmail.com>
parents:
33705
diff
changeset
|
258 * segfaults. Now we lock the whole routine. |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
259 */ |
|
33699
0c26db381673
Style guide & consistency changes. No semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
33145
diff
changeset
|
260 static struct key * |
|
0c26db381673
Style guide & consistency changes. No semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
33145
diff
changeset
|
261 find_key(int key, void *value) |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
262 { |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
263 struct key *p; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
264 long id = PyThread_get_thread_ident(); |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
265 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
266 if (!keymutex) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
267 return NULL; |
|
33712
baa2653f7a76
find_key(): This routine wasn't thread-correct, and accounts for the
Tim Peters <tim.peters@gmail.com>
parents:
33705
diff
changeset
|
268 PyThread_acquire_lock(keymutex, 1); |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
269 for (p = keyhead; p != NULL; p = p->next) { |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
270 if (p->id == id && p->key == key) |
|
33712
baa2653f7a76
find_key(): This routine wasn't thread-correct, and accounts for the
Tim Peters <tim.peters@gmail.com>
parents:
33705
diff
changeset
|
271 goto Done; |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
272 } |
|
33712
baa2653f7a76
find_key(): This routine wasn't thread-correct, and accounts for the
Tim Peters <tim.peters@gmail.com>
parents:
33705
diff
changeset
|
273 if (value == NULL) { |
|
baa2653f7a76
find_key(): This routine wasn't thread-correct, and accounts for the
Tim Peters <tim.peters@gmail.com>
parents:
33705
diff
changeset
|
274 assert(p == NULL); |
|
baa2653f7a76
find_key(): This routine wasn't thread-correct, and accounts for the
Tim Peters <tim.peters@gmail.com>
parents:
33705
diff
changeset
|
275 goto Done; |
|
baa2653f7a76
find_key(): This routine wasn't thread-correct, and accounts for the
Tim Peters <tim.peters@gmail.com>
parents:
33705
diff
changeset
|
276 } |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
277 p = (struct key *)malloc(sizeof(struct key)); |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
278 if (p != NULL) { |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
279 p->id = id; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
280 p->key = key; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
281 p->value = value; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
282 p->next = keyhead; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
283 keyhead = p; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
284 } |
|
33712
baa2653f7a76
find_key(): This routine wasn't thread-correct, and accounts for the
Tim Peters <tim.peters@gmail.com>
parents:
33705
diff
changeset
|
285 Done: |
|
baa2653f7a76
find_key(): This routine wasn't thread-correct, and accounts for the
Tim Peters <tim.peters@gmail.com>
parents:
33705
diff
changeset
|
286 PyThread_release_lock(keymutex); |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
287 return p; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
288 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
289 |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
290 /* Return a new key. This must be called before any other functions in |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
291 * this family, and callers must arrange to serialize calls to this |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
292 * function. No violations are detected. |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
293 */ |
|
33699
0c26db381673
Style guide & consistency changes. No semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
33145
diff
changeset
|
294 int |
|
0c26db381673
Style guide & consistency changes. No semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
33145
diff
changeset
|
295 PyThread_create_key(void) |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
296 { |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
297 /* All parts of this function are wrong if it's called by multiple |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
298 * threads simultaneously. |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
299 */ |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
300 if (keymutex == NULL) |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
301 keymutex = PyThread_allocate_lock(); |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
302 return ++nkeys; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
303 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
304 |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
305 /* Forget the associations for key across *all* threads. */ |
|
33699
0c26db381673
Style guide & consistency changes. No semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
33145
diff
changeset
|
306 void |
|
0c26db381673
Style guide & consistency changes. No semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
33145
diff
changeset
|
307 PyThread_delete_key(int key) |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
308 { |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
309 struct key *p, **q; |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
310 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
311 PyThread_acquire_lock(keymutex, 1); |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
312 q = &keyhead; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
313 while ((p = *q) != NULL) { |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
314 if (p->key == key) { |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
315 *q = p->next; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
316 free((void *)p); |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
317 /* NB This does *not* free p->value! */ |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
318 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
319 else |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
320 q = &p->next; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
321 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
322 PyThread_release_lock(keymutex); |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
323 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
324 |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
325 /* Confusing: If the current thread has an association for key, |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
326 * value is ignored, and 0 is returned. Else an attempt is made to create |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
327 * an association of key to value for the current thread. 0 is returned |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
328 * if that succeeds, but -1 is returned if there's not enough memory |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
329 * to create the association. value must not be NULL. |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
330 */ |
|
33699
0c26db381673
Style guide & consistency changes. No semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
33145
diff
changeset
|
331 int |
|
0c26db381673
Style guide & consistency changes. No semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
33145
diff
changeset
|
332 PyThread_set_key_value(int key, void *value) |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
333 { |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
334 struct key *p; |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
335 |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
336 assert(value != NULL); |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
337 p = find_key(key, value); |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
338 if (p == NULL) |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
339 return -1; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
340 else |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
341 return 0; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
342 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
343 |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
344 /* Retrieve the value associated with key in the current thread, or NULL |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
345 * if the current thread doesn't have an association for key. |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
346 */ |
|
33699
0c26db381673
Style guide & consistency changes. No semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
33145
diff
changeset
|
347 void * |
|
0c26db381673
Style guide & consistency changes. No semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
33145
diff
changeset
|
348 PyThread_get_key_value(int key) |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
349 { |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
350 struct key *p = find_key(key, NULL); |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
351 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
352 if (p == NULL) |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
353 return NULL; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
354 else |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
355 return p->value; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
356 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
357 |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
358 /* Forget the current thread's association for key, if any. */ |
|
33699
0c26db381673
Style guide & consistency changes. No semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
33145
diff
changeset
|
359 void |
|
0c26db381673
Style guide & consistency changes. No semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
33145
diff
changeset
|
360 PyThread_delete_key_value(int key) |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
361 { |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
362 long id = PyThread_get_thread_ident(); |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
363 struct key *p, **q; |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
364 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
365 PyThread_acquire_lock(keymutex, 1); |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
366 q = &keyhead; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
367 while ((p = *q) != NULL) { |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
368 if (p->key == key && p->id == id) { |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
369 *q = p->next; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
370 free((void *)p); |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
371 /* NB This does *not* free p->value! */ |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
372 break; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
373 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
374 else |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
375 q = &p->next; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
376 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
377 PyThread_release_lock(keymutex); |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
378 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
379 |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
380 #endif /* Py_HAVE_NATIVE_TLS */ |
