Mercurial > cpython-lru_cache-weakref
annotate Python/thread_pthread.h @ 33940:dfd07b7be407 legacy-trunk
SF bug 1061968: threads: segfault or Py_FatalError at exit
PyGILState_Ensure(): The fix in 2.4a3 for bug 1010677 reintroduced thread
shutdown race bug 225673. Repaired by (once again) ensuring the GIL is
held whenever deleting a thread state.
Alas, there's no useful test case for this shy bug. Four years ago, only
Guido could provoke it, on his box, and today only Armin can provoke it
on his box. I've never been able to provoke it (but not for lack of
trying!).
This is a critical fix for 2.3.5 too, since the fix for 1010677 got
backported there already and so also reintroduced 225673. I don't intend to
backport this fix. For whoever (if anyone) does, there are other thread
fixes in 2.4 that need backporting too, and I bet they need to happen first
for this patch to apply cleanly.
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Mon, 08 Nov 2004 04:30:21 +0000 |
| parents | 78bd25b42d46 |
| children | fcb507414c41 |
| 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 |
|
26598
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
23 #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
|
24 # 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
|
25 #endif |
|
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
26 #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
|
27 # 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
|
28 #endif |
|
56dbd9079a13
Patch #650415: Avoid redefinition of macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
26499
diff
changeset
|
29 #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
|
30 # define pthread_condattr_default ((pthread_condattr_t *)NULL) |
|
3965
9c05ff6fb0a4
Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents:
3663
diff
changeset
|
31 #endif |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
33 |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
34 /* 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
|
35 * mutexes and condition variables: |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
36 */ |
|
27320
1562c1e10b49
Don't use Posix semaphores on Solaris 8. Fixes #662787.
Martin v. Löwis <martin@v.loewis.de>
parents:
26598
diff
changeset
|
37 #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
|
38 # define USE_SEMAPHORES |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
39 #else |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
40 # undef USE_SEMAPHORES |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
41 #endif |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
42 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
43 |
|
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
|
44 /* 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
|
45 * 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
|
46 * 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
|
47 * 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
|
48 */ |
|
29972
a408ac5527c3
Patch 775605: Cygwin pthread_sigmask() workaround patch
Jason Tishler <jason@tishler.net>
parents:
28687
diff
changeset
|
49 #if defined(HAVE_PTHREAD_SIGMASK) && !defined(HAVE_BROKEN_PTHREAD_SIGMASK) |
|
20398
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
50 # 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
|
51 #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
|
52 # 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
|
53 #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
|
54 |
|
c9a212329da6
Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
Guido van Rossum <guido@python.org>
parents:
19826
diff
changeset
|
55 |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
56 /* 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
|
57 * 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
|
58 * following are undefined: |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
59 * -> 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
|
60 * -> 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
|
61 * 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
|
62 * 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
|
63 * 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
|
64 * |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
65 * 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
|
66 * 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
|
67 * 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
|
68 * 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
|
69 */ |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
70 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 typedef struct { |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
72 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
|
73 /* 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
|
74 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
|
75 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
|
76 } pthread_lock; |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
78 #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
|
79 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 /* |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 * Initialization. |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 */ |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
83 |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
84 #ifdef _HAVE_BSDI |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
85 static |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
86 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
|
87 { |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
88 } |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
89 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
90 static void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
91 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
|
92 { |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
93 /* 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 } |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
99 |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
100 #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
|
101 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
102 static void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
103 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
|
104 { |
|
9079
4d2cb212c8d1
Apparently on AIX when using gcc you need to call pthread_init()
Guido van Rossum <guido@python.org>
parents:
9070
diff
changeset
|
105 #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
|
106 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
|
107 #endif |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
110 #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
|
111 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 /* |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 * Thread support. |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
114 */ |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
115 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
116 |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
117 long |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
118 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
|
119 { |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
120 pthread_t th; |
|
28687
40d287c3d906
Patch #716969: Detect thread creation failure. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28673
diff
changeset
|
121 int status; |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
122 #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
|
123 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
|
124 #endif |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
125 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
|
126 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
|
127 PyThread_init_thread(); |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
128 |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
129 #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
|
130 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
|
131 #endif |
|
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
132 #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
|
133 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
|
134 #endif |
|
31614
c2df8a5c357e
SF Patch #902444: Use process scope thread on FreeBSD. System scope
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31611
diff
changeset
|
135 #if defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) && !defined(__FreeBSD__) |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
136 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
|
137 #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
|
138 |
|
28687
40d287c3d906
Patch #716969: Detect thread creation failure. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28673
diff
changeset
|
139 status = pthread_create(&th, |
|
19826
8ef456949b76
Improve threading on Solaris, according to SF patch #460269, submitted
Guido van Rossum <guido@python.org>
parents:
19549
diff
changeset
|
140 #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
|
141 &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
|
142 #else |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
143 (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
|
144 #endif |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
145 (void* (*)(void *))func, |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
146 (void *)arg |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
147 ); |
|
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
|
148 |
|
20922
7a991d012cd6
Fix memory leak. This is part of SF patch #478006.
Fred Drake <fdrake@acm.org>
parents:
20468
diff
changeset
|
149 #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
|
150 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
|
151 #endif |
|
28687
40d287c3d906
Patch #716969: Detect thread creation failure. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28673
diff
changeset
|
152 if (status != 0) |
|
40d287c3d906
Patch #716969: Detect thread creation failure. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28673
diff
changeset
|
153 return -1; |
|
40d287c3d906
Patch #716969: Detect thread creation failure. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28673
diff
changeset
|
154 |
|
40d287c3d906
Patch #716969: Detect thread creation failure. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28673
diff
changeset
|
155 pthread_detach(th); |
|
40d287c3d906
Patch #716969: Detect thread creation failure. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28673
diff
changeset
|
156 |
|
20468
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
157 #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
|
158 return (long) th; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
159 #else |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
160 return (long) *(long *) &th; |
|
ebfd87e87884
Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents:
20431
diff
changeset
|
161 #endif |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
162 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
163 |
|
14144
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
164 /* 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
|
165 hosed" because: |
| 31611 | 166 - It does not guarantee the promise that a non-zero integer is returned. |
|
14144
31cda87e9ff4
This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents:
13658
diff
changeset
|
167 - 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
|
168 - 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
|
169 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
|
170 */ |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
171 long |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
172 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
|
173 { |
|
9055
5bc64efc65e0
Add a 'volatile' to the declaration of threadid in get_thread_ident().
Guido van Rossum <guido@python.org>
parents:
8343
diff
changeset
|
174 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
|
175 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
|
176 PyThread_init_thread(); |
| 2097 | 177 /* Jump through some hoops for Alpha OSF/1 */ |
| 178 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
|
179 #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
|
180 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
|
181 #else |
| 2097 | 182 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
|
183 #endif |
|
1651
7e5f97bab1e6
ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents:
1629
diff
changeset
|
184 } |
|
7e5f97bab1e6
ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents:
1629
diff
changeset
|
185 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
186 static void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
187 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
|
188 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
189 dprintf(("PyThread_exit_thread called\n")); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5700
diff
changeset
|
190 if (!initialized) { |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
191 if (no_cleanup) |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
192 _exit(0); |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
193 else |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
194 exit(0); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5700
diff
changeset
|
195 } |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
196 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
197 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
198 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
199 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
|
200 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
201 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
|
202 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
203 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
204 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
205 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
|
206 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
207 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
|
208 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
209 |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
210 #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
|
211 static void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
212 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
|
213 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
214 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
|
215 if (!initialized) |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
216 if (no_cleanup) |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
217 _exit(status); |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
218 else |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
219 exit(status); |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
220 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
221 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
222 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
223 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
|
224 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
225 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
|
226 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
227 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
228 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
229 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
|
230 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
231 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
|
232 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
233 #endif /* NO_EXIT_PROG */ |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
234 |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
235 #ifdef USE_SEMAPHORES |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
236 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
237 /* |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
238 * Lock support. |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
239 */ |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
240 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
241 PyThread_type_lock |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
242 PyThread_allocate_lock(void) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
243 { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
244 sem_t *lock; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
245 int status, error = 0; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
246 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
247 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
|
248 if (!initialized) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
249 PyThread_init_thread(); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
250 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
251 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
|
252 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
253 if (lock) { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
254 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
|
255 CHECK_STATUS("sem_init"); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
256 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
257 if (error) { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
258 free((void *)lock); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
259 lock = NULL; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
260 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
261 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
262 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
263 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
|
264 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
|
265 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
266 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
267 void |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
268 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
|
269 { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
270 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
|
271 int status, error = 0; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
272 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
273 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
|
274 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
275 if (!thelock) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
276 return; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
277 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
278 status = sem_destroy(thelock); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
279 CHECK_STATUS("sem_destroy"); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
280 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
281 free((void *)thelock); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
282 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
283 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
284 /* |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
285 * 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
|
286 * 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
|
287 * 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
|
288 * either. |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
289 */ |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
290 static int |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
291 fix_status(int status) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
292 { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
293 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
|
294 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
295 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
296 int |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
297 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
|
298 { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
299 int success; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
300 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
|
301 int status, error = 0; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
302 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
303 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
|
304 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
305 do { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
306 if (waitflag) |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
307 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
|
308 else |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
309 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
|
310 } 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
|
311 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
312 if (waitflag) { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
313 CHECK_STATUS("sem_wait"); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
314 } else if (status != EAGAIN) { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
315 CHECK_STATUS("sem_trywait"); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
316 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
317 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
318 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
|
319 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
320 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
|
321 return success; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
322 } |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
323 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
324 void |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
325 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
|
326 { |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
327 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
|
328 int status, error = 0; |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
329 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
330 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
|
331 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
332 status = sem_post(thelock); |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
333 CHECK_STATUS("sem_post"); |
|
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 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
336 #else /* USE_SEMAPHORES */ |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
337 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
338 /* |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
339 * Lock support. |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
340 */ |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
341 PyThread_type_lock |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
342 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
|
343 { |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
344 pthread_lock *lock; |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
345 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
|
346 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
347 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
|
348 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
|
349 PyThread_init_thread(); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
350 |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
351 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
|
352 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
|
353 if (lock) { |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
354 lock->locked = 0; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
355 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
356 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
|
357 pthread_mutexattr_default); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
358 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
|
359 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
360 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
|
361 pthread_condattr_default); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
362 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
|
363 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
364 if (error) { |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
365 free((void *)lock); |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
366 lock = 0; |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
367 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
368 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
369 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
370 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
|
371 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
|
372 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
373 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
374 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
375 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
|
376 { |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
377 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
|
378 int status, error = 0; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
379 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
380 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
|
381 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
382 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
|
383 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
|
384 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
385 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
|
386 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
|
387 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
388 free((void *)thelock); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
389 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
390 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
391 int |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
392 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
|
393 { |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
394 int success; |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
395 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
|
396 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
|
397 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
398 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
|
399 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
400 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
|
401 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
|
402 success = thelock->locked == 0; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
403 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
404 if ( !success && waitflag ) { |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
405 /* 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
|
406 |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
407 /* 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
|
408 * protocol */ |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
409 while ( thelock->locked ) { |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
410 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
|
411 &thelock->mut); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
412 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
|
413 } |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
414 success = 1; |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
415 } |
|
28673
c1ba50790c83
Patch #711835: Remove unnecessary lock operations. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
27320
diff
changeset
|
416 if (success) thelock->locked = 1; |
|
c1ba50790c83
Patch #711835: Remove unnecessary lock operations. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
27320
diff
changeset
|
417 status = pthread_mutex_unlock( &thelock->mut ); |
|
c1ba50790c83
Patch #711835: Remove unnecessary lock operations. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
27320
diff
changeset
|
418 CHECK_STATUS("pthread_mutex_unlock[1]"); |
|
c1ba50790c83
Patch #711835: Remove unnecessary lock operations. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
27320
diff
changeset
|
419 |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
420 if (error) success = 0; |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
421 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
|
422 return success; |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
423 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
424 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
425 void |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
426 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
|
427 { |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
428 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
|
429 int status, error = 0; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
430 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
431 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
|
432 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
433 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
|
434 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
|
435 |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
436 thelock->locked = 0; |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
437 |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
438 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
|
439 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
|
440 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
441 /* 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
|
442 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
|
443 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
|
444 } |
|
22339
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
445 |
|
6c3e32357d91
Patch #525532: Add support for POSIX semaphores.
Martin v. Löwis <martin@v.loewis.de>
parents:
21766
diff
changeset
|
446 #endif /* USE_SEMAPHORES */ |
