Mercurial > cpython-lru_cache-weakref
annotate Python/thread_pthread.h @ 28653:56006d97bcef legacy-trunk
_Py_PrintReferences(): Changed to print object address at start of each
new line.
New pvt API function _Py_PrintReferenceAddresses(): Prints only the
addresses and refcnts of the live objects. This is always safe to call,
because it has no dependence on Python's C API.
Py_Finalize(): If envar PYTHONDUMPREFS is set, call (the new)
_Py_PrintReferenceAddresses() right before dumping final pymalloc stats.
We can't print the reprs of the objects here because too much of the
interpreter has been shut down. You need to correlate the addresses
displayed here with the object reprs printed by the earlier
PYTHONDUMPREFS call to _Py_PrintReferences().
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Thu, 17 Apr 2003 19:52:29 +0000 |
| parents | 1562c1e10b49 |
| children | c1ba50790c83 |
| 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 |
|
2548e2f323fa
Document that _POSIX_SEMAPHORES is predefined.
Martin v. Löwis <martin@v.loewis.de>
parents:
22339
diff
changeset
|
15 /* 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
|
16 family of functions must indicate this by defining |
|
2548e2f323fa
Document that _POSIX_SEMAPHORES is predefined.
Martin v. Löwis <martin@v.loewis.de>
parents:
22339
diff
changeset
|
17 _POSIX_SEMAPHORES. */ |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
18 #ifdef _POSIX_SEMAPHORES |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
19 #include <semaphore.h> |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
20 #include <errno.h> |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
21 #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
|
22 |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
23 |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
24 /* try to determine what version of the Pthread Standard is installed. |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
25 * this is important, since all sorts of parameter types changed from |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
26 * draft to draft and there are several (incompatible) drafts in |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
27 * common use. these macros are a start, at least. |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
28 * 12 May 1997 -- david arnold <davida@pobox.com> |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
29 */ |
|
3965
9c05ff6fb0a4
Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents:
3663
diff
changeset
|
30 |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
31 #if defined(__ultrix) && defined(__mips) && defined(_DECTHREADS_) |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
32 /* _DECTHREADS_ is defined in cma.h which is included by pthread.h */ |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
33 # define PY_PTHREAD_D4 |
|
26499
76f79bb36fc7
Add compile-time errors for unsupported systems.
Martin v. Löwis <martin@v.loewis.de>
parents:
25545
diff
changeset
|
34 # error Systems with PY_PTHREAD_D4 are unsupported. See README. |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
35 |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
36 #elif defined(__osf__) && defined (__alpha) |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
37 /* _DECTHREADS_ is defined in cma.h which is included by pthread.h */ |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
38 # if !defined(_PTHREAD_ENV_ALPHA) || defined(_PTHREAD_USE_D4) || defined(PTHREAD_USE_D4) |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
39 # define PY_PTHREAD_D4 |
|
26499
76f79bb36fc7
Add compile-time errors for unsupported systems.
Martin v. Löwis <martin@v.loewis.de>
parents:
25545
diff
changeset
|
40 # error Systems with PY_PTHREAD_D4 are unsupported. See README. |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
41 # else |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
42 # define PY_PTHREAD_STD |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
43 # endif |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
44 |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
45 #elif defined(_AIX) |
|
3965
9c05ff6fb0a4
Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents:
3663
diff
changeset
|
46 /* SCHED_BG_NP is defined if using AIX DCE pthreads |
|
9c05ff6fb0a4
Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents:
3663
diff
changeset
|
47 * but it is unsupported by AIX 4 pthreads. Default |
|
9c05ff6fb0a4
Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents:
3663
diff
changeset
|
48 * attributes for AIX 4 pthreads equal to NULL. For |
|
9c05ff6fb0a4
Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents:
3663
diff
changeset
|
49 * AIX DCE pthreads they should be left unchanged. |
|
9c05ff6fb0a4
Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents:
3663
diff
changeset
|
50 */ |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
51 # if !defined(SCHED_BG_NP) |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
52 # define PY_PTHREAD_STD |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
53 # else |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
54 # define PY_PTHREAD_D7 |
|
26499
76f79bb36fc7
Add compile-time errors for unsupported systems.
Martin v. Löwis <martin@v.loewis.de>
parents:
25545
diff
changeset
|
55 # error Systems with PY_PTHREAD_D7 are unsupported. See README. |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
56 # endif |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
57 |
|
5599
b5e51ae9f832
DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents:
5529
diff
changeset
|
58 #elif defined(__DGUX) |
|
b5e51ae9f832
DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents:
5529
diff
changeset
|
59 # define PY_PTHREAD_D6 |
|
26499
76f79bb36fc7
Add compile-time errors for unsupported systems.
Martin v. Löwis <martin@v.loewis.de>
parents:
25545
diff
changeset
|
60 # error Systems with PY_PTHREAD_D6 are unsupported. See README. |
|
5700
60fca4783793
Add default case (standard conformance) to avoid piling up
Guido van Rossum <guido@python.org>
parents:
5599
diff
changeset
|
61 |
|
8343
1b4a37f37345
Improved version of patch for HPUX from David Arnold.
Guido van Rossum <guido@python.org>
parents:
8250
diff
changeset
|
62 #elif defined(__hpux) && defined(_DECTHREADS_) |
|
8250
50d35bdf2042
Support HPUX 10.20 DCE threads.
Guido van Rossum <guido@python.org>
parents:
7982
diff
changeset
|
63 # define PY_PTHREAD_D4 |
|
26499
76f79bb36fc7
Add compile-time errors for unsupported systems.
Martin v. Löwis <martin@v.loewis.de>
parents:
25545
diff
changeset
|
64 # error Systems with PY_PTHREAD_D4 are unsupported. See README. |
|
8250
50d35bdf2042
Support HPUX 10.20 DCE threads.
Guido van Rossum <guido@python.org>
parents:
7982
diff
changeset
|
65 |
|
5700
60fca4783793
Add default case (standard conformance) to avoid piling up
Guido van Rossum <guido@python.org>
parents:
5599
diff
changeset
|
66 #else /* Default case */ |
|
60fca4783793
Add default case (standard conformance) to avoid piling up
Guido van Rossum <guido@python.org>
parents:
5599
diff
changeset
|
67 # define PY_PTHREAD_STD |
|
60fca4783793
Add default case (standard conformance) to avoid piling up
Guido van Rossum <guido@python.org>
parents:
5599
diff
changeset
|
68 |
|
3965
9c05ff6fb0a4
Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents:
3663
diff
changeset
|
69 #endif |
|
9c05ff6fb0a4
Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents:
3663
diff
changeset
|
70 |
|
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
|
71 #ifdef USE_GUSI |
|
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
|
72 /* The Macintosh GUSI I/O library sets the stackspace to |
|
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
|
73 ** 20KB, much too low. We up it to 64K. |
|
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
|
74 */ |
|
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
|
75 #define THREAD_STACK_SIZE 0x10000 |
|
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
|
76 #endif |
|
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
|
77 |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
78 |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
79 /* set default attribute object for different versions */ |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
80 |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
81 #if defined(PY_PTHREAD_D4) || defined(PY_PTHREAD_D7) |
|
26598
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
82 #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
|
83 # define pthread_attr_default pthread_attr_default |
|
26598
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
84 #endif |
|
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
85 #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
|
86 # define pthread_mutexattr_default pthread_mutexattr_default |
|
26598
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
87 #endif |
|
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
88 #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
|
89 # define pthread_condattr_default pthread_condattr_default |
|
26598
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
90 #endif |
|
5599
b5e51ae9f832
DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents:
5529
diff
changeset
|
91 #elif defined(PY_PTHREAD_STD) || defined(PY_PTHREAD_D6) |
|
26598
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
92 #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
|
93 # 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
|
94 #endif |
|
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
95 #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
|
96 # 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
|
97 #endif |
|
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
98 #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
|
99 # define pthread_condattr_default ((pthread_condattr_t *)NULL) |
|
3965
9c05ff6fb0a4
Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents:
3663
diff
changeset
|
100 #endif |
|
26598
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
101 #endif |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
102 |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
103 |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
104 /* 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
|
105 * mutexes and condition variables: |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
106 */ |
|
27320
1562c1e10b49
Don't use Posix semaphores on Solaris 8. Fixes #662787.
Martin v. Löwis <martin@v.loewis.de>
parents:
26598
diff
changeset
|
107 #if defined(_POSIX_SEMAPHORES) && !defined(HAVE_BROKEN_POSIX_SEMAPHORES) |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
108 # define USE_SEMAPHORES |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
109 #else |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
110 # undef USE_SEMAPHORES |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
111 #endif |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
112 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
113 |
|
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
|
114 /* 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
|
115 * 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
|
116 * 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
|
117 * 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
|
118 */ |
|
20431
cee0fe5fce11
Do not define _POSIX_THREADS if unistd.h defines it.
Martin v. Löwis <martin@v.loewis.de>
parents:
20398
diff
changeset
|
119 #ifdef HAVE_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
|
120 # 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
|
121 #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
|
122 # 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
|
123 #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
|
124 |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
125 |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
126 /* 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
|
127 * 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
|
128 * following are undefined: |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
129 * -> 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
|
130 * -> 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
|
131 * 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
|
132 * 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
|
133 * 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
|
134 * |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
135 * 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
|
136 * 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
|
137 * 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
|
138 * 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
|
139 */ |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
140 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
141 typedef struct { |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
142 char locked; /* 0=unlocked, 1=locked */ |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
143 /* a <cond, mutex> pair to handle an acquire of a locked lock */ |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
144 pthread_cond_t lock_released; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
145 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
|
146 } pthread_lock; |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
147 |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
148 #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
|
149 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
150 /* |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
151 * Initialization. |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
152 */ |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
153 |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
154 #ifdef _HAVE_BSDI |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
155 static |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
156 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
|
157 { |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
158 } |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
159 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
160 static void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
161 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
|
162 { |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
163 /* DO AN INIT BY STARTING THE THREAD */ |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
164 static int dummy = 0; |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
165 pthread_t thread1; |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
166 pthread_create(&thread1, NULL, (void *) _noop, &dummy); |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
167 pthread_join(thread1, NULL); |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
168 } |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
169 |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
170 #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
|
171 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
172 static void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
173 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
|
174 { |
|
9079
4d2cb212c8d1
Apparently on AIX when using gcc you need to call pthread_init()
Guido van Rossum <guido@python.org>
parents:
9070
diff
changeset
|
175 #if defined(_AIX) && defined(__GNUC__) |
|
4d2cb212c8d1
Apparently on AIX when using gcc you need to call pthread_init()
Guido van Rossum <guido@python.org>
parents:
9070
diff
changeset
|
176 pthread_init(); |
|
4d2cb212c8d1
Apparently on AIX when using gcc you need to call pthread_init()
Guido van Rossum <guido@python.org>
parents:
9070
diff
changeset
|
177 #endif |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
178 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
179 |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
180 #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
|
181 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
182 /* |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
183 * Thread support. |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
184 */ |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
185 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
186 |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
187 long |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
188 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
|
189 { |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
190 pthread_t th; |
|
1651
7e5f97bab1e6
ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents:
1629
diff
changeset
|
191 int success; |
|
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
|
192 sigset_t oldmask, newmask; |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
193 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) |
|
19549
11a758c56027
GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents:
14375
diff
changeset
|
194 pthread_attr_t attrs; |
|
11a758c56027
GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents:
14375
diff
changeset
|
195 #endif |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
196 dprintf(("PyThread_start_new_thread called\n")); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
197 if (!initialized) |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
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) |
|
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
|
201 pthread_attr_init(&attrs); |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
202 #endif |
|
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
203 #ifdef THREAD_STACK_SIZE |
|
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
|
204 pthread_attr_setstacksize(&attrs, THREAD_STACK_SIZE); |
|
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
|
205 #endif |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
206 #ifdef PTHREAD_SYSTEM_SCHED_SUPPORTED |
|
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
207 pthread_attr_setscope(&attrs, PTHREAD_SCOPE_SYSTEM); |
|
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
208 #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
|
209 |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
210 /* Mask all signals in the current thread before creating the new |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
211 * thread. This causes the new thread to start with all signals |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
212 * blocked. |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
213 */ |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
214 sigfillset(&newmask); |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
215 SET_THREAD_SIGMASK(SIG_BLOCK, &newmask, &oldmask); |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
216 |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
217 success = pthread_create(&th, |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
218 #if defined(PY_PTHREAD_D4) |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
219 pthread_attr_default, |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
220 (pthread_startroutine_t)func, |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
221 (pthread_addr_t)arg |
|
5599
b5e51ae9f832
DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents:
5529
diff
changeset
|
222 #elif defined(PY_PTHREAD_D6) |
|
b5e51ae9f832
DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents:
5529
diff
changeset
|
223 pthread_attr_default, |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
224 (void* (*)(void *))func, |
|
5599
b5e51ae9f832
DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents:
5529
diff
changeset
|
225 arg |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
226 #elif defined(PY_PTHREAD_D7) |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
227 pthread_attr_default, |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
228 func, |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
229 arg |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
230 #elif defined(PY_PTHREAD_STD) |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
231 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) |
|
19549
11a758c56027
GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents:
14375
diff
changeset
|
232 &attrs, |
|
11a758c56027
GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents:
14375
diff
changeset
|
233 #else |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
234 (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
|
235 #endif |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
236 (void* (*)(void *))func, |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
237 (void *)arg |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
238 #endif |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
239 ); |
|
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
|
240 |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
241 /* Restore signal mask for original thread */ |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
242 SET_THREAD_SIGMASK(SIG_SETMASK, &oldmask, NULL); |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
243 |
|
20922
7a991d012cd6
Fix memory leak. This is part of SF patch #478006.
Fred Drake <fdrake@acm.org>
parents:
20468
diff
changeset
|
244 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) |
|
19549
11a758c56027
GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents:
14375
diff
changeset
|
245 pthread_attr_destroy(&attrs); |
|
11a758c56027
GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents:
14375
diff
changeset
|
246 #endif |
| 10400 | 247 if (success == 0) { |
|
9070
c2cbe9acfc8e
Correct typo in #ifdef: PY_THREAD_D4, should be PY_PTHREAD_D4.
Guido van Rossum <guido@python.org>
parents:
9055
diff
changeset
|
248 #if defined(PY_PTHREAD_D4) || defined(PY_PTHREAD_D6) || defined(PY_PTHREAD_D7) |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
249 pthread_detach(&th); |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
250 #elif defined(PY_PTHREAD_STD) |
|
5395
2c81d7d68ed3
Add detach call so threads are GC'ed.
Guido van Rossum <guido@python.org>
parents:
4994
diff
changeset
|
251 pthread_detach(th); |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
252 #endif |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
253 } |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
254 #if SIZEOF_PTHREAD_T <= SIZEOF_LONG |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
255 return (long) th; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
256 #else |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
257 return (long) *(long *) &th; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
258 #endif |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
259 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
260 |
|
14144
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
261 /* 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
|
262 hosed" because: |
|
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
263 - It does not guanrantee the promise that a non-zero integer is returned. |
|
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
264 - The cast to long is inherently unsafe. |
|
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
265 - It is not clear that the 'volatile' (for AIX?) and ugly casting in the |
|
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
266 latter return statement (for Alpha OSF/1) are any longer necessary. |
|
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
267 */ |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
268 long |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
269 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
|
270 { |
|
9055
5bc64efc65e0
Add a 'volatile' to the declaration of threadid in get_thread_ident().
Guido van Rossum <guido@python.org>
parents:
8343
diff
changeset
|
271 volatile pthread_t threadid; |
|
1651
7e5f97bab1e6
ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents:
1629
diff
changeset
|
272 if (!initialized) |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
273 PyThread_init_thread(); |
| 2097 | 274 /* Jump through some hoops for Alpha OSF/1 */ |
| 275 threadid = pthread_self(); | |
|
14144
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
276 #if SIZEOF_PTHREAD_T <= SIZEOF_LONG |
|
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
277 return (long) threadid; |
|
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
278 #else |
| 2097 | 279 return (long) *(long *) &threadid; |
|
14144
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
280 #endif |
|
1651
7e5f97bab1e6
ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents:
1629
diff
changeset
|
281 } |
|
7e5f97bab1e6
ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents:
1629
diff
changeset
|
282 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
283 static void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
284 do_PyThread_exit_thread(int no_cleanup) |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
285 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
286 dprintf(("PyThread_exit_thread called\n")); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5700
diff
changeset
|
287 if (!initialized) { |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
288 if (no_cleanup) |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
289 _exit(0); |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
290 else |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
291 exit(0); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5700
diff
changeset
|
292 } |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
293 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
294 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
295 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
296 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
|
297 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
298 do_PyThread_exit_thread(0); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
299 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
300 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
301 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
302 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
|
303 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
304 do_PyThread_exit_thread(1); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
305 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
306 |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
307 #ifndef NO_EXIT_PROG |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
308 static void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
309 do_PyThread_exit_prog(int status, int no_cleanup) |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
310 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
311 dprintf(("PyThread_exit_prog(%d) called\n", status)); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
312 if (!initialized) |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
313 if (no_cleanup) |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
314 _exit(status); |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
315 else |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
316 exit(status); |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
317 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
318 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
319 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
320 PyThread_exit_prog(int status) |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
321 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
322 do_PyThread_exit_prog(status, 0); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
323 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
324 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
325 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
326 PyThread__exit_prog(int status) |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
327 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
328 do_PyThread_exit_prog(status, 1); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
329 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
330 #endif /* NO_EXIT_PROG */ |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
331 |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
332 #ifdef USE_SEMAPHORES |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
333 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
334 /* |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
335 * Lock support. |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
336 */ |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
337 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
338 PyThread_type_lock |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
339 PyThread_allocate_lock(void) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
340 { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
341 sem_t *lock; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
342 int status, error = 0; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
343 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
344 dprintf(("PyThread_allocate_lock called\n")); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
345 if (!initialized) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
346 PyThread_init_thread(); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
347 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
348 lock = (sem_t *)malloc(sizeof(sem_t)); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
349 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
350 if (lock) { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
351 status = sem_init(lock,0,1); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
352 CHECK_STATUS("sem_init"); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
353 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
354 if (error) { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
355 free((void *)lock); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
356 lock = NULL; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
357 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
358 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
359 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
360 dprintf(("PyThread_allocate_lock() -> %p\n", lock)); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
361 return (PyThread_type_lock)lock; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
362 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
363 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
364 void |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
365 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
|
366 { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
367 sem_t *thelock = (sem_t *)lock; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
368 int status, error = 0; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
369 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
370 dprintf(("PyThread_free_lock(%p) called\n", lock)); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
371 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
372 if (!thelock) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
373 return; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
374 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
375 status = sem_destroy(thelock); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
376 CHECK_STATUS("sem_destroy"); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
377 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
378 free((void *)thelock); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
379 } |
|
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 /* |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
382 * 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
|
383 * 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
|
384 * 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
|
385 * either. |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
386 */ |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
387 static int |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
388 fix_status(int status) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
389 { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
390 return (status == -1) ? errno : status; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
391 } |
|
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 int |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
394 PyThread_acquire_lock(PyThread_type_lock lock, int waitflag) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
395 { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
396 int success; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
397 sem_t *thelock = (sem_t *)lock; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
398 int status, error = 0; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
399 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
400 dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag)); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
401 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
402 do { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
403 if (waitflag) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
404 status = fix_status(sem_wait(thelock)); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
405 else |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
406 status = fix_status(sem_trywait(thelock)); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
407 } while (status == EINTR); /* Retry if interrupted by a signal */ |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
408 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
409 if (waitflag) { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
410 CHECK_STATUS("sem_wait"); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
411 } else if (status != EAGAIN) { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
412 CHECK_STATUS("sem_trywait"); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
413 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
414 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
415 success = (status == 0) ? 1 : 0; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
416 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
417 dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success)); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
418 return success; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
419 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
420 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
421 void |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
422 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
|
423 { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
424 sem_t *thelock = (sem_t *)lock; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
425 int status, error = 0; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
426 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
427 dprintf(("PyThread_release_lock(%p) called\n", lock)); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
428 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
429 status = sem_post(thelock); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
430 CHECK_STATUS("sem_post"); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
431 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
432 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
433 #else /* USE_SEMAPHORES */ |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
434 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
435 /* |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
436 * Lock support. |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
437 */ |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
438 PyThread_type_lock |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
439 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
|
440 { |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
441 pthread_lock *lock; |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
442 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
|
443 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
444 dprintf(("PyThread_allocate_lock called\n")); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
445 if (!initialized) |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
446 PyThread_init_thread(); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
447 |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
448 lock = (pthread_lock *) malloc(sizeof(pthread_lock)); |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
449 memset((void *)lock, '\0', sizeof(pthread_lock)); |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
450 if (lock) { |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
451 lock->locked = 0; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
452 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
453 status = pthread_mutex_init(&lock->mut, |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
454 pthread_mutexattr_default); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
455 CHECK_STATUS("pthread_mutex_init"); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
456 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
457 status = pthread_cond_init(&lock->lock_released, |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
458 pthread_condattr_default); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
459 CHECK_STATUS("pthread_cond_init"); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
460 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
461 if (error) { |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
462 free((void *)lock); |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
463 lock = 0; |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
464 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
465 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
466 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
467 dprintf(("PyThread_allocate_lock() -> %p\n", lock)); |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
468 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
|
469 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
470 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
471 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
472 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
|
473 { |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
474 pthread_lock *thelock = (pthread_lock *)lock; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
475 int status, error = 0; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
476 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
477 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
|
478 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
479 status = pthread_mutex_destroy( &thelock->mut ); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
480 CHECK_STATUS("pthread_mutex_destroy"); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
481 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
482 status = pthread_cond_destroy( &thelock->lock_released ); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
483 CHECK_STATUS("pthread_cond_destroy"); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
484 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
485 free((void *)thelock); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
486 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
487 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
488 int |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
489 PyThread_acquire_lock(PyThread_type_lock lock, int waitflag) |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
490 { |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
491 int success; |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
492 pthread_lock *thelock = (pthread_lock *)lock; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
493 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
|
494 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
495 dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag)); |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
496 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
497 status = pthread_mutex_lock( &thelock->mut ); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
498 CHECK_STATUS("pthread_mutex_lock[1]"); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
499 success = thelock->locked == 0; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
500 if (success) thelock->locked = 1; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
501 status = pthread_mutex_unlock( &thelock->mut ); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
502 CHECK_STATUS("pthread_mutex_unlock[1]"); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
503 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
504 if ( !success && waitflag ) { |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
505 /* 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
|
506 |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
507 /* mut must be locked by me -- part of the condition |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
508 * protocol */ |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
509 status = pthread_mutex_lock( &thelock->mut ); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
510 CHECK_STATUS("pthread_mutex_lock[2]"); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
511 while ( thelock->locked ) { |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
512 status = pthread_cond_wait(&thelock->lock_released, |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
513 &thelock->mut); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
514 CHECK_STATUS("pthread_cond_wait"); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
515 } |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
516 thelock->locked = 1; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
517 status = pthread_mutex_unlock( &thelock->mut ); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
518 CHECK_STATUS("pthread_mutex_unlock[2]"); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
519 success = 1; |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
520 } |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
521 if (error) success = 0; |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
522 dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success)); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
523 return success; |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
524 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
525 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
526 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
527 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
|
528 { |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
529 pthread_lock *thelock = (pthread_lock *)lock; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
530 int status, error = 0; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
531 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
532 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
|
533 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
534 status = pthread_mutex_lock( &thelock->mut ); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
535 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
|
536 |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
537 thelock->locked = 0; |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
538 |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
539 status = pthread_mutex_unlock( &thelock->mut ); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
540 CHECK_STATUS("pthread_mutex_unlock[3]"); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
541 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
542 /* wake up someone (anyone, if any) waiting on the lock */ |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
543 status = pthread_cond_signal( &thelock->lock_released ); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
544 CHECK_STATUS("pthread_cond_signal"); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
545 } |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
546 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
547 #endif /* USE_SEMAPHORES */ |
