annotate Python/thread_pthread.h @ 19665:08c3c9edd99b legacy-trunk

Make dir() wordier (see the new docstring). The new behavior is a mixed bag. It's clearly wrong for classic classes, at heart because a classic class doesn't have a __class__ attribute, and I'm unclear on whether that's feature or bug. I'll repair this once I find out (in the meantime, dir() applied to classic classes won't find the base classes, while dir() applied to a classic-class instance *will* find the base classes but not *their* base classes). Please give the new dir() a try and see whether you love it or hate it. The new dir([]) behavior is something I could come to love. Here's something to hate: >>> class C: ... pass ... >>> c = C() >>> dir(c) ['__doc__', '__module__'] >>> The idea that an instance has a __doc__ attribute is jarring (of course it's really c.__class__.__doc__ == C.__doc__; likewise for __module__). OTOH, the code already has too many special cases, and dir(x) doesn't have a compelling or clear purpose when x isn't a module.
author Tim Peters <tim.peters@gmail.com>
date Mon, 03 Sep 2001 05:47:38 +0000
parents 11a758c56027
children 8ef456949b76
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
3663
07164d30429d Got rid of florida hack and made it work with Solaris 2.5 pthreads.
Guido van Rossum <guido@python.org>
parents: 2097
diff changeset
2 /* Posix threads interface */
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
3663
07164d30429d Got rid of florida hack and made it work with Solaris 2.5 pthreads.
Guido van Rossum <guido@python.org>
parents: 2097
diff changeset
4 #include <stdlib.h>
9290
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
5 #include <string.h>
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
6 #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
7
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
8
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
9 /* 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
10 * 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
11 * 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
12 * 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
13 * 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
14 */
3965
9c05ff6fb0a4 Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents: 3663
diff changeset
15
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
16 #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
17 /* _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
18 # define PY_PTHREAD_D4
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
19
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
20 #elif defined(__osf__) && defined (__alpha)
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
21 /* _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
22 # 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
23 # define PY_PTHREAD_D4
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
24 # else
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
25 # define PY_PTHREAD_STD
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
26 # endif
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
27
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
28 #elif defined(_AIX)
3965
9c05ff6fb0a4 Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents: 3663
diff changeset
29 /* 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
30 * but it is unsupported by AIX 4 pthreads. Default
9c05ff6fb0a4 Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents: 3663
diff changeset
31 * attributes for AIX 4 pthreads equal to NULL. For
9c05ff6fb0a4 Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents: 3663
diff changeset
32 * AIX DCE pthreads they should be left unchanged.
9c05ff6fb0a4 Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents: 3663
diff changeset
33 */
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
34 # if !defined(SCHED_BG_NP)
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
35 # define PY_PTHREAD_STD
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
36 # else
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
37 # define PY_PTHREAD_D7
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
38 # endif
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
39
5599
b5e51ae9f832 DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents: 5529
diff changeset
40 #elif defined(__DGUX)
b5e51ae9f832 DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents: 5529
diff changeset
41 # 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
42
8343
1b4a37f37345 Improved version of patch for HPUX from David Arnold.
Guido van Rossum <guido@python.org>
parents: 8250
diff changeset
43 #elif defined(__hpux) && defined(_DECTHREADS_)
8250
50d35bdf2042 Support HPUX 10.20 DCE threads.
Guido van Rossum <guido@python.org>
parents: 7982
diff changeset
44 # define PY_PTHREAD_D4
50d35bdf2042 Support HPUX 10.20 DCE threads.
Guido van Rossum <guido@python.org>
parents: 7982
diff changeset
45
5700
60fca4783793 Add default case (standard conformance) to avoid piling up
Guido van Rossum <guido@python.org>
parents: 5599
diff changeset
46 #else /* Default case */
60fca4783793 Add default case (standard conformance) to avoid piling up
Guido van Rossum <guido@python.org>
parents: 5599
diff changeset
47 # define PY_PTHREAD_STD
60fca4783793 Add default case (standard conformance) to avoid piling up
Guido van Rossum <guido@python.org>
parents: 5599
diff changeset
48
3965
9c05ff6fb0a4 Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents: 3663
diff changeset
49 #endif
9c05ff6fb0a4 Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents: 3663
diff changeset
50
19549
11a758c56027 GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
51 #ifdef USE_GUSI
11a758c56027 GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
52 /* The Macintosh GUSI I/O library sets the stackspace to
11a758c56027 GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
53 ** 20KB, much too low. We up it to 64K.
11a758c56027 GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
54 */
11a758c56027 GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
55 #define THREAD_STACK_SIZE 0x10000
11a758c56027 GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
56 #endif
11a758c56027 GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
57
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
58
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
59 /* 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
60
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
61 #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
62 # 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
63 # 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
64 # 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
65 #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
66 # 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
67 # 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
68 # define pthread_condattr_default ((pthread_condattr_t *)NULL)
3965
9c05ff6fb0a4 Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents: 3663
diff changeset
69 #endif
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
70
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
71
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
72 /* 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
73 * 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
74 * following are undefined:
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
75 * -> 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
76 * -> 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
77 * 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
78 * 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
79 * 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
80 *
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
81 * 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
82 * 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
83 * 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
84 * 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
85 */
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
86
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 typedef struct {
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
88 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
89 /* 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
90 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
91 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
92 } pthread_lock;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
93
9290
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
94 #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
95
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 /*
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 * Initialization.
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 */
9290
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
99
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
100 #ifdef _HAVE_BSDI
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
101 static
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
102 void _noop(void)
9290
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
103 {
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
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
106 static void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
107 PyThread__init_thread(void)
9290
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
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
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
118 static void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
119 PyThread__init_thread(void)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 {
9079
4d2cb212c8d1 Apparently on AIX when using gcc you need to call pthread_init()
Guido van Rossum <guido@python.org>
parents: 9070
diff changeset
121 #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
122 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
123 #endif
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
125
9290
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
126 #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
127
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 /*
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 * Thread support.
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 */
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
131
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
132
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
133 int
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
134 PyThread_start_new_thread(void (*func)(void *), void *arg)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 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
137 int success;
19549
11a758c56027 GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
138 #ifdef THREAD_STACK_SIZE
11a758c56027 GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
139 pthread_attr_t attrs;
11a758c56027 GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
140 #endif
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
141 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
142 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
143 PyThread_init_thread();
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
144
19549
11a758c56027 GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
145 #ifdef THREAD_STACK_SIZE
11a758c56027 GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
146 pthread_attr_init(&attrs);
11a758c56027 GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
147 pthread_attr_setstacksize(&attrs, THREAD_STACK_SIZE);
11a758c56027 GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
148 #endif
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
149 success = pthread_create(&th,
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
150 #if defined(PY_PTHREAD_D4)
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
151 pthread_attr_default,
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
152 (pthread_startroutine_t)func,
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
153 (pthread_addr_t)arg
5599
b5e51ae9f832 DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents: 5529
diff changeset
154 #elif defined(PY_PTHREAD_D6)
b5e51ae9f832 DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents: 5529
diff changeset
155 pthread_attr_default,
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
156 (void* (*)(void *))func,
5599
b5e51ae9f832 DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents: 5529
diff changeset
157 arg
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
158 #elif defined(PY_PTHREAD_D7)
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
159 pthread_attr_default,
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
160 func,
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
161 arg
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
162 #elif defined(PY_PTHREAD_STD)
19549
11a758c56027 GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
163 #ifdef THREAD_STACK_SIZE
11a758c56027 GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
164 &attrs,
11a758c56027 GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
165 #else
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
166 (pthread_attr_t*)NULL,
19549
11a758c56027 GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
167 #endif
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
168 (void* (*)(void *))func,
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
169 (void *)arg
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
170 #endif
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
171 );
19549
11a758c56027 GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
172 #ifdef THREAD_STACK_SIZE
11a758c56027 GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
173 pthread_attr_destroy(&attrs);
11a758c56027 GUSI on the Mac creates threads with a default stack size of 20KB, which is
Jack Jansen <jack.jansen@cwi.nl>
parents: 14375
diff changeset
174 #endif
10400
94ad90fd2712 Rob Riggs wrote:
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
175 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
176 #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
177 pthread_detach(&th);
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
178 #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
179 pthread_detach(th);
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
180 #endif
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
181 }
10400
94ad90fd2712 Rob Riggs wrote:
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
182 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
183 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
184
14144
31cda87e9ff4 This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents: 13658
diff changeset
185 /* XXX This implementation is considered (to quote Tim Peters) "inherently
31cda87e9ff4 This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents: 13658
diff changeset
186 hosed" because:
31cda87e9ff4 This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents: 13658
diff changeset
187 - It does not guanrantee the promise that a non-zero integer is returned.
31cda87e9ff4 This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents: 13658
diff changeset
188 - The cast to long is inherently unsafe.
31cda87e9ff4 This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents: 13658
diff changeset
189 - It is not clear that the 'volatile' (for AIX?) and ugly casting in the
31cda87e9ff4 This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents: 13658
diff changeset
190 latter return statement (for Alpha OSF/1) are any longer necessary.
31cda87e9ff4 This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents: 13658
diff changeset
191 */
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
192 long
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
193 PyThread_get_thread_ident(void)
1651
7e5f97bab1e6 ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents: 1629
diff changeset
194 {
9055
5bc64efc65e0 Add a 'volatile' to the declaration of threadid in get_thread_ident().
Guido van Rossum <guido@python.org>
parents: 8343
diff changeset
195 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
196 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
197 PyThread_init_thread();
2097
e4588404fdff Alpha OSF/1 fix
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
198 /* Jump through some hoops for Alpha OSF/1 */
e4588404fdff Alpha OSF/1 fix
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
199 threadid = pthread_self();
14144
31cda87e9ff4 This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents: 13658
diff changeset
200 #if SIZEOF_PTHREAD_T <= SIZEOF_LONG
31cda87e9ff4 This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents: 13658
diff changeset
201 return (long) threadid;
31cda87e9ff4 This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents: 13658
diff changeset
202 #else
2097
e4588404fdff Alpha OSF/1 fix
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
203 return (long) *(long *) &threadid;
14144
31cda87e9ff4 This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents: 13658
diff changeset
204 #endif
1651
7e5f97bab1e6 ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents: 1629
diff changeset
205 }
7e5f97bab1e6 ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents: 1629
diff changeset
206
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
207 static void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
208 do_PyThread_exit_thread(int no_cleanup)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
209 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
210 dprintf(("PyThread_exit_thread called\n"));
7982
a909a2869ac5 Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 5700
diff changeset
211 if (!initialized) {
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 if (no_cleanup)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
213 _exit(0);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
214 else
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 exit(0);
7982
a909a2869ac5 Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 5700
diff changeset
216 }
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
218
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
219 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
220 PyThread_exit_thread(void)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
222 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
223 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
224
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
225 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
226 PyThread__exit_thread(void)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
227 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
228 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
229 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
230
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 #ifndef NO_EXIT_PROG
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
232 static void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
233 do_PyThread_exit_prog(int status, int no_cleanup)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
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 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
236 if (!initialized)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 if (no_cleanup)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 _exit(status);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 else
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 exit(status);
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
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
243 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
244 PyThread_exit_prog(int status)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
245 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
246 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
247 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
248
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
249 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
250 PyThread__exit_prog(int status)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
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 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
253 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
254 #endif /* NO_EXIT_PROG */
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 /*
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
257 * Lock support.
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
258 */
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
259 PyThread_type_lock
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
260 PyThread_allocate_lock(void)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
261 {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
262 pthread_lock *lock;
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
263 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
264
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
265 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
266 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
267 PyThread_init_thread();
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
268
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
269 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
270 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
271 if (lock) {
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
272 lock->locked = 0;
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
273
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
274 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
275 pthread_mutexattr_default);
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
276 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
277
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
278 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
279 pthread_condattr_default);
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
280 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
281
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
282 if (error) {
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
283 free((void *)lock);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
284 lock = 0;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
285 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
286 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
287
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 10400
diff changeset
288 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
289 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
290 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
291
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
292 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
293 PyThread_free_lock(PyThread_type_lock lock)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
294 {
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
295 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
296 int status, error = 0;
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
297
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 10400
diff changeset
298 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
299
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
300 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
301 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
302
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
303 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
304 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
305
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
306 free((void *)thelock);
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
307 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
308
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
309 int
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
310 PyThread_acquire_lock(PyThread_type_lock lock, int waitflag)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
311 {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
312 int success;
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;
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
315
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 10400
diff changeset
316 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
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[1]");
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
320 success = thelock->locked == 0;
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
321 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
322 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
323 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
324
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
325 if ( !success && waitflag ) {
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
326 /* 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
327
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
328 /* 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
329 * protocol */
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
330 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
331 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
332 while ( thelock->locked ) {
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
333 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
334 &thelock->mut);
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
335 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
336 }
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
337 thelock->locked = 1;
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
338 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
339 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
340 success = 1;
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 if (error) success = 0;
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 10400
diff changeset
343 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
344 return success;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
345 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
346
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
347 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
348 PyThread_release_lock(PyThread_type_lock lock)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
349 {
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
350 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
351 int status, error = 0;
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
352
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 10400
diff changeset
353 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
354
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
355 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
356 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
357
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
358 thelock->locked = 0;
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
359
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
360 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
361 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
362
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
363 /* 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
364 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
365 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
366 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
367
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
368 /*
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
369 * Semaphore support.
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
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
372 struct semaphore {
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
373 pthread_mutex_t mutex;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
374 pthread_cond_t cond;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
375 int value;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
376 };
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
377
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
378 PyThread_type_sema
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
379 PyThread_allocate_sema(int value)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
380 {
4994
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
381 struct semaphore *sema;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
382 int status, error = 0;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
383
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
384 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
385 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
386 PyThread_init_thread();
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
387
4994
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
388 sema = (struct semaphore *) malloc(sizeof(struct semaphore));
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
389 if (sema != NULL) {
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
390 sema->value = value;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
391 status = pthread_mutex_init(&sema->mutex,
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
392 pthread_mutexattr_default);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
393 CHECK_STATUS("pthread_mutex_init");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
394 status = pthread_cond_init(&sema->cond,
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
395 pthread_condattr_default);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
396 CHECK_STATUS("pthread_cond_init");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
397 if (error) {
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
398 free((void *) sema);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
399 sema = NULL;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
400 }
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
401 }
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 10400
diff changeset
402 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
403 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
404 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
405
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
406 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
407 PyThread_free_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
408 {
4994
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
409 int status, error = 0;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
410 struct semaphore *thesema = (struct semaphore *) sema;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
411
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 10400
diff changeset
412 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
413 status = pthread_cond_destroy(&thesema->cond);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
414 CHECK_STATUS("pthread_cond_destroy");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
415 status = pthread_mutex_destroy(&thesema->mutex);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
416 CHECK_STATUS("pthread_mutex_destroy");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
417 free((void *) thesema);
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
418 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
419
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
420 int
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
421 PyThread_down_sema(PyThread_type_sema sema, int waitflag)
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
422 {
4994
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
423 int status, error = 0, success;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
424 struct semaphore *thesema = (struct semaphore *) sema;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
425
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 10400
diff changeset
426 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
427 status = pthread_mutex_lock(&thesema->mutex);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
428 CHECK_STATUS("pthread_mutex_lock");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
429 if (waitflag) {
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
430 while (!error && thesema->value <= 0) {
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
431 status = pthread_cond_wait(&thesema->cond,
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
432 &thesema->mutex);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
433 CHECK_STATUS("pthread_cond_wait");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
434 }
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
435 }
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
436 if (error)
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
437 success = 0;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
438 else if (thesema->value > 0) {
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 success = 1;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
441 }
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
442 else
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
443 success = 0;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
444 status = pthread_mutex_unlock(&thesema->mutex);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
445 CHECK_STATUS("pthread_mutex_unlock");
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 10400
diff changeset
446 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
447 return success;
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
448 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
449
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
450 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
451 PyThread_up_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
452 {
4994
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
453 int status, error = 0;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
454 struct semaphore *thesema = (struct semaphore *) sema;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
455
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 10400
diff changeset
456 dprintf(("PyThread_up_sema(%p)\n", sema));
4994
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
457 status = pthread_mutex_lock(&thesema->mutex);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
458 CHECK_STATUS("pthread_mutex_lock");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
459 thesema->value++;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
460 status = pthread_cond_signal(&thesema->cond);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
461 CHECK_STATUS("pthread_cond_signal");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
462 status = pthread_mutex_unlock(&thesema->mutex);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
463 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
464 }