Mercurial > cpython-lru_cache-weakref
annotate Python/thread_pthread.h @ 13378:113d833eea7e legacy-trunk
Added support for H (unsigned short) specifier in PyArg_ParseTuple and
Py_BuildValue.
| author | Jack Jansen <jack.jansen@cwi.nl> |
|---|---|
| date | Thu, 06 Jul 2000 12:22:00 +0000 |
| parents | 87ee82e5c56d |
| children | f79434ee41fa |
| 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 /*********************************************************** |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13210
diff
changeset
|
2 Copyright (c) 2000, BeOpen.com. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13210
diff
changeset
|
3 Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13210
diff
changeset
|
4 Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13210
diff
changeset
|
5 All rights reserved. |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13210
diff
changeset
|
7 See the file "Misc/COPYRIGHT" for information on usage and |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13210
diff
changeset
|
8 redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 ******************************************************************/ |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 |
|
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
|
11 /* Posix threads interface */ |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 |
|
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
|
13 #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
|
14 #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
|
15 #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
|
16 |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
17 |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
18 /* 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
|
19 * 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
|
20 * 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
|
21 * 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
|
22 * 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
|
23 */ |
|
3965
9c05ff6fb0a4
Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents:
3663
diff
changeset
|
24 |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
25 #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
|
26 /* _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
|
27 # define PY_PTHREAD_D4 |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
28 |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
29 #elif defined(__osf__) && defined (__alpha) |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
30 /* _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
|
31 # 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
|
32 # define PY_PTHREAD_D4 |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
33 # else |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
34 # define PY_PTHREAD_STD |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
35 # endif |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
36 |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
37 #elif defined(_AIX) |
|
3965
9c05ff6fb0a4
Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents:
3663
diff
changeset
|
38 /* 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
|
39 * but it is unsupported by AIX 4 pthreads. Default |
|
9c05ff6fb0a4
Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents:
3663
diff
changeset
|
40 * attributes for AIX 4 pthreads equal to NULL. For |
|
9c05ff6fb0a4
Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents:
3663
diff
changeset
|
41 * AIX DCE pthreads they should be left unchanged. |
|
9c05ff6fb0a4
Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents:
3663
diff
changeset
|
42 */ |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
43 # if !defined(SCHED_BG_NP) |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
44 # define PY_PTHREAD_STD |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
45 # else |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
46 # define PY_PTHREAD_D7 |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
47 # endif |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
48 |
|
5599
b5e51ae9f832
DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents:
5529
diff
changeset
|
49 #elif defined(__DGUX) |
|
b5e51ae9f832
DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents:
5529
diff
changeset
|
50 # 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
|
51 |
|
8343
1b4a37f37345
Improved version of patch for HPUX from David Arnold.
Guido van Rossum <guido@python.org>
parents:
8250
diff
changeset
|
52 #elif defined(__hpux) && defined(_DECTHREADS_) |
|
8250
50d35bdf2042
Support HPUX 10.20 DCE threads.
Guido van Rossum <guido@python.org>
parents:
7982
diff
changeset
|
53 # define PY_PTHREAD_D4 |
|
50d35bdf2042
Support HPUX 10.20 DCE threads.
Guido van Rossum <guido@python.org>
parents:
7982
diff
changeset
|
54 |
|
5700
60fca4783793
Add default case (standard conformance) to avoid piling up
Guido van Rossum <guido@python.org>
parents:
5599
diff
changeset
|
55 #else /* Default case */ |
|
60fca4783793
Add default case (standard conformance) to avoid piling up
Guido van Rossum <guido@python.org>
parents:
5599
diff
changeset
|
56 # define PY_PTHREAD_STD |
|
60fca4783793
Add default case (standard conformance) to avoid piling up
Guido van Rossum <guido@python.org>
parents:
5599
diff
changeset
|
57 |
|
3965
9c05ff6fb0a4
Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents:
3663
diff
changeset
|
58 #endif |
|
9c05ff6fb0a4
Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents:
3663
diff
changeset
|
59 |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
60 |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
61 /* 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
|
62 |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
63 #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
|
64 # 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
|
65 # 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
|
66 # 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
|
67 #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
|
68 # 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
|
69 # 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
|
70 # define pthread_condattr_default ((pthread_condattr_t *)NULL) |
|
3965
9c05ff6fb0a4
Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents:
3663
diff
changeset
|
71 #endif |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
73 |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
74 /* 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
|
75 * 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
|
76 * following are undefined: |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
77 * -> 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
|
78 * -> 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
|
79 * 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
|
80 * 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
|
81 * 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
|
82 * |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
83 * 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
|
84 * 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
|
85 * 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
|
86 * 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
|
87 */ |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
88 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
89 typedef struct { |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
90 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
|
91 /* 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
|
92 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
|
93 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
|
94 } pthread_lock; |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
96 #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
|
97 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
98 /* |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 * Initialization. |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
100 */ |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
101 |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
102 #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
|
103 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
|
104 { |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
105 } |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
106 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
107 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
|
108 { |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
109 /* 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
|
110 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
|
111 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
|
112 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
|
113 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
|
114 } |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
115 |
|
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
116 #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
|
117 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
118 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
|
119 { |
|
9079
4d2cb212c8d1
Apparently on AIX when using gcc you need to call pthread_init()
Guido van Rossum <guido@python.org>
parents:
9070
diff
changeset
|
120 #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
|
121 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
|
122 #endif |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
123 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
124 |
|
9290
2340f615da8f
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents:
9079
diff
changeset
|
125 #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
|
126 |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
127 /* |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
128 * Thread support. |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
129 */ |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
130 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
131 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
132 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
|
133 { |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
134 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
|
135 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
|
136 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
|
137 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
|
138 PyThread_init_thread(); |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
139 |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
140 success = pthread_create(&th, |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
141 #if defined(PY_PTHREAD_D4) |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
142 pthread_attr_default, |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
143 (pthread_startroutine_t)func, |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
144 (pthread_addr_t)arg |
|
5599
b5e51ae9f832
DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents:
5529
diff
changeset
|
145 #elif defined(PY_PTHREAD_D6) |
|
b5e51ae9f832
DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents:
5529
diff
changeset
|
146 pthread_attr_default, |
|
b5e51ae9f832
DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents:
5529
diff
changeset
|
147 (void* (*)_P((void *)))func, |
|
b5e51ae9f832
DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents:
5529
diff
changeset
|
148 arg |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
149 #elif defined(PY_PTHREAD_D7) |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
150 pthread_attr_default, |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
151 func, |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
152 arg |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
153 #elif defined(PY_PTHREAD_STD) |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
154 (pthread_attr_t*)NULL, |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
155 (void* (*)_P((void *)))func, |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
156 (void *)arg |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
157 #endif |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
158 ); |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
159 |
| 10400 | 160 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
|
161 #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
|
162 pthread_detach(&th); |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
163 #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
|
164 pthread_detach(th); |
|
5493
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
165 #endif |
|
ef93d51dab36
Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents:
5395
diff
changeset
|
166 } |
| 10400 | 167 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
|
168 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
169 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
170 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
|
171 { |
|
9055
5bc64efc65e0
Add a 'volatile' to the declaration of threadid in get_thread_ident().
Guido van Rossum <guido@python.org>
parents:
8343
diff
changeset
|
172 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
|
173 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
|
174 PyThread_init_thread(); |
| 2097 | 175 /* Jump through some hoops for Alpha OSF/1 */ |
| 176 threadid = pthread_self(); | |
| 177 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
|
178 } |
|
7e5f97bab1e6
ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents:
1629
diff
changeset
|
179 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
180 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
|
181 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
182 dprintf(("PyThread_exit_thread called\n")); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5700
diff
changeset
|
183 if (!initialized) { |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
184 if (no_cleanup) |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
185 _exit(0); |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
186 else |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
187 exit(0); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5700
diff
changeset
|
188 } |
|
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 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
|
192 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
193 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
|
194 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
195 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
196 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
|
197 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
198 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
|
199 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
200 |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
201 #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
|
202 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
|
203 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
204 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
|
205 if (!initialized) |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
206 if (no_cleanup) |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
207 _exit(status); |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
208 else |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
209 exit(status); |
|
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_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
|
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_prog(status, 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_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
|
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_prog(status, 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 #endif /* NO_EXIT_PROG */ |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
222 |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
223 /* |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
224 * Lock support. |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
225 */ |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
226 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
|
227 { |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
228 pthread_lock *lock; |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
229 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
|
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 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
|
232 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
|
233 PyThread_init_thread(); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
234 |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
235 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
|
236 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
|
237 if (lock) { |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
238 lock->locked = 0; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
239 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
240 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
|
241 pthread_mutexattr_default); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
242 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
|
243 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
244 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
|
245 pthread_condattr_default); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
246 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
|
247 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
248 if (error) { |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
249 free((void *)lock); |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
250 lock = 0; |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
251 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
252 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
253 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
254 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
|
255 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
|
256 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
257 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
258 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
|
259 { |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
260 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
|
261 int status, error = 0; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
262 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
263 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
|
264 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
265 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
|
266 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
|
267 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
268 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
|
269 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
|
270 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
271 free((void *)thelock); |
|
1628
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 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
274 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
|
275 { |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
276 int success; |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
277 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
|
278 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
|
279 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
280 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
|
281 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
282 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
|
283 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
|
284 success = thelock->locked == 0; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
285 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
|
286 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
|
287 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
|
288 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
289 if ( !success && waitflag ) { |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
290 /* 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
|
291 |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
292 /* 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
|
293 * protocol */ |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
294 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
|
295 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
|
296 while ( thelock->locked ) { |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
297 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
|
298 &thelock->mut); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
299 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
|
300 } |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
301 thelock->locked = 1; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
302 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
|
303 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
|
304 success = 1; |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
305 } |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
306 if (error) success = 0; |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
307 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
|
308 return success; |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
309 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
310 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
311 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
|
312 { |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
313 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
|
314 int status, error = 0; |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
315 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
316 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
|
317 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
318 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
|
319 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
|
320 |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
321 thelock->locked = 0; |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
322 |
|
1629
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[3]"); |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
325 |
|
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
326 /* 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
|
327 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
|
328 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
|
329 } |
|
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 /* |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
332 * Semaphore support. |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
333 */ |
|
4994
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
334 |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
335 struct semaphore { |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
336 pthread_mutex_t mutex; |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
337 pthread_cond_t cond; |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
338 int value; |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
339 }; |
|
1629
4121afd76d73
Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents:
1628
diff
changeset
|
340 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
341 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
|
342 { |
|
4994
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
343 struct semaphore *sema; |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
344 int status, error = 0; |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
345 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
346 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
|
347 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
|
348 PyThread_init_thread(); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
349 |
|
4994
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
350 sema = (struct semaphore *) malloc(sizeof(struct semaphore)); |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
351 if (sema != NULL) { |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
352 sema->value = value; |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
353 status = pthread_mutex_init(&sema->mutex, |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
354 pthread_mutexattr_default); |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
355 CHECK_STATUS("pthread_mutex_init"); |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
356 status = pthread_cond_init(&sema->cond, |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
357 pthread_condattr_default); |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
358 CHECK_STATUS("pthread_cond_init"); |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
359 if (error) { |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
360 free((void *) sema); |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
361 sema = NULL; |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
362 } |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
363 } |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
364 dprintf(("PyThread_allocate_sema() -> %p\n", sema)); |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
365 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
|
366 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
367 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
368 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
|
369 { |
|
4994
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
370 int status, error = 0; |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
371 struct semaphore *thesema = (struct semaphore *) sema; |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
372 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
373 dprintf(("PyThread_free_sema(%p) called\n", sema)); |
|
4994
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
374 status = pthread_cond_destroy(&thesema->cond); |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
375 CHECK_STATUS("pthread_cond_destroy"); |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
376 status = pthread_mutex_destroy(&thesema->mutex); |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
377 CHECK_STATUS("pthread_mutex_destroy"); |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
378 free((void *) thesema); |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
379 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
380 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
381 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
|
382 { |
|
4994
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
383 int status, error = 0, success; |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
384 struct semaphore *thesema = (struct semaphore *) sema; |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
385 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
386 dprintf(("PyThread_down_sema(%p, %d) called\n", sema, waitflag)); |
|
4994
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
387 status = pthread_mutex_lock(&thesema->mutex); |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
388 CHECK_STATUS("pthread_mutex_lock"); |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
389 if (waitflag) { |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
390 while (!error && thesema->value <= 0) { |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
391 status = pthread_cond_wait(&thesema->cond, |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
392 &thesema->mutex); |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
393 CHECK_STATUS("pthread_cond_wait"); |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
394 } |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
395 } |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
396 if (error) |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
397 success = 0; |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
398 else if (thesema->value > 0) { |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
399 thesema->value--; |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
400 success = 1; |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
401 } |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
402 else |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
403 success = 0; |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
404 status = pthread_mutex_unlock(&thesema->mutex); |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
405 CHECK_STATUS("pthread_mutex_unlock"); |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
406 dprintf(("PyThread_down_sema(%p) return\n", sema)); |
|
4994
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
407 return success; |
|
1628
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
408 } |
|
a9dd2e1ea5c9
Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
409 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9290
diff
changeset
|
410 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
|
411 { |
|
4994
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
412 int status, error = 0; |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
413 struct semaphore *thesema = (struct semaphore *) sema; |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
414 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
10400
diff
changeset
|
415 dprintf(("PyThread_up_sema(%p)\n", sema)); |
|
4994
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
416 status = pthread_mutex_lock(&thesema->mutex); |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
417 CHECK_STATUS("pthread_mutex_lock"); |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
418 thesema->value++; |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
419 status = pthread_cond_signal(&thesema->cond); |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
420 CHECK_STATUS("pthread_cond_signal"); |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
421 status = pthread_mutex_unlock(&thesema->mutex); |
|
9bc652e9f2b4
Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
422 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
|
423 } |
