Mercurial > cpython-lru_cache-weakref
annotate Python/thread_pthread.h @ 81257:c256764e2b3f 3.2
Issue #16455: On FreeBSD and Solaris, if the locale is C, the
ASCII/surrogateescape codec is now used, instead of the locale encoding, to
decode the command line arguments. This change fixes inconsistencies with
os.fsencode() and os.fsdecode() because these operating systems announces an
ASCII locale encoding, whereas the ISO-8859-1 encoding is used in practice.
| author | Victor Stinner <victor.stinner@gmail.com> |
|---|---|
| date | Thu, 03 Jan 2013 01:08:58 +0100 |
| parents | 280469ce6669 |
| children | 470785a9fdd5 |
| 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 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
19 #define THREAD_STACK_SIZE 0 /* use default stack size */ |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
20 #endif |
|
70448
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
21 |
|
75596
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
22 /* The default stack size for new threads on OSX and BSD is small enough that |
|
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
23 * we'll get hard crashes instead of 'maximum recursion depth exceeded' |
|
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
24 * exceptions. |
|
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
25 * |
|
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
26 * The default stack sizes below are the empirically determined minimal stack |
|
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
27 * sizes where a simple recursive function doesn't cause a hard crash. |
|
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
28 */ |
|
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
29 #if defined(__APPLE__) && defined(THREAD_STACK_SIZE) && THREAD_STACK_SIZE == 0 |
|
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
30 #undef THREAD_STACK_SIZE |
|
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
31 #define THREAD_STACK_SIZE 0x500000 |
|
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
32 #endif |
|
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
33 #if defined(__FreeBSD__) && defined(THREAD_STACK_SIZE) && THREAD_STACK_SIZE == 0 |
|
70448
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
34 #undef THREAD_STACK_SIZE |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
35 #define THREAD_STACK_SIZE 0x400000 |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
36 #endif |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
37 /* for safety, ensure a viable minimum stacksize */ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
38 #define THREAD_STACK_MIN 0x8000 /* 32kB */ |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
39 #else /* !_POSIX_THREAD_ATTR_STACKSIZE */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
40 #ifdef THREAD_STACK_SIZE |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
41 #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
|
42 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
43 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
44 |
|
22341
2548e2f323fa
Document that _POSIX_SEMAPHORES is predefined.
Martin v. Löwis <martin@v.loewis.de>
parents:
22339
diff
changeset
|
45 /* 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
|
46 family of functions must indicate this by defining |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
47 _POSIX_SEMAPHORES. */ |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
48 #ifdef _POSIX_SEMAPHORES |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
49 /* On FreeBSD 4.x, _POSIX_SEMAPHORES is defined empty, so |
|
34824
a50ffe65911b
Add 0 to _POSIX_SEMAPHORES.
Martin v. Löwis <martin@v.loewis.de>
parents:
34762
diff
changeset
|
50 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
|
51 #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
|
52 #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
|
53 #else |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
54 #include <semaphore.h> |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
55 #include <errno.h> |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
56 #endif |
|
34762
fcb507414c41
Patch #1163249 - Correctly handle _POSIX_SEMAPHORES == -1 to mean no
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32526
diff
changeset
|
57 #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
|
58 |
|
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
|
59 /* 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
|
60 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
|
61 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
|
62 #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
|
63 #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
|
64 #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
|
65 #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
|
66 #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
|
67 #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
|
68 |
|
26598
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
69 #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
|
70 # 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
|
71 #endif |
|
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
72 #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
|
73 # 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
|
74 #endif |
|
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
75 #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
|
76 # define pthread_condattr_default ((pthread_condattr_t *)NULL) |
|
3965
9c05ff6fb0a4
Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents:
3663
diff
changeset
|
77 #endif |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
79 |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
80 /* 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
|
81 * mutexes and condition variables: |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
82 */ |
|
65205
ed5e598da150
Issue #10062: Allow building on platforms which do not have sem_timedwait.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64844
diff
changeset
|
83 #if (defined(_POSIX_SEMAPHORES) && !defined(HAVE_BROKEN_POSIX_SEMAPHORES) && \ |
|
ed5e598da150
Issue #10062: Allow building on platforms which do not have sem_timedwait.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64844
diff
changeset
|
84 defined(HAVE_SEM_TIMEDWAIT)) |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
85 # define USE_SEMAPHORES |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
86 #else |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
87 # undef USE_SEMAPHORES |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
88 #endif |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
89 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
90 |
|
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
|
91 /* 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
|
92 * 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
|
93 * 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
|
94 * 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
|
95 */ |
|
29972
a408ac5527c3
Patch 775605: Cygwin pthread_sigmask() workaround patch
Jason Tishler <jason@tishler.net>
parents:
28687
diff
changeset
|
96 #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
|
97 # 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
|
98 #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
|
99 # 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
|
100 #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
|
101 |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
102 |
|
60598
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
103 /* We assume all modern POSIX systems have gettimeofday() */ |
|
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
104 #ifdef GETTIMEOFDAY_NO_TZ |
|
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
105 #define GETTIMEOFDAY(ptv) gettimeofday(ptv) |
|
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
106 #else |
|
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
107 #define GETTIMEOFDAY(ptv) gettimeofday(ptv, (struct timezone *)NULL) |
|
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
108 #endif |
|
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
109 |
|
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
110 #define MICROSECONDS_TO_TIMESPEC(microseconds, ts) \ |
|
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
111 do { \ |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
112 struct timeval tv; \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
113 GETTIMEOFDAY(&tv); \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
114 tv.tv_usec += microseconds % 1000000; \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
115 tv.tv_sec += microseconds / 1000000; \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
116 tv.tv_sec += tv.tv_usec / 1000000; \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
117 tv.tv_usec %= 1000000; \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
118 ts.tv_sec = tv.tv_sec; \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
119 ts.tv_nsec = tv.tv_usec * 1000; \ |
|
60598
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
120 } while(0) |
|
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
121 |
|
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
122 |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
123 /* 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
|
124 * 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
|
125 * following are undefined: |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
126 * -> 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
|
127 * -> 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
|
128 * 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
|
129 * 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
|
130 * 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
|
131 * |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
132 * 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
|
133 * 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
|
134 * 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
|
135 * 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
|
136 */ |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
137 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 typedef struct { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
139 char locked; /* 0=unlocked, 1=locked */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
140 /* a <cond, mutex> pair to handle an acquire of a locked lock */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
141 pthread_cond_t lock_released; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
142 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
|
143 } pthread_lock; |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
144 |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
145 #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
|
146 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
147 /* |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
148 * Initialization. |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 */ |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
150 |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
151 #ifdef _HAVE_BSDI |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
152 static |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
153 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
|
154 { |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
155 } |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
156 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
157 static void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
158 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
|
159 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
160 /* DO AN INIT BY STARTING THE THREAD */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
161 static int dummy = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
162 pthread_t thread1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
163 pthread_create(&thread1, NULL, (void *) _noop, &dummy); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
164 pthread_join(thread1, NULL); |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
165 } |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
166 |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
167 #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
|
168 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
169 static void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
170 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
|
171 { |
|
9079
4d2cb212c8d1
Apparently on AIX when using gcc you need to call pthread_init()
Guido van Rossum <guido@python.org>
parents:
9070
diff
changeset
|
172 #if defined(_AIX) && defined(__GNUC__) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
173 pthread_init(); |
|
9079
4d2cb212c8d1
Apparently on AIX when using gcc you need to call pthread_init()
Guido van Rossum <guido@python.org>
parents:
9070
diff
changeset
|
174 #endif |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
175 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
176 |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
177 #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
|
178 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
179 /* |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
180 * Thread support. |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
181 */ |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
182 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
183 |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
184 long |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
185 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
|
186 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
187 pthread_t th; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
188 int status; |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
189 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
190 pthread_attr_t attrs; |
|
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
|
191 #endif |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
192 #if defined(THREAD_STACK_SIZE) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
193 size_t tss; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
194 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
195 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
196 dprintf(("PyThread_start_new_thread called\n")); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
197 if (!initialized) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
198 PyThread_init_thread(); |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
199 |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
200 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
201 if (pthread_attr_init(&attrs) != 0) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
202 return -1; |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
203 #endif |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
204 #if defined(THREAD_STACK_SIZE) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
205 tss = (_pythread_stacksize != 0) ? _pythread_stacksize |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
206 : THREAD_STACK_SIZE; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
207 if (tss != 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
208 if (pthread_attr_setstacksize(&attrs, tss) != 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
209 pthread_attr_destroy(&attrs); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
210 return -1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
211 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
212 } |
|
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
|
213 #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
|
214 #if defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
215 pthread_attr_setscope(&attrs, PTHREAD_SCOPE_SYSTEM); |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
216 #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
|
217 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
218 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
|
219 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
220 &attrs, |
|
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
|
221 #else |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
222 (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
|
223 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
224 (void* (*)(void *))func, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
225 (void *)arg |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
226 ); |
|
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
|
227 |
|
20922
7a991d012cd6
Fix memory leak. This is part of SF patch #478006.
Fred Drake <fdrake@acm.org>
parents:
20468
diff
changeset
|
228 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
229 pthread_attr_destroy(&attrs); |
|
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
|
230 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
231 if (status != 0) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
232 return -1; |
|
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
|
233 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
234 pthread_detach(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
|
235 |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
236 #if SIZEOF_PTHREAD_T <= SIZEOF_LONG |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
237 return (long) th; |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
238 #else |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
239 return (long) *(long *) &th; |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
240 #endif |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
241 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
242 |
|
14144
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
243 /* 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
|
244 hosed" because: |
| 31611 | 245 - 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
|
246 - 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
|
247 - 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
|
248 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
|
249 */ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
250 long |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
251 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
|
252 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
253 volatile pthread_t threadid; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
254 if (!initialized) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
255 PyThread_init_thread(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
256 /* Jump through some hoops for Alpha OSF/1 */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
257 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
|
258 #if SIZEOF_PTHREAD_T <= SIZEOF_LONG |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
259 return (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
|
260 #else |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
261 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
|
262 #endif |
|
1651
7e5f97bab1e6
ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents:
1629
diff
changeset
|
263 } |
|
7e5f97bab1e6
ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents:
1629
diff
changeset
|
264 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
265 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
266 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
|
267 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
268 dprintf(("PyThread_exit_thread called\n")); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
269 if (!initialized) |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
270 exit(0); |
|
69832
2a19d09b08f8
Issue #1856: Avoid crashes and lockups when daemon threads run while the
Antoine Pitrou <solipsis@pitrou.net>
parents:
69226
diff
changeset
|
271 pthread_exit(0); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
272 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
273 |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
274 #ifdef USE_SEMAPHORES |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
275 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
276 /* |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
277 * Lock support. |
|
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 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
280 PyThread_type_lock |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
281 PyThread_allocate_lock(void) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
282 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
283 sem_t *lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
284 int status, error = 0; |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
285 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
286 dprintf(("PyThread_allocate_lock called\n")); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
287 if (!initialized) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
288 PyThread_init_thread(); |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
289 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
290 lock = (sem_t *)malloc(sizeof(sem_t)); |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
291 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
292 if (lock) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
293 status = sem_init(lock,0,1); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
294 CHECK_STATUS("sem_init"); |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
295 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
296 if (error) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
297 free((void *)lock); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
298 lock = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
299 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
300 } |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
301 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
302 dprintf(("PyThread_allocate_lock() -> %p\n", lock)); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
303 return (PyThread_type_lock)lock; |
|
22339
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 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
306 void |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
307 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
|
308 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
309 sem_t *thelock = (sem_t *)lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
310 int status, error = 0; |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
311 |
|
80677
280469ce6669
Issue #16588: Silence unused-but-set warnings in Python/thread_pthread.h
Christian Heimes <christian@cheimes.de>
parents:
75596
diff
changeset
|
312 (void) error; /* silence unused-but-set-variable warning */ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
313 dprintf(("PyThread_free_lock(%p) called\n", lock)); |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
314 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
315 if (!thelock) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
316 return; |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
317 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
318 status = sem_destroy(thelock); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
319 CHECK_STATUS("sem_destroy"); |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
320 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
321 free((void *)thelock); |
|
22339
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 |
|
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 * 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
|
326 * 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
|
327 * 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
|
328 * either. |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
329 */ |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
330 static int |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
331 fix_status(int status) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
332 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
333 return (status == -1) ? errno : status; |
|
22339
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 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
336 PyLockStatus |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
337 PyThread_acquire_lock_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds, |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
338 int intr_flag) |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
339 { |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
340 PyLockStatus success; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
341 sem_t *thelock = (sem_t *)lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
342 int status, error = 0; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
343 struct timespec ts; |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
344 |
|
80677
280469ce6669
Issue #16588: Silence unused-but-set warnings in Python/thread_pthread.h
Christian Heimes <christian@cheimes.de>
parents:
75596
diff
changeset
|
345 (void) error; /* silence unused-but-set-variable warning */ |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
346 dprintf(("PyThread_acquire_lock_timed(%p, %lld, %d) called\n", |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
347 lock, microseconds, intr_flag)); |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
348 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
349 if (microseconds > 0) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
350 MICROSECONDS_TO_TIMESPEC(microseconds, ts); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
351 do { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
352 if (microseconds > 0) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
353 status = fix_status(sem_timedwait(thelock, &ts)); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
354 else if (microseconds == 0) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
355 status = fix_status(sem_trywait(thelock)); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
356 else |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
357 status = fix_status(sem_wait(thelock)); |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
358 /* Retry if interrupted by a signal, unless the caller wants to be |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
359 notified. */ |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
360 } while (!intr_flag && status == EINTR); |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
361 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
362 /* Don't check the status if we're stopping because of an interrupt. */ |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
363 if (!(intr_flag && status == EINTR)) { |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
364 if (microseconds > 0) { |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
365 if (status != ETIMEDOUT) |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
366 CHECK_STATUS("sem_timedwait"); |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
367 } |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
368 else if (microseconds == 0) { |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
369 if (status != EAGAIN) |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
370 CHECK_STATUS("sem_trywait"); |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
371 } |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
372 else { |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
373 CHECK_STATUS("sem_wait"); |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
374 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
375 } |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
376 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
377 if (status == 0) { |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
378 success = PY_LOCK_ACQUIRED; |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
379 } else if (intr_flag && status == EINTR) { |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
380 success = PY_LOCK_INTR; |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
381 } else { |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
382 success = PY_LOCK_FAILURE; |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
383 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
384 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
385 dprintf(("PyThread_acquire_lock_timed(%p, %lld, %d) -> %d\n", |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
386 lock, microseconds, intr_flag, success)); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
387 return success; |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
388 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
389 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
390 void |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
391 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
|
392 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
393 sem_t *thelock = (sem_t *)lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
394 int status, error = 0; |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
395 |
|
80677
280469ce6669
Issue #16588: Silence unused-but-set warnings in Python/thread_pthread.h
Christian Heimes <christian@cheimes.de>
parents:
75596
diff
changeset
|
396 (void) error; /* silence unused-but-set-variable warning */ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
397 dprintf(("PyThread_release_lock(%p) called\n", lock)); |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
398 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
399 status = sem_post(thelock); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
400 CHECK_STATUS("sem_post"); |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
401 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
402 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
403 #else /* USE_SEMAPHORES */ |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
404 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
405 /* |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
406 * Lock support. |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
407 */ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
408 PyThread_type_lock |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
409 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
|
410 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
411 pthread_lock *lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
412 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
|
413 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
414 dprintf(("PyThread_allocate_lock called\n")); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
415 if (!initialized) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
416 PyThread_init_thread(); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
417 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
418 lock = (pthread_lock *) malloc(sizeof(pthread_lock)); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
419 if (lock) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
420 memset((void *)lock, '\0', sizeof(pthread_lock)); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
421 lock->locked = 0; |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
422 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
423 status = pthread_mutex_init(&lock->mut, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
424 pthread_mutexattr_default); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
425 CHECK_STATUS("pthread_mutex_init"); |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
426 /* Mark the pthread mutex underlying a Python mutex as |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
427 pure happens-before. We can't simply mark the |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
428 Python-level mutex as a mutex because it can be |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
429 acquired and released in different threads, which |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
430 will cause errors. */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
431 _Py_ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX(&lock->mut); |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
432 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
433 status = pthread_cond_init(&lock->lock_released, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
434 pthread_condattr_default); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
435 CHECK_STATUS("pthread_cond_init"); |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
436 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
437 if (error) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
438 free((void *)lock); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
439 lock = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
440 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
441 } |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
442 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
443 dprintf(("PyThread_allocate_lock() -> %p\n", lock)); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
444 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
|
445 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
446 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
447 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
448 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
|
449 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
450 pthread_lock *thelock = (pthread_lock *)lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
451 int status, error = 0; |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
452 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
453 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
|
454 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
455 status = pthread_mutex_destroy( &thelock->mut ); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
456 CHECK_STATUS("pthread_mutex_destroy"); |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
457 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
458 status = pthread_cond_destroy( &thelock->lock_released ); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
459 CHECK_STATUS("pthread_cond_destroy"); |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
460 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
461 free((void *)thelock); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
462 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
463 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
464 PyLockStatus |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
465 PyThread_acquire_lock_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds, |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
466 int intr_flag) |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
467 { |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
468 PyLockStatus success; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
469 pthread_lock *thelock = (pthread_lock *)lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
470 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
|
471 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
472 dprintf(("PyThread_acquire_lock_timed(%p, %lld, %d) called\n", |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
473 lock, microseconds, intr_flag)); |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
474 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
475 status = pthread_mutex_lock( &thelock->mut ); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
476 CHECK_STATUS("pthread_mutex_lock[1]"); |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
477 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
478 if (thelock->locked == 0) { |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
479 success = PY_LOCK_ACQUIRED; |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
480 } else if (microseconds == 0) { |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
481 success = PY_LOCK_FAILURE; |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
482 } else { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
483 struct timespec ts; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
484 if (microseconds > 0) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
485 MICROSECONDS_TO_TIMESPEC(microseconds, ts); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
486 /* 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
|
487 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
488 /* mut must be locked by me -- part of the condition |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
489 * protocol */ |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
490 success = PY_LOCK_FAILURE; |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
491 while (success == PY_LOCK_FAILURE) { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
492 if (microseconds > 0) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
493 status = pthread_cond_timedwait( |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
494 &thelock->lock_released, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
495 &thelock->mut, &ts); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
496 if (status == ETIMEDOUT) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
497 break; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
498 CHECK_STATUS("pthread_cond_timed_wait"); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
499 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
500 else { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
501 status = pthread_cond_wait( |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
502 &thelock->lock_released, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
503 &thelock->mut); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
504 CHECK_STATUS("pthread_cond_wait"); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
505 } |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
506 |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
507 if (intr_flag && status == 0 && thelock->locked) { |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
508 /* We were woken up, but didn't get the lock. We probably received |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
509 * a signal. Return PY_LOCK_INTR to allow the caller to handle |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
510 * it and retry. */ |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
511 success = PY_LOCK_INTR; |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
512 break; |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
513 } else if (status == 0 && !thelock->locked) { |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
514 success = PY_LOCK_ACQUIRED; |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
515 } else { |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
516 success = PY_LOCK_FAILURE; |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
517 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
518 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
519 } |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
520 if (success == PY_LOCK_ACQUIRED) thelock->locked = 1; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
521 status = pthread_mutex_unlock( &thelock->mut ); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
522 CHECK_STATUS("pthread_mutex_unlock[1]"); |
|
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
|
523 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
524 if (error) success = PY_LOCK_FAILURE; |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
525 dprintf(("PyThread_acquire_lock_timed(%p, %lld, %d) -> %d\n", |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
526 lock, microseconds, intr_flag, success)); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
527 return success; |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
528 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
529 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
530 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
531 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
|
532 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
533 pthread_lock *thelock = (pthread_lock *)lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
534 int status, error = 0; |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
535 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
536 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
|
537 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
538 status = pthread_mutex_lock( &thelock->mut ); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
539 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
|
540 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
541 thelock->locked = 0; |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
542 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
543 status = pthread_mutex_unlock( &thelock->mut ); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
544 CHECK_STATUS("pthread_mutex_unlock[3]"); |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
545 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
546 /* wake up someone (anyone, if any) waiting on the lock */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
547 status = pthread_cond_signal( &thelock->lock_released ); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
548 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
|
549 } |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
550 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
551 #endif /* USE_SEMAPHORES */ |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
552 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
553 int |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
554 PyThread_acquire_lock(PyThread_type_lock lock, int waitflag) |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
555 { |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
556 return PyThread_acquire_lock_timed(lock, waitflag ? -1 : 0, /*intr_flag=*/0); |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
557 } |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
558 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
559 /* set the thread stack size. |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
560 * 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
|
561 * -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
|
562 */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
563 static int |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
564 _pythread_pthread_set_stacksize(size_t size) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
565 { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
566 #if defined(THREAD_STACK_SIZE) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
567 pthread_attr_t attrs; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
568 size_t tss_min; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
569 int rc = 0; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
570 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
571 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
572 /* set to default */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
573 if (size == 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
574 _pythread_stacksize = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
575 return 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
576 } |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
577 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
578 #if defined(THREAD_STACK_SIZE) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
579 #if defined(PTHREAD_STACK_MIN) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
580 tss_min = PTHREAD_STACK_MIN > THREAD_STACK_MIN ? PTHREAD_STACK_MIN |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
581 : THREAD_STACK_MIN; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
582 #else |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
583 tss_min = THREAD_STACK_MIN; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
584 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
585 if (size >= tss_min) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
586 /* validate stack size by setting thread attribute */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
587 if (pthread_attr_init(&attrs) == 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
588 rc = pthread_attr_setstacksize(&attrs, size); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
589 pthread_attr_destroy(&attrs); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
590 if (rc == 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
591 _pythread_stacksize = size; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
592 return 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
593 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
594 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
595 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
596 return -1; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
597 #else |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
598 return -2; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
599 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
600 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
601 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
602 #define THREAD_SET_STACKSIZE(x) _pythread_pthread_set_stacksize(x) |
|
64844
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
603 |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
604 #define Py_HAVE_NATIVE_TLS |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
605 |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
606 int |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
607 PyThread_create_key(void) |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
608 { |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
609 pthread_key_t key; |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
610 int fail = pthread_key_create(&key, NULL); |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
611 return fail ? -1 : key; |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
612 } |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
613 |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
614 void |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
615 PyThread_delete_key(int key) |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
616 { |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
617 pthread_key_delete(key); |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
618 } |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
619 |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
620 void |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
621 PyThread_delete_key_value(int key) |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
622 { |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
623 pthread_setspecific(key, NULL); |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
624 } |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
625 |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
626 int |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
627 PyThread_set_key_value(int key, void *value) |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
628 { |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
629 int fail; |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
630 void *oldValue = pthread_getspecific(key); |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
631 if (oldValue != NULL) |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
632 return 0; |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
633 fail = pthread_setspecific(key, value); |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
634 return fail ? -1 : 0; |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
635 } |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
636 |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
637 void * |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
638 PyThread_get_key_value(int key) |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
639 { |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
640 return pthread_getspecific(key); |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
641 } |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
642 |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
643 void |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
644 PyThread_ReInitTLS(void) |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
645 {} |
