Mercurial > cpython-lru_cache-weakref
annotate Python/thread_pthread.h @ 48499:de0bf60f1245
Merged revisions 64722,64729,64753,64845-64846,64849,64871,64880-64882,64885,64888,64897,64900-64901,64915,64926-64929,64938-64941,64944,64961,64966,64973 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r64722 | georg.brandl | 2008-07-05 12:13:36 +0200 (Sat, 05 Jul 2008) | 4 lines
#2663: support an *ignore* argument to shutil.copytree(). Patch by Tarek Ziade.
This is a new feature, but Barry authorized adding it in the beta period.
........
r64729 | mark.dickinson | 2008-07-05 13:33:52 +0200 (Sat, 05 Jul 2008) | 5 lines
Issue 3188: accept float('infinity') as well as float('inf'). This
makes the float constructor behave in the same way as specified
by various other language standards, including C99, IEEE 754r,
and the IBM Decimal standard.
........
r64753 | gregory.p.smith | 2008-07-06 05:35:58 +0200 (Sun, 06 Jul 2008) | 4 lines
- Issue #2862: Make int and float freelist management consistent with other
freelists. Changes their CompactFreeList apis into ClearFreeList apis and
calls them via gc.collect().
........
r64845 | raymond.hettinger | 2008-07-10 16:03:19 +0200 (Thu, 10 Jul 2008) | 1 line
Issue 3301: Bisect functions behaved badly when lo was negative.
........
r64846 | raymond.hettinger | 2008-07-10 16:34:57 +0200 (Thu, 10 Jul 2008) | 1 line
Issue 3285: Fractions from_float() and from_decimal() accept Integral arguments.
........
r64849 | andrew.kuchling | 2008-07-10 16:43:31 +0200 (Thu, 10 Jul 2008) | 1 line
Wording changes
........
r64871 | raymond.hettinger | 2008-07-11 14:00:21 +0200 (Fri, 11 Jul 2008) | 1 line
Add cautionary note on the use of PySequence_Fast_ITEMS.
........
r64880 | amaury.forgeotdarc | 2008-07-11 23:28:25 +0200 (Fri, 11 Jul 2008) | 5 lines
#3317 in zipfile module, restore the previous names of global variables:
some applications relied on them.
Also remove duplicated lines.
........
r64881 | amaury.forgeotdarc | 2008-07-11 23:45:06 +0200 (Fri, 11 Jul 2008) | 3 lines
#3342: In tracebacks, printed source lines were not indented since r62555.
#3343: Py_DisplaySourceLine should be a private function. Rename it to _Py_DisplaySourceLine.
........
r64882 | josiah.carlson | 2008-07-12 00:17:14 +0200 (Sat, 12 Jul 2008) | 2 lines
Fix for the AttributeError in test_asynchat.
........
r64885 | josiah.carlson | 2008-07-12 01:26:59 +0200 (Sat, 12 Jul 2008) | 2 lines
Fixed test for asyncore.
........
r64888 | matthias.klose | 2008-07-12 09:51:48 +0200 (Sat, 12 Jul 2008) | 2 lines
- Fix bashisms in Tools/faqwiz/move-faqwiz.sh
........
r64897 | benjamin.peterson | 2008-07-12 22:16:19 +0200 (Sat, 12 Jul 2008) | 1 line
fix various doc typos #3320
........
r64900 | alexandre.vassalotti | 2008-07-13 00:06:53 +0200 (Sun, 13 Jul 2008) | 2 lines
Fixed typo.
........
r64901 | benjamin.peterson | 2008-07-13 01:41:19 +0200 (Sun, 13 Jul 2008) | 1 line
#1778443 robotparser fixes from Aristotelis Mikropoulos
........
r64915 | nick.coghlan | 2008-07-13 16:52:36 +0200 (Sun, 13 Jul 2008) | 1 line
Fix issue 3221 by emitting a RuntimeWarning instead of raising SystemError when the parent module can't be found during an absolute import (likely due to non-PEP 361 aware code which sets a module level __package__ attribute)
........
r64926 | martin.v.loewis | 2008-07-13 22:31:49 +0200 (Sun, 13 Jul 2008) | 2 lines
Add turtle into the module index.
........
r64927 | alexandre.vassalotti | 2008-07-13 22:42:44 +0200 (Sun, 13 Jul 2008) | 3 lines
Issue #3274: Use a less common identifier for the temporary variable
in Py_CLEAR().
........
r64928 | andrew.kuchling | 2008-07-13 23:43:25 +0200 (Sun, 13 Jul 2008) | 1 line
Re-word
........
r64929 | andrew.kuchling | 2008-07-13 23:43:52 +0200 (Sun, 13 Jul 2008) | 1 line
Add various items; move ctypes items into a subsection of their own
........
r64938 | andrew.kuchling | 2008-07-14 02:35:32 +0200 (Mon, 14 Jul 2008) | 1 line
Typo fixes
........
r64939 | andrew.kuchling | 2008-07-14 02:40:55 +0200 (Mon, 14 Jul 2008) | 1 line
Typo fix
........
r64940 | andrew.kuchling | 2008-07-14 03:18:16 +0200 (Mon, 14 Jul 2008) | 1 line
Typo fix
........
r64941 | andrew.kuchling | 2008-07-14 03:18:31 +0200 (Mon, 14 Jul 2008) | 1 line
Expand the multiprocessing section
........
r64944 | gregory.p.smith | 2008-07-14 08:06:48 +0200 (Mon, 14 Jul 2008) | 7 lines
Fix posix.fork1() / os.fork1() to only call PyOS_AfterFork() in the child
process rather than both parent and child.
Does anyone actually use fork1()? It appears to be a Solaris thing
but if Python is built with pthreads on Solaris, fork1() and fork()
should be the same.
........
r64961 | jesse.noller | 2008-07-15 15:47:33 +0200 (Tue, 15 Jul 2008) | 1 line
multiprocessing/connection.py patch to remove fqdn oddness for issue 3270
........
r64966 | nick.coghlan | 2008-07-15 17:40:22 +0200 (Tue, 15 Jul 2008) | 1 line
Add missing NEWS entry for r64962
........
r64973 | jesse.noller | 2008-07-15 20:29:18 +0200 (Tue, 15 Jul 2008) | 1 line
Revert 3270 patch: self._address is in pretty widespread use, need to revisit
........
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Wed, 16 Jul 2008 12:55:28 +0000 |
| parents | 654c380cf8b9 |
| children | f197407bdba2 798e0d0c7246 |
| rev | line source |
|---|---|
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 |
|
3663
07164d30429d
Got rid of florida hack and made it work with Solaris 2.5 pthreads.
Guido van Rossum <guido@python.org>
parents:
2097
diff
changeset
|
2 /* Posix threads interface */ |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 |
|
3663
07164d30429d
Got rid of florida hack and made it work with Solaris 2.5 pthreads.
Guido van Rossum <guido@python.org>
parents:
2097
diff
changeset
|
4 #include <stdlib.h> |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
5 #include <string.h> |
|
25545
3731be28e1a3
Patch #618347: Work around Solaris 2.6 pthread.h bug. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
22341
diff
changeset
|
6 #if defined(__APPLE__) || defined(HAVE_PTHREAD_DESTRUCTOR) |
|
21724
884e57bf3ada
Workaround for what is probably a problem in Apple's gcc: <pthread.h> fails
Jack Jansen <jack.jansen@cwi.nl>
parents:
20922
diff
changeset
|
7 #define destructor xxdestructor |
|
884e57bf3ada
Workaround for what is probably a problem in Apple's gcc: <pthread.h> fails
Jack Jansen <jack.jansen@cwi.nl>
parents:
20922
diff
changeset
|
8 #endif |
|
3663
07164d30429d
Got rid of florida hack and made it work with Solaris 2.5 pthreads.
Guido van Rossum <guido@python.org>
parents:
2097
diff
changeset
|
9 #include <pthread.h> |
|
25545
3731be28e1a3
Patch #618347: Work around Solaris 2.6 pthread.h bug. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
22341
diff
changeset
|
10 #if defined(__APPLE__) || defined(HAVE_PTHREAD_DESTRUCTOR) |
|
21724
884e57bf3ada
Workaround for what is probably a problem in Apple's gcc: <pthread.h> fails
Jack Jansen <jack.jansen@cwi.nl>
parents:
20922
diff
changeset
|
11 #undef destructor |
|
884e57bf3ada
Workaround for what is probably a problem in Apple's gcc: <pthread.h> fails
Jack Jansen <jack.jansen@cwi.nl>
parents:
20922
diff
changeset
|
12 #endif |
|
20398
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
13 #include <signal.h> |
|
22341
2548e2f323fa
Document that _POSIX_SEMAPHORES is predefined.
Martin v. Löwis <martin@v.loewis.de>
parents:
22339
diff
changeset
|
14 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
15 /* The POSIX spec requires that use of pthread_attr_setstacksize |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
16 be conditional on _POSIX_THREAD_ATTR_STACKSIZE being defined. */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
17 #ifdef _POSIX_THREAD_ATTR_STACKSIZE |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
18 #ifndef THREAD_STACK_SIZE |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
19 #define THREAD_STACK_SIZE 0 /* use default stack size */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
20 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
21 /* for safety, ensure a viable minimum stacksize */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
22 #define THREAD_STACK_MIN 0x8000 /* 32kB */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
23 #else /* !_POSIX_THREAD_ATTR_STACKSIZE */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
24 #ifdef THREAD_STACK_SIZE |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
25 #error "THREAD_STACK_SIZE defined but _POSIX_THREAD_ATTR_STACKSIZE undefined" |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
26 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
27 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
28 |
|
22341
2548e2f323fa
Document that _POSIX_SEMAPHORES is predefined.
Martin v. Löwis <martin@v.loewis.de>
parents:
22339
diff
changeset
|
29 /* The POSIX spec says that implementations supporting the sem_* |
|
2548e2f323fa
Document that _POSIX_SEMAPHORES is predefined.
Martin v. Löwis <martin@v.loewis.de>
parents:
22339
diff
changeset
|
30 family of functions must indicate this by defining |
|
2548e2f323fa
Document that _POSIX_SEMAPHORES is predefined.
Martin v. Löwis <martin@v.loewis.de>
parents:
22339
diff
changeset
|
31 _POSIX_SEMAPHORES. */ |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
32 #ifdef _POSIX_SEMAPHORES |
|
34824
a50ffe65911b
Add 0 to _POSIX_SEMAPHORES.
Martin v. Löwis <martin@v.loewis.de>
parents:
34762
diff
changeset
|
33 /* On FreeBSD 4.x, _POSIX_SEMAPHORES is defined empty, so |
|
a50ffe65911b
Add 0 to _POSIX_SEMAPHORES.
Martin v. Löwis <martin@v.loewis.de>
parents:
34762
diff
changeset
|
34 we need to add 0 to make it work there as well. */ |
|
a50ffe65911b
Add 0 to _POSIX_SEMAPHORES.
Martin v. Löwis <martin@v.loewis.de>
parents:
34762
diff
changeset
|
35 #if (_POSIX_SEMAPHORES+0) == -1 |
|
34762
fcb507414c41
Patch #1163249 - Correctly handle _POSIX_SEMAPHORES == -1 to mean no
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32526
diff
changeset
|
36 #define HAVE_BROKEN_POSIX_SEMAPHORES |
|
fcb507414c41
Patch #1163249 - Correctly handle _POSIX_SEMAPHORES == -1 to mean no
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32526
diff
changeset
|
37 #else |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
38 #include <semaphore.h> |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
39 #include <errno.h> |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
40 #endif |
|
34762
fcb507414c41
Patch #1163249 - Correctly handle _POSIX_SEMAPHORES == -1 to mean no
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32526
diff
changeset
|
41 #endif |
|
3663
07164d30429d
Got rid of florida hack and made it work with Solaris 2.5 pthreads.
Guido van Rossum <guido@python.org>
parents:
2097
diff
changeset
|
42 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35607
diff
changeset
|
43 /* Before FreeBSD 5.4, system scope threads was very limited resource |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35607
diff
changeset
|
44 in default setting. So the process scope is preferred to get |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35607
diff
changeset
|
45 enough number of threads to work. */ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35607
diff
changeset
|
46 #ifdef __FreeBSD__ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35607
diff
changeset
|
47 #include <osreldate.h> |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35607
diff
changeset
|
48 #if __FreeBSD_version >= 500000 && __FreeBSD_version < 504101 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35607
diff
changeset
|
49 #undef PTHREAD_SYSTEM_SCHED_SUPPORTED |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35607
diff
changeset
|
50 #endif |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35607
diff
changeset
|
51 #endif |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35607
diff
changeset
|
52 |
|
26598
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
53 #if !defined(pthread_attr_default) |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
54 # define pthread_attr_default ((pthread_attr_t *)NULL) |
|
26598
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
55 #endif |
|
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
56 #if !defined(pthread_mutexattr_default) |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
57 # define pthread_mutexattr_default ((pthread_mutexattr_t *)NULL) |
|
26598
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
58 #endif |
|
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
59 #if !defined(pthread_condattr_default) |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
60 # define pthread_condattr_default ((pthread_condattr_t *)NULL) |
|
3965
9c05ff6fb0a4
Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents:
3663
diff
changeset
|
61 #endif |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
63 |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
64 /* Whether or not to use semaphores directly rather than emulating them with |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
65 * mutexes and condition variables: |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
66 */ |
|
27320
1562c1e10b49
Don't use Posix semaphores on Solaris 8. Fixes #662787.
Martin v. Löwis <martin@v.loewis.de>
parents:
26598
diff
changeset
|
67 #if defined(_POSIX_SEMAPHORES) && !defined(HAVE_BROKEN_POSIX_SEMAPHORES) |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
68 # define USE_SEMAPHORES |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
69 #else |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
70 # undef USE_SEMAPHORES |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
71 #endif |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
72 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
73 |
|
20398
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
74 /* On platforms that don't use standard POSIX threads pthread_sigmask() |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
75 * isn't present. DEC threads uses sigprocmask() instead as do most |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
76 * other UNIX International compliant systems that don't have the full |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
77 * pthread implementation. |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
78 */ |
|
29972
a408ac5527c3
Patch 775605: Cygwin pthread_sigmask() workaround patch
Jason Tishler <jason@tishler.net>
parents:
28687
diff
changeset
|
79 #if defined(HAVE_PTHREAD_SIGMASK) && !defined(HAVE_BROKEN_PTHREAD_SIGMASK) |
|
20398
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
80 # define SET_THREAD_SIGMASK pthread_sigmask |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
81 #else |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
82 # define SET_THREAD_SIGMASK sigprocmask |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
83 #endif |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
84 |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
85 |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
86 /* A pthread mutex isn't sufficient to model the Python lock type |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
87 * because, according to Draft 5 of the docs (P1003.4a/D5), both of the |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
88 * following are undefined: |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
89 * -> a thread tries to lock a mutex it already has locked |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
90 * -> a thread tries to unlock a mutex locked by a different thread |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
91 * pthread mutexes are designed for serializing threads over short pieces |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
92 * of code anyway, so wouldn't be an appropriate implementation of |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 * Python's locks regardless. |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
94 * |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
95 * The pthread_lock struct implements a Python lock as a "locked?" bit |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
96 * and a <condition, mutex> pair. In general, if the bit can be acquired |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
97 * instantly, it is, else the pair is used to block the thread until the |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
98 * bit is cleared. 9 May 1994 tim@ksr.com |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 */ |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
100 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
101 typedef struct { |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
102 char locked; /* 0=unlocked, 1=locked */ |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
103 /* a <cond, mutex> pair to handle an acquire of a locked lock */ |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
104 pthread_cond_t lock_released; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
105 pthread_mutex_t mut; |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
106 } pthread_lock; |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
107 |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
108 #define CHECK_STATUS(name) if (status != 0) { perror(name); error = 1; } |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
109 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 /* |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
111 * Initialization. |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 */ |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
113 |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
114 #ifdef _HAVE_BSDI |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
115 static |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
116 void _noop(void) |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
117 { |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
118 } |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
119 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
120 static void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
121 PyThread__init_thread(void) |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
122 { |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
123 /* DO AN INIT BY STARTING THE THREAD */ |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
124 static int dummy = 0; |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
125 pthread_t thread1; |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
126 pthread_create(&thread1, NULL, (void *) _noop, &dummy); |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
127 pthread_join(thread1, NULL); |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
128 } |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
129 |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
130 #else /* !_HAVE_BSDI */ |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
131 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
132 static void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
133 PyThread__init_thread(void) |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
134 { |
|
9079
4d2cb212c8d1
Apparently on AIX when using gcc you need to call pthread_init()
Guido van Rossum <guido@python.org>
parents:
9070
diff
changeset
|
135 #if defined(_AIX) && defined(__GNUC__) |
|
4d2cb212c8d1
Apparently on AIX when using gcc you need to call pthread_init()
Guido van Rossum <guido@python.org>
parents:
9070
diff
changeset
|
136 pthread_init(); |
|
4d2cb212c8d1
Apparently on AIX when using gcc you need to call pthread_init()
Guido van Rossum <guido@python.org>
parents:
9070
diff
changeset
|
137 #endif |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
139 |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
140 #endif /* !_HAVE_BSDI */ |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
141 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
142 /* |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
143 * Thread support. |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
144 */ |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
145 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
146 |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
147 long |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
148 PyThread_start_new_thread(void (*func)(void *), void *arg) |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 { |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
150 pthread_t th; |
|
28687
40d287c3d906
Patch #716969: Detect thread creation failure. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28673
diff
changeset
|
151 int status; |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
152 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) |
|
19549
11a758c56027
GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents:
14375
diff
changeset
|
153 pthread_attr_t attrs; |
|
11a758c56027
GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents:
14375
diff
changeset
|
154 #endif |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
155 #if defined(THREAD_STACK_SIZE) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
156 size_t tss; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
157 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
158 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
159 dprintf(("PyThread_start_new_thread called\n")); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
160 if (!initialized) |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
161 PyThread_init_thread(); |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
162 |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
163 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
164 if (pthread_attr_init(&attrs) != 0) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
165 return -1; |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
166 #endif |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
167 #if defined(THREAD_STACK_SIZE) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
168 tss = (_pythread_stacksize != 0) ? _pythread_stacksize |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
169 : THREAD_STACK_SIZE; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
170 if (tss != 0) { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
171 if (pthread_attr_setstacksize(&attrs, tss) != 0) { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
172 pthread_attr_destroy(&attrs); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
173 return -1; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
174 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
175 } |
|
19549
11a758c56027
GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents:
14375
diff
changeset
|
176 #endif |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35607
diff
changeset
|
177 #if defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
178 pthread_attr_setscope(&attrs, PTHREAD_SCOPE_SYSTEM); |
|
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
179 #endif |
|
20398
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
180 |
|
28687
40d287c3d906
Patch #716969: Detect thread creation failure. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28673
diff
changeset
|
181 status = pthread_create(&th, |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
182 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) |
|
19549
11a758c56027
GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents:
14375
diff
changeset
|
183 &attrs, |
|
11a758c56027
GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents:
14375
diff
changeset
|
184 #else |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
185 (pthread_attr_t*)NULL, |
|
19549
11a758c56027
GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents:
14375
diff
changeset
|
186 #endif |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
187 (void* (*)(void *))func, |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
188 (void *)arg |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
189 ); |
|
20398
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
190 |
|
20922
7a991d012cd6
Fix memory leak. This is part of SF patch #478006.
Fred Drake <fdrake@acm.org>
parents:
20468
diff
changeset
|
191 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) |
|
19549
11a758c56027
GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents:
14375
diff
changeset
|
192 pthread_attr_destroy(&attrs); |
|
11a758c56027
GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents:
14375
diff
changeset
|
193 #endif |
|
28687
40d287c3d906
Patch #716969: Detect thread creation failure. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28673
diff
changeset
|
194 if (status != 0) |
|
40d287c3d906
Patch #716969: Detect thread creation failure. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28673
diff
changeset
|
195 return -1; |
|
40d287c3d906
Patch #716969: Detect thread creation failure. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28673
diff
changeset
|
196 |
|
40d287c3d906
Patch #716969: Detect thread creation failure. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28673
diff
changeset
|
197 pthread_detach(th); |
|
40d287c3d906
Patch #716969: Detect thread creation failure. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28673
diff
changeset
|
198 |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
199 #if SIZEOF_PTHREAD_T <= SIZEOF_LONG |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
200 return (long) th; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
201 #else |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
202 return (long) *(long *) &th; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
203 #endif |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
204 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
205 |
|
14144
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
206 /* XXX This implementation is considered (to quote Tim Peters) "inherently |
|
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
207 hosed" because: |
| 31611 | 208 - It does not guarantee the promise that a non-zero integer is returned. |
|
14144
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
209 - The cast to long is inherently unsafe. |
|
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
210 - It is not clear that the 'volatile' (for AIX?) and ugly casting in the |
|
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
211 latter return statement (for Alpha OSF/1) are any longer necessary. |
|
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
212 */ |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
213 long |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
214 PyThread_get_thread_ident(void) |
|
1651
7e5f97bab1e6
ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents:
1629
diff
changeset
|
215 { |
|
9055
5bc64efc65e0
Add a 'volatile' to the declaration of threadid in get_thread_ident().
Guido van Rossum <guido@python.org>
parents:
8343
diff
changeset
|
216 volatile pthread_t threadid; |
|
1651
7e5f97bab1e6
ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents:
1629
diff
changeset
|
217 if (!initialized) |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
218 PyThread_init_thread(); |
| 2097 | 219 /* Jump through some hoops for Alpha OSF/1 */ |
| 220 threadid = pthread_self(); | |
|
14144
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
221 #if SIZEOF_PTHREAD_T <= SIZEOF_LONG |
|
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
222 return (long) threadid; |
|
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
223 #else |
| 2097 | 224 return (long) *(long *) &threadid; |
|
14144
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
225 #endif |
|
1651
7e5f97bab1e6
ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents:
1629
diff
changeset
|
226 } |
|
7e5f97bab1e6
ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents:
1629
diff
changeset
|
227 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
228 static void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
229 do_PyThread_exit_thread(int no_cleanup) |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
230 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
231 dprintf(("PyThread_exit_thread called\n")); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5700
diff
changeset
|
232 if (!initialized) { |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
233 if (no_cleanup) |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
234 _exit(0); |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
235 else |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
236 exit(0); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5700
diff
changeset
|
237 } |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
238 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
239 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
240 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
241 PyThread_exit_thread(void) |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
242 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
243 do_PyThread_exit_thread(0); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
244 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
245 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
246 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
247 PyThread__exit_thread(void) |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
248 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
249 do_PyThread_exit_thread(1); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
250 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
251 |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
252 #ifndef NO_EXIT_PROG |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
253 static void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
254 do_PyThread_exit_prog(int status, int no_cleanup) |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
255 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
256 dprintf(("PyThread_exit_prog(%d) called\n", status)); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
257 if (!initialized) |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
258 if (no_cleanup) |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
259 _exit(status); |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
260 else |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
261 exit(status); |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
262 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
263 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
264 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
265 PyThread_exit_prog(int status) |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
266 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
267 do_PyThread_exit_prog(status, 0); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
268 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
269 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
270 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
271 PyThread__exit_prog(int status) |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
272 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
273 do_PyThread_exit_prog(status, 1); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
274 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
275 #endif /* NO_EXIT_PROG */ |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
276 |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
277 #ifdef USE_SEMAPHORES |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
278 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
279 /* |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
280 * Lock support. |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
281 */ |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
282 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
283 PyThread_type_lock |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
284 PyThread_allocate_lock(void) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
285 { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
286 sem_t *lock; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
287 int status, error = 0; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
288 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
289 dprintf(("PyThread_allocate_lock called\n")); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
290 if (!initialized) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
291 PyThread_init_thread(); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
292 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
293 lock = (sem_t *)malloc(sizeof(sem_t)); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
294 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
295 if (lock) { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
296 status = sem_init(lock,0,1); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
297 CHECK_STATUS("sem_init"); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
298 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
299 if (error) { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
300 free((void *)lock); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
301 lock = NULL; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
302 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
303 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
304 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
305 dprintf(("PyThread_allocate_lock() -> %p\n", lock)); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
306 return (PyThread_type_lock)lock; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
307 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
308 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
309 void |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
310 PyThread_free_lock(PyThread_type_lock lock) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
311 { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
312 sem_t *thelock = (sem_t *)lock; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
313 int status, error = 0; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
314 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
315 dprintf(("PyThread_free_lock(%p) called\n", lock)); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
316 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
317 if (!thelock) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
318 return; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
319 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
320 status = sem_destroy(thelock); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
321 CHECK_STATUS("sem_destroy"); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
322 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
323 free((void *)thelock); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
324 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
325 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
326 /* |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
327 * As of February 2002, Cygwin thread implementations mistakenly report error |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
328 * codes in the return value of the sem_ calls (like the pthread_ functions). |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
329 * Correct implementations return -1 and put the code in errno. This supports |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
330 * either. |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
331 */ |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
332 static int |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
333 fix_status(int status) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
334 { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
335 return (status == -1) ? errno : status; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
336 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
337 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
338 int |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
339 PyThread_acquire_lock(PyThread_type_lock lock, int waitflag) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
340 { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
341 int success; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
342 sem_t *thelock = (sem_t *)lock; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
343 int status, error = 0; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
344 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
345 dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag)); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
346 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
347 do { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
348 if (waitflag) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
349 status = fix_status(sem_wait(thelock)); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
350 else |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
351 status = fix_status(sem_trywait(thelock)); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
352 } while (status == EINTR); /* Retry if interrupted by a signal */ |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
353 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
354 if (waitflag) { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
355 CHECK_STATUS("sem_wait"); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
356 } else if (status != EAGAIN) { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
357 CHECK_STATUS("sem_trywait"); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
358 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
359 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
360 success = (status == 0) ? 1 : 0; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
361 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
362 dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success)); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
363 return success; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
364 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
365 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
366 void |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
367 PyThread_release_lock(PyThread_type_lock lock) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
368 { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
369 sem_t *thelock = (sem_t *)lock; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
370 int status, error = 0; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
371 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
372 dprintf(("PyThread_release_lock(%p) called\n", lock)); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
373 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
374 status = sem_post(thelock); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
375 CHECK_STATUS("sem_post"); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
376 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
377 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
378 #else /* USE_SEMAPHORES */ |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
379 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
380 /* |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
381 * Lock support. |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
382 */ |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
383 PyThread_type_lock |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
384 PyThread_allocate_lock(void) |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
385 { |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
386 pthread_lock *lock; |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
387 int status, error = 0; |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
388 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
389 dprintf(("PyThread_allocate_lock called\n")); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
390 if (!initialized) |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
391 PyThread_init_thread(); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
392 |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
393 lock = (pthread_lock *) malloc(sizeof(pthread_lock)); |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
394 if (lock) { |
|
35607
5a8bf8e7d010
Don't call memset() before checking that the ptr is not NULL.
Armin Rigo <arigo@tunes.org>
parents:
34824
diff
changeset
|
395 memset((void *)lock, '\0', sizeof(pthread_lock)); |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
396 lock->locked = 0; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
397 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
398 status = pthread_mutex_init(&lock->mut, |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
399 pthread_mutexattr_default); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
400 CHECK_STATUS("pthread_mutex_init"); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
401 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
402 status = pthread_cond_init(&lock->lock_released, |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
403 pthread_condattr_default); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
404 CHECK_STATUS("pthread_cond_init"); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
405 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
406 if (error) { |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
407 free((void *)lock); |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
408 lock = 0; |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
409 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
410 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
411 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
412 dprintf(("PyThread_allocate_lock() -> %p\n", lock)); |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
413 return (PyThread_type_lock) lock; |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
414 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
415 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
416 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
417 PyThread_free_lock(PyThread_type_lock lock) |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
418 { |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
419 pthread_lock *thelock = (pthread_lock *)lock; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
420 int status, error = 0; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
421 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
422 dprintf(("PyThread_free_lock(%p) called\n", lock)); |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
423 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
424 status = pthread_mutex_destroy( &thelock->mut ); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
425 CHECK_STATUS("pthread_mutex_destroy"); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
426 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
427 status = pthread_cond_destroy( &thelock->lock_released ); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
428 CHECK_STATUS("pthread_cond_destroy"); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
429 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
430 free((void *)thelock); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
431 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
432 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
433 int |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
434 PyThread_acquire_lock(PyThread_type_lock lock, int waitflag) |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
435 { |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
436 int success; |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
437 pthread_lock *thelock = (pthread_lock *)lock; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
438 int status, error = 0; |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
439 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
440 dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag)); |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
441 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
442 status = pthread_mutex_lock( &thelock->mut ); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
443 CHECK_STATUS("pthread_mutex_lock[1]"); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
444 success = thelock->locked == 0; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
445 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
446 if ( !success && waitflag ) { |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
447 /* continue trying until we get the lock */ |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
448 |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
449 /* mut must be locked by me -- part of the condition |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
450 * protocol */ |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
451 while ( thelock->locked ) { |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
452 status = pthread_cond_wait(&thelock->lock_released, |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
453 &thelock->mut); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
454 CHECK_STATUS("pthread_cond_wait"); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
455 } |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
456 success = 1; |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
457 } |
|
28673
c1ba50790c83
Patch #711835: Remove unnecessary lock operations. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
27320
diff
changeset
|
458 if (success) thelock->locked = 1; |
|
c1ba50790c83
Patch #711835: Remove unnecessary lock operations. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
27320
diff
changeset
|
459 status = pthread_mutex_unlock( &thelock->mut ); |
|
c1ba50790c83
Patch #711835: Remove unnecessary lock operations. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
27320
diff
changeset
|
460 CHECK_STATUS("pthread_mutex_unlock[1]"); |
|
c1ba50790c83
Patch #711835: Remove unnecessary lock operations. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
27320
diff
changeset
|
461 |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
462 if (error) success = 0; |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
463 dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success)); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
464 return success; |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
465 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
466 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
467 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
468 PyThread_release_lock(PyThread_type_lock lock) |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
469 { |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
470 pthread_lock *thelock = (pthread_lock *)lock; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
471 int status, error = 0; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
472 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
473 dprintf(("PyThread_release_lock(%p) called\n", lock)); |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
474 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
475 status = pthread_mutex_lock( &thelock->mut ); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
476 CHECK_STATUS("pthread_mutex_lock[3]"); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
477 |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
478 thelock->locked = 0; |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
479 |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
480 status = pthread_mutex_unlock( &thelock->mut ); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
481 CHECK_STATUS("pthread_mutex_unlock[3]"); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
482 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
483 /* wake up someone (anyone, if any) waiting on the lock */ |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
484 status = pthread_cond_signal( &thelock->lock_released ); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
485 CHECK_STATUS("pthread_cond_signal"); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
486 } |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
487 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
488 #endif /* USE_SEMAPHORES */ |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
489 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
490 /* set the thread stack size. |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
491 * Return 0 if size is valid, -1 if size is invalid, |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
492 * -2 if setting stack size is not supported. |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
493 */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
494 static int |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
495 _pythread_pthread_set_stacksize(size_t size) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
496 { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
497 #if defined(THREAD_STACK_SIZE) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
498 pthread_attr_t attrs; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
499 size_t tss_min; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
500 int rc = 0; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
501 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
502 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
503 /* set to default */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
504 if (size == 0) { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
505 _pythread_stacksize = 0; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
506 return 0; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
507 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
508 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
509 #if defined(THREAD_STACK_SIZE) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
510 #if defined(PTHREAD_STACK_MIN) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
511 tss_min = PTHREAD_STACK_MIN > THREAD_STACK_MIN ? PTHREAD_STACK_MIN |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
512 : THREAD_STACK_MIN; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
513 #else |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
514 tss_min = THREAD_STACK_MIN; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
515 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
516 if (size >= tss_min) { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
517 /* validate stack size by setting thread attribute */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
518 if (pthread_attr_init(&attrs) == 0) { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
519 rc = pthread_attr_setstacksize(&attrs, size); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
520 pthread_attr_destroy(&attrs); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
521 if (rc == 0) { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
522 _pythread_stacksize = size; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
523 return 0; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
524 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
525 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
526 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
527 return -1; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
528 #else |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
529 return -2; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
530 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
531 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
532 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
533 #define THREAD_SET_STACKSIZE(x) _pythread_pthread_set_stacksize(x) |
