annotate Python/thread_pthread.h @ 12970:63436719d12e legacy-trunk

Add new parser error code, E_OVERFLOW. This error is returned when the number of children of a node exceeds the max possible value for the short that is used to count them. The Python runtime converts this parser error into the SyntaxError "expression too long."
author Jeremy Hylton <jeremy@alum.mit.edu>
date Tue, 20 Jun 2000 19:10:44 +0000
parents 94ad90fd2712
children ff243b0f16ee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 /***********************************************************
2062
d0d0a69b5ca3 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
d0d0a69b5ca3 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 1651
diff changeset
3 The Netherlands.
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 All Rights Reserved
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4371
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4371
diff changeset
8 documentation for any purpose and without fee is hereby granted,
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 provided that the above copyright notice appear in all copies and that
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4371
diff changeset
10 both that copyright notice and this permission notice appear in
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4371
diff changeset
12 Centrum or CWI or Corporation for National Research Initiatives or
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4371
diff changeset
13 CNRI not be used in advertising or publicity pertaining to
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4371
diff changeset
14 distribution of the software without specific, written prior
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4371
diff changeset
15 permission.
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4371
diff changeset
17 While CWI is the initial source for this software, a modified version
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4371
diff changeset
18 is made available by the Corporation for National Research Initiatives
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4371
diff changeset
19 (CNRI) at the Internet address ftp://ftp.python.org.
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4371
diff changeset
20
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4371
diff changeset
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4371
diff changeset
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4371
diff changeset
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4371
diff changeset
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4371
diff changeset
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4371
diff changeset
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4371
diff changeset
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4371
diff changeset
28 PERFORMANCE OF THIS SOFTWARE.
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 ******************************************************************/
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
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
32 /* Posix threads interface */
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
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
34 #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
35 #include <string.h>
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
36 #include <pthread.h>
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
37
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
38
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
39 /* 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
40 * 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
41 * 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
42 * 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
43 * 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
44 */
3965
9c05ff6fb0a4 Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents: 3663
diff changeset
45
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
46 #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
47 /* _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
48 # define PY_PTHREAD_D4
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
49
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
50 #elif defined(__osf__) && defined (__alpha)
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
51 /* _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
52 # 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
53 # define PY_PTHREAD_D4
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
54 # else
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
55 # define PY_PTHREAD_STD
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
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
58 #elif defined(_AIX)
3965
9c05ff6fb0a4 Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents: 3663
diff changeset
59 /* 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
60 * but it is unsupported by AIX 4 pthreads. Default
9c05ff6fb0a4 Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents: 3663
diff changeset
61 * attributes for AIX 4 pthreads equal to NULL. For
9c05ff6fb0a4 Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents: 3663
diff changeset
62 * AIX DCE pthreads they should be left unchanged.
9c05ff6fb0a4 Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents: 3663
diff changeset
63 */
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
64 # if !defined(SCHED_BG_NP)
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
65 # define PY_PTHREAD_STD
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
66 # else
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
67 # define PY_PTHREAD_D7
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
68 # endif
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
69
5599
b5e51ae9f832 DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents: 5529
diff changeset
70 #elif defined(__DGUX)
b5e51ae9f832 DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents: 5529
diff changeset
71 # define PY_PTHREAD_D6
5700
60fca4783793 Add default case (standard conformance) to avoid piling up
Guido van Rossum <guido@python.org>
parents: 5599
diff changeset
72
8343
1b4a37f37345 Improved version of patch for HPUX from David Arnold.
Guido van Rossum <guido@python.org>
parents: 8250
diff changeset
73 #elif defined(__hpux) && defined(_DECTHREADS_)
8250
50d35bdf2042 Support HPUX 10.20 DCE threads.
Guido van Rossum <guido@python.org>
parents: 7982
diff changeset
74 # define PY_PTHREAD_D4
50d35bdf2042 Support HPUX 10.20 DCE threads.
Guido van Rossum <guido@python.org>
parents: 7982
diff changeset
75
5700
60fca4783793 Add default case (standard conformance) to avoid piling up
Guido van Rossum <guido@python.org>
parents: 5599
diff changeset
76 #else /* Default case */
60fca4783793 Add default case (standard conformance) to avoid piling up
Guido van Rossum <guido@python.org>
parents: 5599
diff changeset
77 # define PY_PTHREAD_STD
60fca4783793 Add default case (standard conformance) to avoid piling up
Guido van Rossum <guido@python.org>
parents: 5599
diff changeset
78
3965
9c05ff6fb0a4 Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents: 3663
diff changeset
79 #endif
9c05ff6fb0a4 Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents: 3663
diff changeset
80
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
81
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
82 /* 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
83
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
84 #if defined(PY_PTHREAD_D4) || defined(PY_PTHREAD_D7)
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
85 # define pthread_attr_default pthread_attr_default
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
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
87 # define pthread_condattr_default pthread_condattr_default
5599
b5e51ae9f832 DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents: 5529
diff changeset
88 #elif defined(PY_PTHREAD_STD) || defined(PY_PTHREAD_D6)
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
89 # define pthread_attr_default ((pthread_attr_t *)NULL)
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
90 # define pthread_mutexattr_default ((pthread_mutexattr_t *)NULL)
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
91 # define pthread_condattr_default ((pthread_condattr_t *)NULL)
3965
9c05ff6fb0a4 Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents: 3663
diff changeset
92 #endif
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
93
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
94
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
95 /* 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
96 * 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
97 * following are undefined:
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
98 * -> 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
99 * -> 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
100 * 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
101 * 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
102 * 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
103 *
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
104 * 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
105 * 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
106 * 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
107 * 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
108 */
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
109
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 typedef struct {
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
111 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
112 /* 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
113 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
114 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
115 } pthread_lock;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
116
9290
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
117 #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
118
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 * Initialization.
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 */
9290
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
122
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
123 #ifdef _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
124 static void _noop()
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
125 {
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
126 }
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
127
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
128 static void PyThread__init_thread _P0()
9290
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
129 {
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
130 /* 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
131 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
132 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
133 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
134 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
135 }
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
136
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
137 #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
138
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
139 static void PyThread__init_thread _P0()
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 {
9079
4d2cb212c8d1 Apparently on AIX when using gcc you need to call pthread_init()
Guido van Rossum <guido@python.org>
parents: 9070
diff changeset
141 #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
142 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
143 #endif
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
145
9290
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
146 #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
147
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 /*
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 * Thread support.
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 */
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
151
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
152
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
153 int PyThread_start_new_thread _P2(func, void (*func) _P((void *)), arg, void *arg)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 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
156 int success;
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
157 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
158 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
159 PyThread_init_thread();
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
160
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
161 success = pthread_create(&th,
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
162 #if defined(PY_PTHREAD_D4)
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
163 pthread_attr_default,
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
164 (pthread_startroutine_t)func,
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
165 (pthread_addr_t)arg
5599
b5e51ae9f832 DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents: 5529
diff changeset
166 #elif defined(PY_PTHREAD_D6)
b5e51ae9f832 DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents: 5529
diff changeset
167 pthread_attr_default,
b5e51ae9f832 DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents: 5529
diff changeset
168 (void* (*)_P((void *)))func,
b5e51ae9f832 DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents: 5529
diff changeset
169 arg
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
170 #elif defined(PY_PTHREAD_D7)
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
171 pthread_attr_default,
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
172 func,
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
173 arg
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
174 #elif defined(PY_PTHREAD_STD)
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
175 (pthread_attr_t*)NULL,
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
176 (void* (*)_P((void *)))func,
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
177 (void *)arg
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
178 #endif
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
179 );
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
180
10400
94ad90fd2712 Rob Riggs wrote:
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
181 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
182 #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
183 pthread_detach(&th);
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
184 #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
185 pthread_detach(th);
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
186 #endif
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
187 }
10400
94ad90fd2712 Rob Riggs wrote:
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
188 return success != 0 ? 0 : 1;
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
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
191 long PyThread_get_thread_ident _P0()
1651
7e5f97bab1e6 ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents: 1629
diff changeset
192 {
9055
5bc64efc65e0 Add a 'volatile' to the declaration of threadid in get_thread_ident().
Guido van Rossum <guido@python.org>
parents: 8343
diff changeset
193 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
194 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
195 PyThread_init_thread();
2097
e4588404fdff Alpha OSF/1 fix
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
196 /* Jump through some hoops for Alpha OSF/1 */
e4588404fdff Alpha OSF/1 fix
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
197 threadid = pthread_self();
e4588404fdff Alpha OSF/1 fix
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
198 return (long) *(long *) &threadid;
1651
7e5f97bab1e6 ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents: 1629
diff changeset
199 }
7e5f97bab1e6 ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents: 1629
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 static void do_PyThread_exit_thread _P1(no_cleanup, int no_cleanup)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
203 dprintf(("PyThread_exit_thread called\n"));
7982
a909a2869ac5 Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 5700
diff changeset
204 if (!initialized) {
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 if (no_cleanup)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 _exit(0);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 else
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 exit(0);
7982
a909a2869ac5 Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 5700
diff changeset
209 }
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
211
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
212 void PyThread_exit_thread _P0()
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 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
215 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
216
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
217 void PyThread__exit_thread _P0()
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
219 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
220 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
221
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
222 #ifndef NO_EXIT_PROG
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
223 static void do_PyThread_exit_prog _P2(status, int status, no_cleanup, int no_cleanup)
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 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
226 if (!initialized)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
227 if (no_cleanup)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 _exit(status);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
229 else
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 exit(status);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
232
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
233 void PyThread_exit_prog _P1(status, int status)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
234 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
235 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
236 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
237
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
238 void PyThread__exit_prog _P1(status, int status)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
240 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
241 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
242 #endif /* NO_EXIT_PROG */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
243
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 /*
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
245 * Lock support.
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
246 */
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
247 PyThread_type_lock PyThread_allocate_lock _P0()
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
248 {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 pthread_lock *lock;
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
250 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
251
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
252 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
253 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
254 PyThread_init_thread();
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
255
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
256 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
257 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
258 if (lock) {
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
259 lock->locked = 0;
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
260
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
261 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
262 pthread_mutexattr_default);
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
263 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
264
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
265 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
266 pthread_condattr_default);
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
267 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
268
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
269 if (error) {
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
270 free((void *)lock);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
271 lock = 0;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
272 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
273 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
274
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
275 dprintf(("PyThread_allocate_lock() -> %lx\n", (long)lock));
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
276 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
277 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
278
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
279 void PyThread_free_lock _P1(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
280 {
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
281 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
282 int status, error = 0;
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
283
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
284 dprintf(("PyThread_free_lock(%lx) called\n", (long)lock));
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
285
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
286 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
287 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
288
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
289 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
290 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
291
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
292 free((void *)thelock);
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
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
295 int PyThread_acquire_lock _P2(lock, PyThread_type_lock lock, waitflag, int waitflag)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
296 {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
297 int success;
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
298 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
299 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
300
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
301 dprintf(("PyThread_acquire_lock(%lx, %d) called\n", (long)lock, waitflag));
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
302
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
303 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
304 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
305 success = thelock->locked == 0;
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
306 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
307 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
308 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
309
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
310 if ( !success && waitflag ) {
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
311 /* 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
312
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
313 /* 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
314 * protocol */
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
315 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
316 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
317 while ( thelock->locked ) {
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
318 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
319 &thelock->mut);
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
320 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
321 }
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
322 thelock->locked = 1;
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
323 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
324 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
325 success = 1;
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
326 }
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
327 if (error) success = 0;
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
328 dprintf(("PyThread_acquire_lock(%lx, %d) -> %d\n", (long)lock, waitflag, success));
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
329 return success;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
330 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
331
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
332 void PyThread_release_lock _P1(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
333 {
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
334 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
335 int status, error = 0;
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
336
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
337 dprintf(("PyThread_release_lock(%lx) called\n", (long)lock));
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
338
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
339 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
340 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
341
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
342 thelock->locked = 0;
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
343
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
344 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
345 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
346
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
347 /* 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
348 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
349 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
350 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
351
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
352 /*
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
353 * Semaphore support.
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
354 */
4994
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
355
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
356 struct semaphore {
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
357 pthread_mutex_t mutex;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
358 pthread_cond_t cond;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
359 int value;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
360 };
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
361
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
362 PyThread_type_sema PyThread_allocate_sema _P1(value, int value)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
363 {
4994
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
364 struct semaphore *sema;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
365 int status, error = 0;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
366
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
367 dprintf(("PyThread_allocate_sema called\n"));
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
368 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
369 PyThread_init_thread();
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
370
4994
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
371 sema = (struct semaphore *) malloc(sizeof(struct semaphore));
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
372 if (sema != NULL) {
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
373 sema->value = value;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
374 status = pthread_mutex_init(&sema->mutex,
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
375 pthread_mutexattr_default);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
376 CHECK_STATUS("pthread_mutex_init");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
377 status = pthread_cond_init(&sema->cond,
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
378 pthread_condattr_default);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
379 CHECK_STATUS("pthread_cond_init");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
380 if (error) {
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
381 free((void *) sema);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
382 sema = NULL;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
383 }
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
384 }
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
385 dprintf(("PyThread_allocate_sema() -> %lx\n", (long) sema));
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
386 return (PyThread_type_sema) sema;
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
387 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
388
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
389 void PyThread_free_sema _P1(sema, PyThread_type_sema sema)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
390 {
4994
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
391 int status, error = 0;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
392 struct semaphore *thesema = (struct semaphore *) sema;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
393
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
394 dprintf(("PyThread_free_sema(%lx) called\n", (long) sema));
4994
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
395 status = pthread_cond_destroy(&thesema->cond);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
396 CHECK_STATUS("pthread_cond_destroy");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
397 status = pthread_mutex_destroy(&thesema->mutex);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
398 CHECK_STATUS("pthread_mutex_destroy");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
399 free((void *) thesema);
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
400 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
401
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
402 int PyThread_down_sema _P2(sema, PyThread_type_sema sema, waitflag, int waitflag)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
403 {
4994
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
404 int status, error = 0, success;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
405 struct semaphore *thesema = (struct semaphore *) sema;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
406
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
407 dprintf(("PyThread_down_sema(%lx, %d) called\n", (long) sema, waitflag));
4994
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
408 status = pthread_mutex_lock(&thesema->mutex);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
409 CHECK_STATUS("pthread_mutex_lock");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
410 if (waitflag) {
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
411 while (!error && thesema->value <= 0) {
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
412 status = pthread_cond_wait(&thesema->cond,
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
413 &thesema->mutex);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
414 CHECK_STATUS("pthread_cond_wait");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
415 }
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
416 }
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
417 if (error)
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
418 success = 0;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
419 else if (thesema->value > 0) {
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
420 thesema->value--;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
421 success = 1;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
422 }
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
423 else
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
424 success = 0;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
425 status = pthread_mutex_unlock(&thesema->mutex);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
426 CHECK_STATUS("pthread_mutex_unlock");
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
427 dprintf(("PyThread_down_sema(%lx) return\n", (long) sema));
4994
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
428 return success;
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
429 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
430
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
431 void PyThread_up_sema _P1(sema, PyThread_type_sema sema)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
432 {
4994
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
433 int status, error = 0;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
434 struct semaphore *thesema = (struct semaphore *) sema;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
435
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
436 dprintf(("PyThread_up_sema(%lx)\n", (long) sema));
4994
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
437 status = pthread_mutex_lock(&thesema->mutex);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
438 CHECK_STATUS("pthread_mutex_lock");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
439 thesema->value++;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
440 status = pthread_cond_signal(&thesema->cond);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
441 CHECK_STATUS("pthread_cond_signal");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
442 status = pthread_mutex_unlock(&thesema->mutex);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
443 CHECK_STATUS("pthread_mutex_unlock");
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
444 }