Mercurial > cpython-lru_cache-weakref
annotate Python/thread_pthread.h @ 78758:ca4bf8e10bc0
Issue #15316: Let exceptions raised during imports triggered by the
fromlist of __import__ propagate.
The problem previously was that if something listed in fromlist didn't
exist then that's okay. The fix for that was too broad in terms of
catching ImportError.
The trick with the solution to this issue is that the proper
refactoring of import thanks to importlib doesn't allow for a way to
distinguish (portably) between an ImportError because finders couldn't
find a loader, or a loader raised the exception. In Python 3.4 the
hope is to introduce a new exception (e.g. ModuleNotFound) to make it
clean to differentiate why ImportError was raised.
| author | Brett Cannon <brett@python.org> |
|---|---|
| date | Fri, 24 Aug 2012 18:25:59 -0400 |
| parents | 6d146e2ae9a9 |
| children | 470785a9fdd5 |
| rev | line source |
|---|---|
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 |
|
3663
07164d30429d
Got rid of florida hack and made it work with Solaris 2.5 pthreads.
Guido van Rossum <guido@python.org>
parents:
2097
diff
changeset
|
2 /* Posix threads interface */ |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 |
|
3663
07164d30429d
Got rid of florida hack and made it work with Solaris 2.5 pthreads.
Guido van Rossum <guido@python.org>
parents:
2097
diff
changeset
|
4 #include <stdlib.h> |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
5 #include <string.h> |
|
25545
3731be28e1a3
Patch #618347: Work around Solaris 2.6 pthread.h bug. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
22341
diff
changeset
|
6 #if defined(__APPLE__) || defined(HAVE_PTHREAD_DESTRUCTOR) |
|
21724
884e57bf3ada
Workaround for what is probably a problem in Apple's gcc: <pthread.h> fails
Jack Jansen <jack.jansen@cwi.nl>
parents:
20922
diff
changeset
|
7 #define destructor xxdestructor |
|
884e57bf3ada
Workaround for what is probably a problem in Apple's gcc: <pthread.h> fails
Jack Jansen <jack.jansen@cwi.nl>
parents:
20922
diff
changeset
|
8 #endif |
|
3663
07164d30429d
Got rid of florida hack and made it work with Solaris 2.5 pthreads.
Guido van Rossum <guido@python.org>
parents:
2097
diff
changeset
|
9 #include <pthread.h> |
|
25545
3731be28e1a3
Patch #618347: Work around Solaris 2.6 pthread.h bug. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
22341
diff
changeset
|
10 #if defined(__APPLE__) || defined(HAVE_PTHREAD_DESTRUCTOR) |
|
21724
884e57bf3ada
Workaround for what is probably a problem in Apple's gcc: <pthread.h> fails
Jack Jansen <jack.jansen@cwi.nl>
parents:
20922
diff
changeset
|
11 #undef destructor |
|
884e57bf3ada
Workaround for what is probably a problem in Apple's gcc: <pthread.h> fails
Jack Jansen <jack.jansen@cwi.nl>
parents:
20922
diff
changeset
|
12 #endif |
|
20398
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
13 #include <signal.h> |
|
22341
2548e2f323fa
Document that _POSIX_SEMAPHORES is predefined.
Martin v. Löwis <martin@v.loewis.de>
parents:
22339
diff
changeset
|
14 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
15 /* The POSIX spec requires that use of pthread_attr_setstacksize |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
16 be conditional on _POSIX_THREAD_ATTR_STACKSIZE being defined. */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
17 #ifdef _POSIX_THREAD_ATTR_STACKSIZE |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
18 #ifndef THREAD_STACK_SIZE |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
19 #define THREAD_STACK_SIZE 0 /* use default stack size */ |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
20 #endif |
|
70448
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
21 |
|
75596
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
22 /* The default stack size for new threads on OSX and BSD is small enough that |
|
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
23 * we'll get hard crashes instead of 'maximum recursion depth exceeded' |
|
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
24 * exceptions. |
|
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
25 * |
|
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
26 * The default stack sizes below are the empirically determined minimal stack |
|
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
27 * sizes where a simple recursive function doesn't cause a hard crash. |
|
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
28 */ |
|
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
29 #if defined(__APPLE__) && defined(THREAD_STACK_SIZE) && THREAD_STACK_SIZE == 0 |
|
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
30 #undef THREAD_STACK_SIZE |
|
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
31 #define THREAD_STACK_SIZE 0x500000 |
|
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
32 #endif |
|
246e681a4272
Issue #14184: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
70449
diff
changeset
|
33 #if defined(__FreeBSD__) && defined(THREAD_STACK_SIZE) && THREAD_STACK_SIZE == 0 |
|
70448
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
34 #undef THREAD_STACK_SIZE |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
35 #define THREAD_STACK_SIZE 0x400000 |
|
0cded2f2cea3
Issue #9670: Increase the default stack size for secondary threads on
Ned Deily <nad@acm.org>
parents:
69225
diff
changeset
|
36 #endif |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
37 /* for safety, ensure a viable minimum stacksize */ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
38 #define THREAD_STACK_MIN 0x8000 /* 32kB */ |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
39 #else /* !_POSIX_THREAD_ATTR_STACKSIZE */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
40 #ifdef THREAD_STACK_SIZE |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
41 #error "THREAD_STACK_SIZE defined but _POSIX_THREAD_ATTR_STACKSIZE undefined" |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
42 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
43 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
44 |
|
22341
2548e2f323fa
Document that _POSIX_SEMAPHORES is predefined.
Martin v. Löwis <martin@v.loewis.de>
parents:
22339
diff
changeset
|
45 /* The POSIX spec says that implementations supporting the sem_* |
|
2548e2f323fa
Document that _POSIX_SEMAPHORES is predefined.
Martin v. Löwis <martin@v.loewis.de>
parents:
22339
diff
changeset
|
46 family of functions must indicate this by defining |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
47 _POSIX_SEMAPHORES. */ |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
48 #ifdef _POSIX_SEMAPHORES |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
49 /* On FreeBSD 4.x, _POSIX_SEMAPHORES is defined empty, so |
|
34824
a50ffe65911b
Add 0 to _POSIX_SEMAPHORES.
Martin v. Löwis <martin@v.loewis.de>
parents:
34762
diff
changeset
|
50 we need to add 0 to make it work there as well. */ |
|
a50ffe65911b
Add 0 to _POSIX_SEMAPHORES.
Martin v. Löwis <martin@v.loewis.de>
parents:
34762
diff
changeset
|
51 #if (_POSIX_SEMAPHORES+0) == -1 |
|
34762
fcb507414c41
Patch #1163249 - Correctly handle _POSIX_SEMAPHORES == -1 to mean no
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32526
diff
changeset
|
52 #define HAVE_BROKEN_POSIX_SEMAPHORES |
|
fcb507414c41
Patch #1163249 - Correctly handle _POSIX_SEMAPHORES == -1 to mean no
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32526
diff
changeset
|
53 #else |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
54 #include <semaphore.h> |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
55 #include <errno.h> |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
56 #endif |
|
34762
fcb507414c41
Patch #1163249 - Correctly handle _POSIX_SEMAPHORES == -1 to mean no
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32526
diff
changeset
|
57 #endif |
|
3663
07164d30429d
Got rid of florida hack and made it work with Solaris 2.5 pthreads.
Guido van Rossum <guido@python.org>
parents:
2097
diff
changeset
|
58 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35607
diff
changeset
|
59 /* Before FreeBSD 5.4, system scope threads was very limited resource |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35607
diff
changeset
|
60 in default setting. So the process scope is preferred to get |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35607
diff
changeset
|
61 enough number of threads to work. */ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35607
diff
changeset
|
62 #ifdef __FreeBSD__ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35607
diff
changeset
|
63 #include <osreldate.h> |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35607
diff
changeset
|
64 #if __FreeBSD_version >= 500000 && __FreeBSD_version < 504101 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35607
diff
changeset
|
65 #undef PTHREAD_SYSTEM_SCHED_SUPPORTED |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35607
diff
changeset
|
66 #endif |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35607
diff
changeset
|
67 #endif |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35607
diff
changeset
|
68 |
|
26598
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
69 #if !defined(pthread_attr_default) |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
70 # define pthread_attr_default ((pthread_attr_t *)NULL) |
|
26598
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
71 #endif |
|
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
72 #if !defined(pthread_mutexattr_default) |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
73 # define pthread_mutexattr_default ((pthread_mutexattr_t *)NULL) |
|
26598
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
74 #endif |
|
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
75 #if !defined(pthread_condattr_default) |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
76 # define pthread_condattr_default ((pthread_condattr_t *)NULL) |
|
3965
9c05ff6fb0a4
Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents:
3663
diff
changeset
|
77 #endif |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
79 |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
80 /* Whether or not to use semaphores directly rather than emulating them with |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
81 * mutexes and condition variables: |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
82 */ |
|
65205
ed5e598da150
Issue #10062: Allow building on platforms which do not have sem_timedwait.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64844
diff
changeset
|
83 #if (defined(_POSIX_SEMAPHORES) && !defined(HAVE_BROKEN_POSIX_SEMAPHORES) && \ |
|
ed5e598da150
Issue #10062: Allow building on platforms which do not have sem_timedwait.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64844
diff
changeset
|
84 defined(HAVE_SEM_TIMEDWAIT)) |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
85 # define USE_SEMAPHORES |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
86 #else |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
87 # undef USE_SEMAPHORES |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
88 #endif |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
89 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
90 |
|
20398
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
91 /* On platforms that don't use standard POSIX threads pthread_sigmask() |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
92 * isn't present. DEC threads uses sigprocmask() instead as do most |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
93 * other UNIX International compliant systems that don't have the full |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
94 * pthread implementation. |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
95 */ |
|
29972
a408ac5527c3
Patch 775605: Cygwin pthread_sigmask() workaround patch
Jason Tishler <jason@tishler.net>
parents:
28687
diff
changeset
|
96 #if defined(HAVE_PTHREAD_SIGMASK) && !defined(HAVE_BROKEN_PTHREAD_SIGMASK) |
|
20398
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
97 # define SET_THREAD_SIGMASK pthread_sigmask |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
98 #else |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
99 # define SET_THREAD_SIGMASK sigprocmask |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
100 #endif |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
101 |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
102 |
|
60598
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
103 /* We assume all modern POSIX systems have gettimeofday() */ |
|
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
104 #ifdef GETTIMEOFDAY_NO_TZ |
|
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
105 #define GETTIMEOFDAY(ptv) gettimeofday(ptv) |
|
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
106 #else |
|
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
107 #define GETTIMEOFDAY(ptv) gettimeofday(ptv, (struct timezone *)NULL) |
|
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
108 #endif |
|
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
109 |
|
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
110 #define MICROSECONDS_TO_TIMESPEC(microseconds, ts) \ |
|
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
111 do { \ |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
112 struct timeval tv; \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
113 GETTIMEOFDAY(&tv); \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
114 tv.tv_usec += microseconds % 1000000; \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
115 tv.tv_sec += microseconds / 1000000; \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
116 tv.tv_sec += tv.tv_usec / 1000000; \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
117 tv.tv_usec %= 1000000; \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
118 ts.tv_sec = tv.tv_sec; \ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
119 ts.tv_nsec = tv.tv_usec * 1000; \ |
|
60598
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
120 } while(0) |
|
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
121 |
|
01d1fd775d16
Issue #7316: the acquire() method of lock objects in the :mod:`threading`
Antoine Pitrou <solipsis@pitrou.net>
parents:
59089
diff
changeset
|
122 |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
123 /* A pthread mutex isn't sufficient to model the Python lock type |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
124 * because, according to Draft 5 of the docs (P1003.4a/D5), both of the |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
125 * following are undefined: |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
126 * -> a thread tries to lock a mutex it already has locked |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
127 * -> a thread tries to unlock a mutex locked by a different thread |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
128 * pthread mutexes are designed for serializing threads over short pieces |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
129 * of code anyway, so wouldn't be an appropriate implementation of |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
130 * Python's locks regardless. |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
131 * |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
132 * The pthread_lock struct implements a Python lock as a "locked?" bit |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
133 * and a <condition, mutex> pair. In general, if the bit can be acquired |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
134 * instantly, it is, else the pair is used to block the thread until the |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
135 * bit is cleared. 9 May 1994 tim@ksr.com |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
136 */ |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
137 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 typedef struct { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
139 char locked; /* 0=unlocked, 1=locked */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
140 /* a <cond, mutex> pair to handle an acquire of a locked lock */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
141 pthread_cond_t lock_released; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
142 pthread_mutex_t mut; |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
143 } pthread_lock; |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
144 |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
145 #define CHECK_STATUS(name) if (status != 0) { perror(name); error = 1; } |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
146 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
147 /* |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
148 * Initialization. |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 */ |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
150 |
|
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__) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
173 pthread_init(); |
|
9079
4d2cb212c8d1
Apparently on AIX when using gcc you need to call pthread_init()
Guido van Rossum <guido@python.org>
parents:
9070
diff
changeset
|
174 #endif |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
175 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
176 |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
177 #endif /* !_HAVE_BSDI */ |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
178 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
179 /* |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
180 * Thread support. |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
181 */ |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
182 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
183 |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
184 long |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
185 PyThread_start_new_thread(void (*func)(void *), void *arg) |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
186 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
187 pthread_t th; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
188 int status; |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
189 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
190 pthread_attr_t attrs; |
|
19549
11a758c56027
GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents:
14375
diff
changeset
|
191 #endif |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
192 #if defined(THREAD_STACK_SIZE) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
193 size_t tss; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
194 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
195 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
196 dprintf(("PyThread_start_new_thread called\n")); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
197 if (!initialized) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
198 PyThread_init_thread(); |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
199 |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
200 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
201 if (pthread_attr_init(&attrs) != 0) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
202 return -1; |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
203 #endif |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
204 #if defined(THREAD_STACK_SIZE) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
205 tss = (_pythread_stacksize != 0) ? _pythread_stacksize |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
206 : THREAD_STACK_SIZE; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
207 if (tss != 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
208 if (pthread_attr_setstacksize(&attrs, tss) != 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
209 pthread_attr_destroy(&attrs); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
210 return -1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
211 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
212 } |
|
19549
11a758c56027
GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents:
14375
diff
changeset
|
213 #endif |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35607
diff
changeset
|
214 #if defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
215 pthread_attr_setscope(&attrs, PTHREAD_SCOPE_SYSTEM); |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
216 #endif |
|
20398
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
217 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
218 status = pthread_create(&th, |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
219 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
220 &attrs, |
|
19549
11a758c56027
GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents:
14375
diff
changeset
|
221 #else |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
222 (pthread_attr_t*)NULL, |
|
19549
11a758c56027
GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents:
14375
diff
changeset
|
223 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
224 (void* (*)(void *))func, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
225 (void *)arg |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
226 ); |
|
20398
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
227 |
|
20922
7a991d012cd6
Fix memory leak. This is part of SF patch #478006.
Fred Drake <fdrake@acm.org>
parents:
20468
diff
changeset
|
228 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
229 pthread_attr_destroy(&attrs); |
|
19549
11a758c56027
GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents:
14375
diff
changeset
|
230 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
231 if (status != 0) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
232 return -1; |
|
28687
40d287c3d906
Patch #716969: Detect thread creation failure. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28673
diff
changeset
|
233 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
234 pthread_detach(th); |
|
28687
40d287c3d906
Patch #716969: Detect thread creation failure. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28673
diff
changeset
|
235 |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
236 #if SIZEOF_PTHREAD_T <= SIZEOF_LONG |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
237 return (long) th; |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
238 #else |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
239 return (long) *(long *) &th; |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
240 #endif |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
241 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
242 |
|
14144
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
243 /* XXX This implementation is considered (to quote Tim Peters) "inherently |
|
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
244 hosed" because: |
| 31611 | 245 - It does not guarantee the promise that a non-zero integer is returned. |
|
14144
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
246 - The cast to long is inherently unsafe. |
|
68457
15b090c9442a
Issue #11495: OSF support is eliminated. It was deprecated in Python 3.2
Jesus Cea <jcea@jcea.es>
parents:
68257
diff
changeset
|
247 - 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
|
248 */ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
249 long |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
250 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
|
251 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
252 volatile pthread_t threadid; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
253 if (!initialized) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
254 PyThread_init_thread(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
255 threadid = pthread_self(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
256 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
|
257 } |
|
7e5f97bab1e6
ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents:
1629
diff
changeset
|
258 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
259 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
260 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
|
261 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
262 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
|
263 if (!initialized) |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
264 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
|
265 pthread_exit(0); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
266 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
267 |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
268 #ifdef USE_SEMAPHORES |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
269 |
|
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 * Lock support. |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
272 */ |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
273 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
274 PyThread_type_lock |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
275 PyThread_allocate_lock(void) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
276 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
277 sem_t *lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
278 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
|
279 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
280 dprintf(("PyThread_allocate_lock called\n")); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
281 if (!initialized) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
282 PyThread_init_thread(); |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
283 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
284 lock = (sem_t *)malloc(sizeof(sem_t)); |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
285 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
286 if (lock) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
287 status = sem_init(lock,0,1); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
288 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
|
289 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
290 if (error) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
291 free((void *)lock); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
292 lock = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
293 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
294 } |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
295 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
296 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
|
297 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
|
298 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
299 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
300 void |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
301 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
|
302 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
303 sem_t *thelock = (sem_t *)lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
304 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
|
305 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
306 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
|
307 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
308 if (!thelock) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
309 return; |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
310 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
311 status = sem_destroy(thelock); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
312 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
|
313 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
314 free((void *)thelock); |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
315 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
316 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
317 /* |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
318 * 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
|
319 * 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
|
320 * 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
|
321 * either. |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
322 */ |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
323 static int |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
324 fix_status(int status) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
325 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
326 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
|
327 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
328 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
329 PyLockStatus |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
330 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
|
331 int intr_flag) |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
332 { |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
333 PyLockStatus success; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
334 sem_t *thelock = (sem_t *)lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
335 int status, error = 0; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
336 struct timespec ts; |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
337 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
338 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
|
339 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
|
340 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
341 if (microseconds > 0) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
342 MICROSECONDS_TO_TIMESPEC(microseconds, ts); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
343 do { |
|
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 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
|
346 else if (microseconds == 0) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
347 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
|
348 else |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
349 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
|
350 /* 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
|
351 notified. */ |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
352 } 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
|
353 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
354 /* 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
|
355 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
|
356 if (microseconds > 0) { |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
357 if (status != ETIMEDOUT) |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
358 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
|
359 } |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
360 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
|
361 if (status != EAGAIN) |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
362 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
|
363 } |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
364 else { |
|
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_wait"); |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
366 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
367 } |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
368 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
369 if (status == 0) { |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
370 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
|
371 } 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
|
372 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
|
373 } else { |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
374 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
|
375 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
376 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
377 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
|
378 lock, microseconds, intr_flag, success)); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
379 return success; |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
380 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
381 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
382 void |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
383 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
|
384 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
385 sem_t *thelock = (sem_t *)lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
386 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
|
387 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
388 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
|
389 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
390 status = sem_post(thelock); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
391 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
|
392 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
393 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
394 #else /* USE_SEMAPHORES */ |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
395 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
396 /* |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
397 * Lock support. |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
398 */ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
399 PyThread_type_lock |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
400 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
|
401 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
402 pthread_lock *lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
403 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
|
404 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
405 dprintf(("PyThread_allocate_lock called\n")); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
406 if (!initialized) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
407 PyThread_init_thread(); |
|
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 lock = (pthread_lock *) malloc(sizeof(pthread_lock)); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
410 if (lock) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
411 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
|
412 lock->locked = 0; |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
413 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
414 status = pthread_mutex_init(&lock->mut, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
415 pthread_mutexattr_default); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
416 CHECK_STATUS("pthread_mutex_init"); |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
417 /* 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
|
418 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
|
419 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
|
420 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
|
421 will cause errors. */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
422 _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
|
423 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
424 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
|
425 pthread_condattr_default); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
426 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
|
427 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
428 if (error) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
429 free((void *)lock); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
430 lock = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
431 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
432 } |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
433 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
434 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
|
435 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
|
436 } |
|
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 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
439 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
|
440 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
441 pthread_lock *thelock = (pthread_lock *)lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
442 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
|
443 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
444 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
|
445 |
|
77365
6d146e2ae9a9
Signal condition variables with the mutex held. Destroy condition variables
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
75597
diff
changeset
|
446 /* 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
|
447 * 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
|
448 */ |
|
6d146e2ae9a9
Signal condition variables with the mutex held. Destroy condition variables
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
75597
diff
changeset
|
449 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
|
450 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
|
451 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
452 status = pthread_mutex_destroy( &thelock->mut ); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
453 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
|
454 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
455 free((void *)thelock); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
456 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
457 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
458 PyLockStatus |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
459 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
|
460 int intr_flag) |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
461 { |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
462 PyLockStatus success; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
463 pthread_lock *thelock = (pthread_lock *)lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
464 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
|
465 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
466 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
|
467 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
|
468 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
469 status = pthread_mutex_lock( &thelock->mut ); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
470 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
|
471 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
472 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
|
473 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
|
474 } 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
|
475 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
|
476 } else { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
477 struct timespec ts; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
478 if (microseconds > 0) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
479 MICROSECONDS_TO_TIMESPEC(microseconds, ts); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
480 /* 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
|
481 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
482 /* 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
|
483 * protocol */ |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
484 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
|
485 while (success == PY_LOCK_FAILURE) { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
486 if (microseconds > 0) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
487 status = pthread_cond_timedwait( |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
488 &thelock->lock_released, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
489 &thelock->mut, &ts); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
490 if (status == ETIMEDOUT) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
491 break; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
492 CHECK_STATUS("pthread_cond_timed_wait"); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
493 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
494 else { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
495 status = pthread_cond_wait( |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
496 &thelock->lock_released, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
497 &thelock->mut); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
498 CHECK_STATUS("pthread_cond_wait"); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61184
diff
changeset
|
499 } |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
500 |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
501 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
|
502 /* 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
|
503 * 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
|
504 * it and retry. */ |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
505 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
|
506 break; |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
507 } 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
|
508 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
|
509 } else { |
|
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_FAILURE; |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
511 } |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
512 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
513 } |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
514 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
|
515 status = pthread_mutex_unlock( &thelock->mut ); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
516 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
|
517 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
518 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
|
519 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
|
520 lock, microseconds, intr_flag, success)); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
521 return success; |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
522 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
523 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
524 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
525 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
|
526 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
527 pthread_lock *thelock = (pthread_lock *)lock; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
528 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
|
529 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
530 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
|
531 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
532 status = pthread_mutex_lock( &thelock->mut ); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
533 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
|
534 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
535 thelock->locked = 0; |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
536 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
537 /* 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
|
538 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
|
539 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
|
540 |
|
6d146e2ae9a9
Signal condition variables with the mutex held. Destroy condition variables
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
75597
diff
changeset
|
541 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
|
542 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
|
543 } |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
544 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
545 #endif /* USE_SEMAPHORES */ |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
546 |
|
66946
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
547 int |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
548 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
|
549 { |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
550 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
|
551 } |
|
b750c45a772c
Issue #8844: Regular and recursive lock acquisitions can now be interrupted
Antoine Pitrou <solipsis@pitrou.net>
parents:
65205
diff
changeset
|
552 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
553 /* set the thread stack size. |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
554 * Return 0 if size is valid, -1 if size is invalid, |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
555 * -2 if setting stack size is not supported. |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
556 */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
557 static int |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
558 _pythread_pthread_set_stacksize(size_t size) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
559 { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
560 #if defined(THREAD_STACK_SIZE) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
561 pthread_attr_t attrs; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
562 size_t tss_min; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
563 int rc = 0; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
564 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
565 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
566 /* set to default */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
567 if (size == 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
568 _pythread_stacksize = 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
569 return 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
570 } |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
571 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
572 #if defined(THREAD_STACK_SIZE) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
573 #if defined(PTHREAD_STACK_MIN) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
574 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
|
575 : THREAD_STACK_MIN; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
576 #else |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
577 tss_min = THREAD_STACK_MIN; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
578 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
579 if (size >= tss_min) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
580 /* 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
|
581 if (pthread_attr_init(&attrs) == 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
582 rc = pthread_attr_setstacksize(&attrs, size); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
583 pthread_attr_destroy(&attrs); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
584 if (rc == 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
585 _pythread_stacksize = size; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
586 return 0; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
587 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
588 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
589 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
590 return -1; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
591 #else |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
592 return -2; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
593 #endif |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
594 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
595 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39442
diff
changeset
|
596 #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
|
597 |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
598 #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
|
599 |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
600 int |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
601 PyThread_create_key(void) |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
602 { |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
603 pthread_key_t key; |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
604 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
|
605 return fail ? -1 : key; |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
606 } |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
607 |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
608 void |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
609 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
|
610 { |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
611 pthread_key_delete(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_value(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_setspecific(key, NULL); |
|
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 int |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
621 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
|
622 { |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
623 int fail; |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
624 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
|
625 if (oldValue != NULL) |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
626 return 0; |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
627 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
|
628 return fail ? -1 : 0; |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
629 } |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
630 |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
631 void * |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
632 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
|
633 { |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
634 return pthread_getspecific(key); |
|
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_ReInitTLS(void) |
|
8e428b8e7d81
issue 9786 Native TLS support for pthreads
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
61466
diff
changeset
|
639 {} |
