Mercurial > cpython-lru_cache-weakref
annotate Python/thread_pthread.h @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | 9af1905f20af |
| children |
| 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:
37168
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:
37168
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:
37168
diff
changeset
|
17 #ifdef _POSIX_THREAD_ATTR_STACKSIZE |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37168
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:
37168
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:
37168
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:
37168
diff
changeset
|
39 #else /* !_POSIX_THREAD_ATTR_STACKSIZE */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37168
diff
changeset
|
40 #ifdef THREAD_STACK_SIZE |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37168
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:
37168
diff
changeset
|
42 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37168
diff
changeset
|
43 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37168
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 |
|
37168
4f97b6a229ce
Patch #1396919: Reenable the system scope threads on FreeBSD 5.4
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35607
diff
changeset
|
59 /* Before FreeBSD 5.4, system scope threads was very limited resource |
|
4f97b6a229ce
Patch #1396919: Reenable the system scope threads on FreeBSD 5.4
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35607
diff
changeset
|
60 in default setting. So the process scope is preferred to get |
|
4f97b6a229ce
Patch #1396919: Reenable the system scope threads on FreeBSD 5.4
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35607
diff
changeset
|
61 enough number of threads to work. */ |
|
4f97b6a229ce
Patch #1396919: Reenable the system scope threads on FreeBSD 5.4
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35607
diff
changeset
|
62 #ifdef __FreeBSD__ |
|
4f97b6a229ce
Patch #1396919: Reenable the system scope threads on FreeBSD 5.4
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35607
diff
changeset
|
63 #include <osreldate.h> |
|
4f97b6a229ce
Patch #1396919: Reenable the system scope threads on FreeBSD 5.4
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35607
diff
changeset
|
64 #if __FreeBSD_version >= 500000 && __FreeBSD_version < 504101 |
|
4f97b6a229ce
Patch #1396919: Reenable the system scope threads on FreeBSD 5.4
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35607
diff
changeset
|
65 #undef PTHREAD_SYSTEM_SCHED_SUPPORTED |
|
4f97b6a229ce
Patch #1396919: Reenable the system scope threads on FreeBSD 5.4
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35607
diff
changeset
|
66 #endif |
|
4f97b6a229ce
Patch #1396919: Reenable the system scope threads on FreeBSD 5.4
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35607
diff
changeset
|
67 #endif |
|
4f97b6a229ce
Patch #1396919: Reenable the system scope threads on FreeBSD 5.4
Hye-Shik Chang <hyeshik@gmail.com>
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 |
|
71213
34061f0d35ba
Issue #12469: partial revert of 024827a9db64, freebsd6 thread initialization
Victor Stinner <victor.stinner@haypocalc.com>
parents:
70943
diff
changeset
|
151 #if defined(_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__) |
|
84205
f2e373ddfa00
Issue #18256: Compilation fix for recent AIX releases. Patch by David Edelsohn.
Antoine Pitrou <solipsis@pitrou.net>
parents:
80678
diff
changeset
|
173 extern void pthread_init(void); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
174 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
|
175 #endif |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
176 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
177 |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
178 #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
|
179 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
180 /* |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
181 * Thread support. |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
182 */ |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
183 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
184 |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
185 long |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
186 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
|
187 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
188 pthread_t th; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
189 int status; |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
190 #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
|
191 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
|
192 #endif |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37168
diff
changeset
|
193 #if defined(THREAD_STACK_SIZE) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
194 size_t tss; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37168
diff
changeset
|
195 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37168
diff
changeset
|
196 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
197 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
|
198 if (!initialized) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
199 PyThread_init_thread(); |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
200 |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
201 #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
|
202 if (pthread_attr_init(&attrs) != 0) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
203 return -1; |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
204 #endif |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37168
diff
changeset
|
205 #if defined(THREAD_STACK_SIZE) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
206 tss = (_pythread_stacksize != 0) ? _pythread_stacksize |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
207 : THREAD_STACK_SIZE; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
208 if (tss != 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
209 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
|
210 pthread_attr_destroy(&attrs); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
211 return -1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
212 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
213 } |
|
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
|
214 #endif |
|
37168
4f97b6a229ce
Patch #1396919: Reenable the system scope threads on FreeBSD 5.4
Hye-Shik Chang <hyeshik@gmail.com>
parents:
35607
diff
changeset
|
215 #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
|
216 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
|
217 #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
|
218 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
219 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
|
220 #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
|
221 &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
|
222 #else |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
223 (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
|
224 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
225 (void* (*)(void *))func, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
226 (void *)arg |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
227 ); |
|
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
|
228 |
|
20922
7a991d012cd6
Fix memory leak. This is part of SF patch #478006.
Fred Drake <fdrake@acm.org>
parents:
20468
diff
changeset
|
229 #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
|
230 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
|
231 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
232 if (status != 0) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
233 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
|
234 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
235 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
|
236 |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
237 #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
|
238 return (long) th; |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
239 #else |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
240 return (long) *(long *) &th; |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
241 #endif |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
242 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
243 |
|
14144
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
244 /* 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
|
245 hosed" because: |
| 31611 | 246 - 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
|
247 - The cast to long is inherently unsafe. |
|
68457
15b090c9442a
Issue #11495: OSF support is eliminated. It was deprecated in Python 3.2
Jesus Cea <jcea@jcea.es>
parents:
68257
diff
changeset
|
248 - It is not clear that the 'volatile' (for AIX?) are any longer necessary. |
|
14144
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 threadid = pthread_self(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
257 return (long) threadid; |
|
1651
7e5f97bab1e6
ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents:
1629
diff
changeset
|
258 } |
|
7e5f97bab1e6
ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents:
1629
diff
changeset
|
259 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
260 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
261 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
|
262 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
263 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
|
264 if (!initialized) |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
265 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
|
266 pthread_exit(0); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
267 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
268 |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
269 #ifdef USE_SEMAPHORES |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
270 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
271 /* |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
272 * Lock support. |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
273 */ |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
274 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
275 PyThread_type_lock |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
276 PyThread_allocate_lock(void) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
277 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
278 sem_t *lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
279 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
|
280 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
281 dprintf(("PyThread_allocate_lock called\n")); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
282 if (!initialized) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
283 PyThread_init_thread(); |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
284 |
|
84497
9af1905f20af
Issue #18203: Replace malloc() with PyMem_RawMalloc() to allocate thread locks
Victor Stinner <victor.stinner@gmail.com>
parents:
84205
diff
changeset
|
285 lock = (sem_t *)PyMem_RawMalloc(sizeof(sem_t)); |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
286 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
287 if (lock) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
288 status = sem_init(lock,0,1); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
289 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
|
290 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
291 if (error) { |
|
84497
9af1905f20af
Issue #18203: Replace malloc() with PyMem_RawMalloc() to allocate thread locks
Victor Stinner <victor.stinner@gmail.com>
parents:
84205
diff
changeset
|
292 PyMem_RawFree((void *)lock); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
293 lock = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
294 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
295 } |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
296 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
297 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
|
298 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
|
299 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
300 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
301 void |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
302 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
|
303 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
304 sem_t *thelock = (sem_t *)lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
305 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
|
306 |
|
80677
280469ce6669
Issue #16588: Silence unused-but-set warnings in Python/thread_pthread.h
Christian Heimes <christian@cheimes.de>
parents:
75596
diff
changeset
|
307 (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
|
308 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
|
309 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
310 if (!thelock) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
311 return; |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
312 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
313 status = sem_destroy(thelock); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
314 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
|
315 |
|
84497
9af1905f20af
Issue #18203: Replace malloc() with PyMem_RawMalloc() to allocate thread locks
Victor Stinner <victor.stinner@gmail.com>
parents:
84205
diff
changeset
|
316 PyMem_RawFree((void *)thelock); |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
317 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
318 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
319 /* |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
320 * 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
|
321 * 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
|
322 * 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
|
323 * either. |
|
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 static int |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
326 fix_status(int status) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
327 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
328 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
|
329 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
330 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
331 PyLockStatus |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
332 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
|
333 int intr_flag) |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
334 { |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
335 PyLockStatus success; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
336 sem_t *thelock = (sem_t *)lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
337 int status, error = 0; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
338 struct timespec ts; |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
339 |
|
80677
280469ce6669
Issue #16588: Silence unused-but-set warnings in Python/thread_pthread.h
Christian Heimes <christian@cheimes.de>
parents:
75596
diff
changeset
|
340 (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
|
341 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
|
342 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
|
343 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
344 if (microseconds > 0) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
345 MICROSECONDS_TO_TIMESPEC(microseconds, ts); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
346 do { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
347 if (microseconds > 0) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
348 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
|
349 else if (microseconds == 0) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
350 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
|
351 else |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
352 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
|
353 /* 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
|
354 notified. */ |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
355 } 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
|
356 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
357 /* 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
|
358 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
|
359 if (microseconds > 0) { |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
360 if (status != ETIMEDOUT) |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
361 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
|
362 } |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
363 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
|
364 if (status != EAGAIN) |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
365 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
|
366 } |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
367 else { |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
368 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
|
369 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
370 } |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
371 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
372 if (status == 0) { |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
373 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
|
374 } 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
|
375 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
|
376 } else { |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
377 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
|
378 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
379 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
380 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
|
381 lock, microseconds, intr_flag, success)); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
382 return success; |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
383 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
384 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
385 void |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
386 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
|
387 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
388 sem_t *thelock = (sem_t *)lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
389 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
|
390 |
|
80677
280469ce6669
Issue #16588: Silence unused-but-set warnings in Python/thread_pthread.h
Christian Heimes <christian@cheimes.de>
parents:
75596
diff
changeset
|
391 (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
|
392 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
|
393 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
394 status = sem_post(thelock); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
395 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
|
396 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
397 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
398 #else /* USE_SEMAPHORES */ |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
399 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
400 /* |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
401 * Lock support. |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
402 */ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
403 PyThread_type_lock |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
404 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
|
405 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
406 pthread_lock *lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
407 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
|
408 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
409 dprintf(("PyThread_allocate_lock called\n")); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
410 if (!initialized) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
411 PyThread_init_thread(); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
412 |
|
84497
9af1905f20af
Issue #18203: Replace malloc() with PyMem_RawMalloc() to allocate thread locks
Victor Stinner <victor.stinner@gmail.com>
parents:
84205
diff
changeset
|
413 lock = (pthread_lock *) PyMem_RawMalloc(sizeof(pthread_lock)); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
414 if (lock) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
415 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
|
416 lock->locked = 0; |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
417 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
418 status = pthread_mutex_init(&lock->mut, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
419 pthread_mutexattr_default); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
420 CHECK_STATUS("pthread_mutex_init"); |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
421 /* 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
|
422 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
|
423 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
|
424 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
|
425 will cause errors. */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
426 _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
|
427 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
428 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
|
429 pthread_condattr_default); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
430 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
|
431 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
432 if (error) { |
|
84497
9af1905f20af
Issue #18203: Replace malloc() with PyMem_RawMalloc() to allocate thread locks
Victor Stinner <victor.stinner@gmail.com>
parents:
84205
diff
changeset
|
433 PyMem_RawFree((void *)lock); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
434 lock = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
435 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
436 } |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
437 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
438 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
|
439 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
|
440 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
441 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
442 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
443 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
|
444 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
445 pthread_lock *thelock = (pthread_lock *)lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
446 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
|
447 |
|
84205
f2e373ddfa00
Issue #18256: Compilation fix for recent AIX releases. Patch by David Edelsohn.
Antoine Pitrou <solipsis@pitrou.net>
parents:
80678
diff
changeset
|
448 (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
|
449 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
|
450 |
|
77365
6d146e2ae9a9
Signal condition variables with the mutex held. Destroy condition variables
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
75597
diff
changeset
|
451 /* some pthread-like implementations tie the mutex to the cond |
|
6d146e2ae9a9
Signal condition variables with the mutex held. Destroy condition variables
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
75597
diff
changeset
|
452 * and must have the cond destroyed first. |
|
6d146e2ae9a9
Signal condition variables with the mutex held. Destroy condition variables
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
75597
diff
changeset
|
453 */ |
|
6d146e2ae9a9
Signal condition variables with the mutex held. Destroy condition variables
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
75597
diff
changeset
|
454 status = pthread_cond_destroy( &thelock->lock_released ); |
|
6d146e2ae9a9
Signal condition variables with the mutex held. Destroy condition variables
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
75597
diff
changeset
|
455 CHECK_STATUS("pthread_cond_destroy"); |
|
6d146e2ae9a9
Signal condition variables with the mutex held. Destroy condition variables
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
75597
diff
changeset
|
456 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
457 status = pthread_mutex_destroy( &thelock->mut ); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
458 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
|
459 |
|
84497
9af1905f20af
Issue #18203: Replace malloc() with PyMem_RawMalloc() to allocate thread locks
Victor Stinner <victor.stinner@gmail.com>
parents:
84205
diff
changeset
|
460 PyMem_RawFree((void *)thelock); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
461 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
462 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
463 PyLockStatus |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
464 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
|
465 int intr_flag) |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
466 { |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
467 PyLockStatus success; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
468 pthread_lock *thelock = (pthread_lock *)lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
469 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
|
470 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
471 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
|
472 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
|
473 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
474 status = pthread_mutex_lock( &thelock->mut ); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
475 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
|
476 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
477 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
|
478 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
|
479 } 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
|
480 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
|
481 } else { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
482 struct timespec ts; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
483 if (microseconds > 0) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
484 MICROSECONDS_TO_TIMESPEC(microseconds, ts); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
485 /* 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
|
486 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
487 /* 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
|
488 * protocol */ |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
489 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
|
490 while (success == PY_LOCK_FAILURE) { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
491 if (microseconds > 0) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
492 status = pthread_cond_timedwait( |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
493 &thelock->lock_released, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
494 &thelock->mut, &ts); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
495 if (status == ETIMEDOUT) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
496 break; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
497 CHECK_STATUS("pthread_cond_timed_wait"); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
498 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
499 else { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
500 status = pthread_cond_wait( |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
501 &thelock->lock_released, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
502 &thelock->mut); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
503 CHECK_STATUS("pthread_cond_wait"); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
504 } |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
505 |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
506 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
|
507 /* 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
|
508 * 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
|
509 * it and retry. */ |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
510 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
|
511 break; |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
512 } 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
|
513 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
|
514 } else { |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
515 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
|
516 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
517 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
518 } |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
519 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
|
520 status = pthread_mutex_unlock( &thelock->mut ); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
521 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
|
522 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
523 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
|
524 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
|
525 lock, microseconds, intr_flag, success)); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
526 return success; |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
527 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
528 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
529 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
530 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
|
531 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
532 pthread_lock *thelock = (pthread_lock *)lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
533 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
|
534 |
|
84205
f2e373ddfa00
Issue #18256: Compilation fix for recent AIX releases. Patch by David Edelsohn.
Antoine Pitrou <solipsis@pitrou.net>
parents:
80678
diff
changeset
|
535 (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
|
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 /* 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
|
544 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
|
545 CHECK_STATUS("pthread_cond_signal"); |
|
77365
6d146e2ae9a9
Signal condition variables with the mutex held. Destroy condition variables
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
75597
diff
changeset
|
546 |
|
6d146e2ae9a9
Signal condition variables with the mutex held. Destroy condition variables
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
75597
diff
changeset
|
547 status = pthread_mutex_unlock( &thelock->mut ); |
|
6d146e2ae9a9
Signal condition variables with the mutex held. Destroy condition variables
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
75597
diff
changeset
|
548 CHECK_STATUS("pthread_mutex_unlock[3]"); |
|
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:
37168
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:
37168
diff
changeset
|
559 /* set the thread stack size. |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37168
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:
37168
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:
37168
diff
changeset
|
562 */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37168
diff
changeset
|
563 static int |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37168
diff
changeset
|
564 _pythread_pthread_set_stacksize(size_t size) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37168
diff
changeset
|
565 { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37168
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:
37168
diff
changeset
|
570 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37168
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:
37168
diff
changeset
|
577 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37168
diff
changeset
|
578 #if defined(THREAD_STACK_SIZE) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37168
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:
37168
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:
37168
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:
37168
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:
37168
diff
changeset
|
599 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37168
diff
changeset
|
600 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37168
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 {} |
