Mercurial > cpython-lru_cache-weakref
annotate Python/thread.c @ 40582:67287ca4e1e8
Merged revisions 53005-53303 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r53012 | walter.doerwald | 2006-12-12 22:55:31 +0100 (Tue, 12 Dec 2006) | 2 lines
Fix typo.
........
r53023 | brett.cannon | 2006-12-13 23:31:37 +0100 (Wed, 13 Dec 2006) | 2 lines
Remove an unneeded import of 'warnings'.
........
r53025 | brett.cannon | 2006-12-14 00:02:38 +0100 (Thu, 14 Dec 2006) | 2 lines
Remove unneeded imports of 'warnings'.
........
r53026 | brett.cannon | 2006-12-14 00:09:53 +0100 (Thu, 14 Dec 2006) | 4 lines
Add test.test_support.guard_warnings_filter . This function returns a context
manager that protects warnings.filter from being modified once the context is
exited.
........
r53029 | george.yoshida | 2006-12-14 03:22:44 +0100 (Thu, 14 Dec 2006) | 2 lines
Note that guard_warnings_filter was added in 2.6
........
r53031 | vinay.sajip | 2006-12-14 09:53:55 +0100 (Thu, 14 Dec 2006) | 1 line
Added news on recent changes to logging
........
r53032 | andrew.kuchling | 2006-12-14 19:57:53 +0100 (Thu, 14 Dec 2006) | 1 line
[Patch #1599256 from David Watson] check that os.fsync is available before using it
........
r53042 | kurt.kaiser | 2006-12-15 06:13:11 +0100 (Fri, 15 Dec 2006) | 6 lines
1. Avoid hang when encountering a duplicate in a completion list. Bug 1571112.
2. Duplicate some old entries from Python's NEWS to IDLE's NEWS.txt
M AutoCompleteWindow.py
M NEWS.txt
........
r53048 | andrew.kuchling | 2006-12-18 18:12:31 +0100 (Mon, 18 Dec 2006) | 1 line
[Bug #1618083] Add missing word; make a few grammar fixes
........
r53050 | andrew.kuchling | 2006-12-18 18:16:05 +0100 (Mon, 18 Dec 2006) | 1 line
Bump version
........
r53051 | andrew.kuchling | 2006-12-18 18:22:07 +0100 (Mon, 18 Dec 2006) | 1 line
[Bug #1616726] Fix description of generator.close(); if you raise some random exception, the exception is raised and doesn't trigger a RuntimeError
........
r53052 | andrew.kuchling | 2006-12-18 18:38:14 +0100 (Mon, 18 Dec 2006) | 1 line
Describe new methods in Queue module
........
r53053 | andrew.kuchling | 2006-12-18 20:22:24 +0100 (Mon, 18 Dec 2006) | 1 line
[Patch #1615868 by Lars Gustaebel] Use Py_off_t to fix BZ2File.seek() for offsets > 2Gb
........
r53057 | andrew.kuchling | 2006-12-18 22:29:07 +0100 (Mon, 18 Dec 2006) | 1 line
Fix markup
........
r53063 | thomas.wouters | 2006-12-19 09:17:50 +0100 (Tue, 19 Dec 2006) | 5 lines
Make sre's SubPattern objects accept slice objects like it already accepts
simple slices.
........
r53065 | andrew.kuchling | 2006-12-19 15:13:05 +0100 (Tue, 19 Dec 2006) | 6 lines
[Patch #1618455 by Ben Maurer] Improve speed of HMAC by using str.translate()
instead of a more general XOR that has to construct a list.
Slightly modified from Maurer's patch: the _strxor() function is no longer
necessary at all.
........
r53066 | andrew.kuchling | 2006-12-19 15:28:23 +0100 (Tue, 19 Dec 2006) | 9 lines
[Bug #1613651] Document socket.recv_into, socket.recvfrom_into
Also, the text for recvfrom told you to read recv() for an explanation of the
'flags' argument, but recv() just pointed you at the man page. Copied the
man-page text to recvfrom(), recvfrom_into, recv_into to avoid the pointless
redirection.
I don't have LaTeX on this machine; hope my markup is OK.
........
r53067 | andrew.kuchling | 2006-12-19 15:29:04 +0100 (Tue, 19 Dec 2006) | 1 line
Comment typo
........
r53068 | andrew.kuchling | 2006-12-19 16:11:41 +0100 (Tue, 19 Dec 2006) | 1 line
[Patch #1617413 from Dug Song] Fix HTTP Basic authentication via HTTPS
........
r53071 | andrew.kuchling | 2006-12-19 16:18:12 +0100 (Tue, 19 Dec 2006) | 1 line
[Patch #1600491 from Jim Jewett] Describe how to build help files on Windows
........
r53073 | andrew.kuchling | 2006-12-19 16:43:10 +0100 (Tue, 19 Dec 2006) | 6 lines
[Patch #1587139 by kxroberto] Protect lock acquisition/release with
try...finally to ensure the lock is always released. This could use
the 'with' statement, but the patch uses 'finally'.
2.5 backport candidate.
........
r53074 | vinay.sajip | 2006-12-19 19:29:11 +0100 (Tue, 19 Dec 2006) | 1 line
Updated documentation for findCaller() to indicate that a 3-tuple is now returned, rather than a 2-tuple.
........
r53090 | georg.brandl | 2006-12-19 23:06:46 +0100 (Tue, 19 Dec 2006) | 3 lines
Patch #1484695: The tarfile module now raises a HeaderError exception
if a buffer given to frombuf() is invalid.
........
r53099 | raymond.hettinger | 2006-12-20 07:42:06 +0100 (Wed, 20 Dec 2006) | 5 lines
Bug #1590891: random.randrange don't return correct value for big number
Needs to be backported.
........
r53106 | georg.brandl | 2006-12-20 12:55:16 +0100 (Wed, 20 Dec 2006) | 3 lines
Testcase for patch #1484695.
........
r53110 | andrew.kuchling | 2006-12-20 20:48:20 +0100 (Wed, 20 Dec 2006) | 17 lines
[Apply length-checking.diff from bug #1599254]
Add length checking to single-file mailbox formats: before doing a
flush() on a mailbox, seek to the end and verify its length is
unchanged, raising ExternalClashError if the file's length has
changed.
This fix avoids potential data loss if some other process appends to
the mailbox file after the table of contents has been generated;
instead of overwriting the modified file, you'll get the exception.
I also noticed that the self._lookup() call in self.flush() wasn't
necessary (everything that sets self._pending to True also calls
self.lookup()), and replaced it by an assertion.
2.5 backport candidate.
........
r53112 | andrew.kuchling | 2006-12-20 20:57:10 +0100 (Wed, 20 Dec 2006) | 1 line
[Bug #1619674] Make sum() use the term iterable, not sequence
........
r53113 | andrew.kuchling | 2006-12-20 20:58:11 +0100 (Wed, 20 Dec 2006) | 1 line
Two grammar fixes
........
r53115 | andrew.kuchling | 2006-12-20 21:11:12 +0100 (Wed, 20 Dec 2006) | 5 lines
Some other built-in functions are described with 'sequence' arguments
that should really be 'iterable'; this commit changes them.
Did I miss any? Did I introduce any errors?
........
r53117 | andrew.kuchling | 2006-12-20 21:20:42 +0100 (Wed, 20 Dec 2006) | 1 line
[Bug #1619680] in_dll() arguments are documented in the wrong order
........
r53120 | neal.norwitz | 2006-12-21 05:38:00 +0100 (Thu, 21 Dec 2006) | 1 line
Lars asked for permission on on python-dev for work on tarfile.py
........
r53125 | andrew.kuchling | 2006-12-21 14:40:29 +0100 (Thu, 21 Dec 2006) | 1 line
Mention the os.SEEK_* constants
........
r53129 | walter.doerwald | 2006-12-21 19:06:30 +0100 (Thu, 21 Dec 2006) | 2 lines
Fix typo.
........
r53131 | thomas.heller | 2006-12-21 19:30:56 +0100 (Thu, 21 Dec 2006) | 3 lines
Fix wrong markup of an argument in a method signature.
Will backport.
........
r53137 | andrew.kuchling | 2006-12-22 01:50:56 +0100 (Fri, 22 Dec 2006) | 1 line
Typo fix
........
r53139 | andrew.kuchling | 2006-12-22 14:25:02 +0100 (Fri, 22 Dec 2006) | 1 line
[Bug #737202; fix from Titus Brown] Make CGIHTTPServer work for scripts in sub-directories
........
r53141 | andrew.kuchling | 2006-12-22 16:04:45 +0100 (Fri, 22 Dec 2006) | 6 lines
[Bug #802128] Make the mode argument of dumbdbm actually work the way it's
described, and add a test for it.
2.5 bugfix candidate, maybe; arguably this patch changes the API of
dumbdbm and shouldn't be added in a point-release.
........
r53142 | andrew.kuchling | 2006-12-22 16:16:58 +0100 (Fri, 22 Dec 2006) | 6 lines
[Bug #802128 continued] Modify mode depending on the process umask.
Is there really no other way to read the umask than to set it?
Hope this works on Windows...
........
r53145 | andrew.kuchling | 2006-12-22 17:43:26 +0100 (Fri, 22 Dec 2006) | 1 line
[Bug #776202] Apply Walter Doerwald's patch to use text mode for encoded files
........
r53146 | andrew.kuchling | 2006-12-22 19:41:42 +0100 (Fri, 22 Dec 2006) | 9 lines
[Patch #783050 from Patrick Lynch] The emulation of forkpty() is incorrect;
the master should close the slave fd.
Added a test to test_pty.py that reads from the master_fd after doing
a pty.fork(); without the fix it hangs forever instead of raising an
exception. (<crossing fingers for the buildbots>)
2.5 backport candidate.
........
r53147 | andrew.kuchling | 2006-12-22 20:06:16 +0100 (Fri, 22 Dec 2006) | 1 line
[Patch #827559 from Chris Gonnerman] Make SimpleHTTPServer redirect when a directory URL is missing the trailing slash; this lets relative links work.
........
r53149 | andrew.kuchling | 2006-12-22 20:21:27 +0100 (Fri, 22 Dec 2006) | 1 line
Darn; this test works when you run test_pty.py directly, but fails when regrtest runs it (the os.read() raises os.error). I can't figure out the cause, so am commenting out the test.
........
r53150 | andrew.kuchling | 2006-12-22 22:48:19 +0100 (Fri, 22 Dec 2006) | 1 line
Frak; this test also fails
........
r53153 | lars.gustaebel | 2006-12-23 17:40:13 +0100 (Sat, 23 Dec 2006) | 5 lines
Patch #1230446: tarfile.py: fix ExFileObject so that read() and tell()
work correctly together with readline().
Will backport to 2.5.
........
r53155 | lars.gustaebel | 2006-12-23 18:57:23 +0100 (Sat, 23 Dec 2006) | 5 lines
Patch #1262036: Prevent TarFiles from being added to themselves under
certain conditions.
Will backport to 2.5.
........
r53159 | andrew.kuchling | 2006-12-27 04:25:31 +0100 (Wed, 27 Dec 2006) | 4 lines
[Part of patch #1182394] Move the HMAC blocksize to be a class-level
constant; this allows changing it in a subclass. To accommodate this,
copy() now uses __class__. Also add some text to a comment.
........
r53160 | andrew.kuchling | 2006-12-27 04:31:24 +0100 (Wed, 27 Dec 2006) | 1 line
[Rest of patch #1182394] Add ._current() method so that we can use the written-in-C .hexdigest() method
........
r53161 | lars.gustaebel | 2006-12-27 11:30:46 +0100 (Wed, 27 Dec 2006) | 4 lines
Patch #1504073: Fix tarfile.open() for mode "r" with a fileobj argument.
Will backport to 2.5.
........
r53165 | neal.norwitz | 2006-12-28 05:39:20 +0100 (Thu, 28 Dec 2006) | 1 line
Remove a stray (old) macro name left around (I guess)
........
r53188 | neal.norwitz | 2006-12-29 04:01:53 +0100 (Fri, 29 Dec 2006) | 1 line
SF bug #1623890, fix argument name in docstring
........
r53200 | raymond.hettinger | 2006-12-30 05:01:17 +0100 (Sat, 30 Dec 2006) | 1 line
For sets with cyclical reprs, emit an ellipsis instead of infinitely recursing.
........
r53232 | brett.cannon | 2007-01-04 01:23:49 +0100 (Thu, 04 Jan 2007) | 3 lines
Add EnvironmentVarGuard to test.test_support. Provides a context manager to
temporarily set or unset environment variables.
........
r53235 | neal.norwitz | 2007-01-04 07:25:31 +0100 (Thu, 04 Jan 2007) | 1 line
SF #1627373, fix typo in CarbonEvt.
........
r53244 | raymond.hettinger | 2007-01-04 18:53:34 +0100 (Thu, 04 Jan 2007) | 1 line
Fix stability of heapq's nlargest() and nsmallest().
........
r53249 | martin.v.loewis | 2007-01-04 22:06:12 +0100 (Thu, 04 Jan 2007) | 3 lines
Bug #1566280: Explicitly invoke threading._shutdown from Py_Main,
to avoid relying on atexit.
Will backport to 2.5.
........
r53252 | gregory.p.smith | 2007-01-05 02:59:42 +0100 (Fri, 05 Jan 2007) | 3 lines
Support linking of the bsddb module against BerkeleyDB 4.5.x
(will backport to 2.5)
........
r53253 | gregory.p.smith | 2007-01-05 03:06:17 +0100 (Fri, 05 Jan 2007) | 2 lines
bump module version to match supported berkeleydb version
........
r53255 | neal.norwitz | 2007-01-05 06:25:22 +0100 (Fri, 05 Jan 2007) | 6 lines
Prevent crash on shutdown which can occur if we are finalizing
and the module dict has been cleared already and some object
raises a warning (like in a __del__).
Will backport.
........
r53258 | gregory.p.smith | 2007-01-05 08:21:35 +0100 (Fri, 05 Jan 2007) | 2 lines
typo fix
........
r53260 | neal.norwitz | 2007-01-05 09:06:43 +0100 (Fri, 05 Jan 2007) | 1 line
Add Collin Winter for access to update PEP 3107
........
r53262 | andrew.kuchling | 2007-01-05 15:22:17 +0100 (Fri, 05 Jan 2007) | 1 line
[Bug #1622533] Make docstrings raw strings because they contain control characters (\0, \1)
........
r53264 | andrew.kuchling | 2007-01-05 16:51:24 +0100 (Fri, 05 Jan 2007) | 1 line
[Patch #1520904] Fix bsddb tests to write to the temp directory instead of the Lib/bsddb/test directory
........
r53279 | brett.cannon | 2007-01-05 22:45:09 +0100 (Fri, 05 Jan 2007) | 3 lines
Silence a warning from gcc 4.0.1 by specifying a function's parameter list is
'void' instead of just a set of empty parentheses.
........
r53285 | raymond.hettinger | 2007-01-06 02:14:41 +0100 (Sat, 06 Jan 2007) | 2 lines
SF# 1409443: Expand comment to cover the interaction between f->f_lasti and the PREDICT macros.
........
r53286 | anthony.baxter | 2007-01-06 05:45:54 +0100 (Sat, 06 Jan 2007) | 1 line
update to (c) years to include 2007
........
r53291 | neal.norwitz | 2007-01-06 22:24:35 +0100 (Sat, 06 Jan 2007) | 1 line
Add Josiah to SF for maintaining asyncore/asynchat
........
r53293 | peter.astrand | 2007-01-07 09:53:46 +0100 (Sun, 07 Jan 2007) | 1 line
Re-implemented fix for #1531862 once again, in a way that works with Python 2.2. Fixes bug #1603424.
........
r53295 | peter.astrand | 2007-01-07 15:34:16 +0100 (Sun, 07 Jan 2007) | 1 line
Avoid O(N**2) bottleneck in _communicate_(). Fixes #1598181.
........
r53300 | raymond.hettinger | 2007-01-08 19:09:20 +0100 (Mon, 08 Jan 2007) | 1 line
Fix zero-length corner case for iterating over a mutating deque.
........
r53301 | vinay.sajip | 2007-01-08 19:50:32 +0100 (Mon, 08 Jan 2007) | 4 lines
Bare except clause removed from SMTPHandler.emit(). Now, only ImportError is trapped.
Bare except clause removed from SocketHandler.createSocket(). Now, only socket.error is trapped.
(SF #411881)
........
r53302 | vinay.sajip | 2007-01-08 19:51:46 +0100 (Mon, 08 Jan 2007) | 2 lines
Bare except clause removed from LogRecord.__init__. Now, only ValueError, TypeError and AttributeError are trapped.
(SF #411881)
........
r53303 | vinay.sajip | 2007-01-08 19:52:36 +0100 (Mon, 08 Jan 2007) | 1 line
Added entries about removal of some bare except clauses from logging.
........
| author | Thomas Wouters <thomas@python.org> |
|---|---|
| date | Tue, 09 Jan 2007 23:18:33 +0000 |
| parents | 654c380cf8b9 |
| children | a5e984eda45a |
| 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 |
| 1418 | 82 char *p = getenv("THREADDEBUG"); |
| 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 |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
136 #ifdef BEOS_THREADS |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
137 #include "thread_beos.h" |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
138 #endif |
|
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
139 |
|
10530
d834ecdf8c26
Changes by Mark Hammond for Windows CE. Mostly of the form
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
140 #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
|
141 #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
|
142 #endif |
|
d834ecdf8c26
Changes by Mark Hammond for Windows CE. Mostly of the form
Guido van Rossum <guido@python.org>
parents:
9679
diff
changeset
|
143 |
|
22206
b898c0feb754
Patch #504224: add plan9 threads include to thread.c.
Martin v. Löwis <martin@v.loewis.de>
parents:
21712
diff
changeset
|
144 #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
|
145 #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
|
146 #endif |
|
b898c0feb754
Patch #504224: add plan9 threads include to thread.c.
Martin v. Löwis <martin@v.loewis.de>
parents:
21712
diff
changeset
|
147 |
|
23777
bec1b942e0bc
Patch #488073: AtheOS port.
Martin v. Löwis <martin@v.loewis.de>
parents:
22509
diff
changeset
|
148 #ifdef ATHEOS_THREADS |
|
bec1b942e0bc
Patch #488073: AtheOS port.
Martin v. Löwis <martin@v.loewis.de>
parents:
22509
diff
changeset
|
149 #include "thread_atheos.h" |
|
bec1b942e0bc
Patch #488073: AtheOS port.
Martin v. Löwis <martin@v.loewis.de>
parents:
22509
diff
changeset
|
150 #endif |
|
bec1b942e0bc
Patch #488073: AtheOS port.
Martin v. Löwis <martin@v.loewis.de>
parents:
22509
diff
changeset
|
151 |
|
961
a31e07847063
New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
152 /* |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
153 #ifdef FOOBAR_THREADS |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
154 #include "thread_foobar.h" |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
155 #endif |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1418
diff
changeset
|
156 */ |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
157 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
158 /* return the current thread stack size */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
159 size_t |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
160 PyThread_get_stacksize(void) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
161 { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
162 return _pythread_stacksize; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
163 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
164 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
165 /* 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
|
166 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
|
167 Return 0 if stack size is valid, |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
168 -1 if stack size value is invalid, |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
169 -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
|
170 int |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
171 PyThread_set_stacksize(size_t size) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
172 { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
173 #if defined(THREAD_SET_STACKSIZE) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
174 return THREAD_SET_STACKSIZE(size); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
175 #else |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
176 return -2; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
177 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
178 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
179 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
180 #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
|
181 /* 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
|
182 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
|
183 |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
184 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
|
185 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
|
186 */ |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
187 /* ------------------------------------------------------------------------ |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
188 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
|
189 |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
190 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
|
191 across threads. |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
192 |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
193 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
|
194 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
|
195 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
|
196 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
|
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_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
|
199 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
|
200 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
|
201 |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
202 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
|
203 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
|
204 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
|
205 |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
206 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
|
207 Python exception. |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
208 |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
209 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
|
210 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
|
211 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
|
212 them either. |
|
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 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
|
215 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
|
216 next paragraph). |
|
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 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
|
219 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
|
220 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
|
221 ------------------------------------------------------------------------ */ |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
222 |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
223 /* 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
|
224 * 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
|
225 * 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
|
226 */ |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
227 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
|
228 /* 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
|
229 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
|
230 |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
231 /* 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
|
232 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
|
233 |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
234 /* 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
|
235 int key; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
236 void *value; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
237 }; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
238 |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
239 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
|
240 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
|
241 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
|
242 |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
243 /* Internal helper. |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
244 * 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
|
245 * 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
|
246 * 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
|
247 * 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
|
248 * 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
|
249 * 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
|
250 * 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
|
251 * 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
|
252 * 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
|
253 * 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
|
254 * |
|
baa2653f7a76
find_key(): This routine wasn't thread-correct, and accounts for the
Tim Peters <tim.peters@gmail.com>
parents:
33705
diff
changeset
|
255 * 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
|
256 * 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
|
257 * 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
|
258 * 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
|
259 * 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
|
260 * 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
|
261 * 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
|
262 * 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
|
263 */ |
|
33699
0c26db381673
Style guide & consistency changes. No semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
33145
diff
changeset
|
264 static struct key * |
|
0c26db381673
Style guide & consistency changes. No semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
33145
diff
changeset
|
265 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
|
266 { |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
267 struct key *p; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
268 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
|
269 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
270 if (!keymutex) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
271 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
|
272 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
|
273 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
|
274 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
|
275 goto Done; |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
276 } |
|
33712
baa2653f7a76
find_key(): This routine wasn't thread-correct, and accounts for the
Tim Peters <tim.peters@gmail.com>
parents:
33705
diff
changeset
|
277 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
|
278 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
|
279 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
|
280 } |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
281 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
|
282 if (p != NULL) { |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
283 p->id = id; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
284 p->key = key; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
285 p->value = value; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
286 p->next = keyhead; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
287 keyhead = p; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
288 } |
|
33712
baa2653f7a76
find_key(): This routine wasn't thread-correct, and accounts for the
Tim Peters <tim.peters@gmail.com>
parents:
33705
diff
changeset
|
289 Done: |
|
baa2653f7a76
find_key(): This routine wasn't thread-correct, and accounts for the
Tim Peters <tim.peters@gmail.com>
parents:
33705
diff
changeset
|
290 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
|
291 return p; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
292 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
293 |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
294 /* 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
|
295 * 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
|
296 * 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
|
297 */ |
|
33699
0c26db381673
Style guide & consistency changes. No semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
33145
diff
changeset
|
298 int |
|
0c26db381673
Style guide & consistency changes. No semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
33145
diff
changeset
|
299 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
|
300 { |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
301 /* 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
|
302 * threads simultaneously. |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
303 */ |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
304 if (keymutex == NULL) |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
305 keymutex = PyThread_allocate_lock(); |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
306 return ++nkeys; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
307 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
308 |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
309 /* 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
|
310 void |
|
0c26db381673
Style guide & consistency changes. No semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
33145
diff
changeset
|
311 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
|
312 { |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
313 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
|
314 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
315 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
|
316 q = &keyhead; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
317 while ((p = *q) != NULL) { |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
318 if (p->key == key) { |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
319 *q = p->next; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
320 free((void *)p); |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
321 /* 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
|
322 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
323 else |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
324 q = &p->next; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
325 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
326 PyThread_release_lock(keymutex); |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
327 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
328 |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
329 /* 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
|
330 * 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
|
331 * 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
|
332 * 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
|
333 * 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
|
334 */ |
|
33699
0c26db381673
Style guide & consistency changes. No semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
33145
diff
changeset
|
335 int |
|
0c26db381673
Style guide & consistency changes. No semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
33145
diff
changeset
|
336 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
|
337 { |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
338 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
|
339 |
|
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
340 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
|
341 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
|
342 if (p == NULL) |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
343 return -1; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
344 else |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
345 return 0; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
346 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
347 |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
348 /* 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
|
349 * 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
|
350 */ |
|
33699
0c26db381673
Style guide & consistency changes. No semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
33145
diff
changeset
|
351 void * |
|
0c26db381673
Style guide & consistency changes. No semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
33145
diff
changeset
|
352 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
|
353 { |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
354 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
|
355 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
356 if (p == NULL) |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
357 return NULL; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
358 else |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
359 return p->value; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
360 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
361 |
|
33705
891042c94aed
Document the results of painful reverse-engineering of the "portable TLS"
Tim Peters <tim.peters@gmail.com>
parents:
33699
diff
changeset
|
362 /* 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
|
363 void |
|
0c26db381673
Style guide & consistency changes. No semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
33145
diff
changeset
|
364 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
|
365 { |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
366 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
|
367 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
|
368 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
369 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
|
370 q = &keyhead; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
371 while ((p = *q) != NULL) { |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
372 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
|
373 *q = p->next; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
374 free((void *)p); |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
375 /* 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
|
376 break; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
377 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
378 else |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
379 q = &p->next; |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
380 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
381 PyThread_release_lock(keymutex); |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
382 } |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
383 |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24315
diff
changeset
|
384 #endif /* Py_HAVE_NATIVE_TLS */ |
