annotate Python/thread_pthread.h @ 17337:96ea0eccdb31 legacy-trunk

SF patch #413552 - Premature decref on object Jeffery Collins pointed out that filterstring decrefs a character object before it's done using it. This works by accident today because another module always happens to have an active reference too at the time. The accident doesn't work after his Pippy modifications, and since it *is* an accident even in the mainline Python, it should work by design there too. The patch accomplishes that.
author Tim Peters <tim.peters@gmail.com>
date Sat, 07 Apr 2001 20:34:48 +0000
parents 6f6f965c5e2d
children 2a785b668a16 11a758c56027
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
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
51
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
52 /* 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
53
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
54 #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
55 # 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
56 # 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
57 # 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
58 #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
59 # 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
60 # 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
61 # define pthread_condattr_default ((pthread_condattr_t *)NULL)
3965
9c05ff6fb0a4 Changes necessary for AIX.
Guido van Rossum <guido@python.org>
parents: 3663
diff changeset
62 #endif
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
63
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
64
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
65 /* 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
66 * 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
67 * following are undefined:
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
68 * -> 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
69 * -> 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
70 * 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
71 * 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
72 * 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
73 *
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
74 * 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
75 * 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
76 * 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
77 * 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
78 */
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
79
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 typedef struct {
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
81 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
82 /* 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
83 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
84 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
85 } pthread_lock;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
86
9290
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
87 #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
88
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 /*
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 * Initialization.
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 */
9290
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
92
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
93 #ifdef _HAVE_BSDI
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
94 static
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
95 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
96 {
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
97 }
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
98
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
99 static void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
100 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
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 /* 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
103 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
104 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
105 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
106 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
107 }
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 #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
110
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
111 static void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
112 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
113 {
9079
4d2cb212c8d1 Apparently on AIX when using gcc you need to call pthread_init()
Guido van Rossum <guido@python.org>
parents: 9070
diff changeset
114 #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
115 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
116 #endif
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
118
9290
2340f615da8f BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Guido van Rossum <guido@python.org>
parents: 9079
diff changeset
119 #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
120
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 /*
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 * Thread support.
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 */
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
124
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
125
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
126 int
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
127 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
128 {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 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
130 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
131 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
132 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
133 PyThread_init_thread();
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
134
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
135 success = pthread_create(&th,
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
136 #if defined(PY_PTHREAD_D4)
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
137 pthread_attr_default,
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
138 (pthread_startroutine_t)func,
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
139 (pthread_addr_t)arg
5599
b5e51ae9f832 DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents: 5529
diff changeset
140 #elif defined(PY_PTHREAD_D6)
b5e51ae9f832 DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents: 5529
diff changeset
141 pthread_attr_default,
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
142 (void* (*)(void *))func,
5599
b5e51ae9f832 DG/UX thread patches (Ross Andrus)
Guido van Rossum <guido@python.org>
parents: 5529
diff changeset
143 arg
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
144 #elif defined(PY_PTHREAD_D7)
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
145 pthread_attr_default,
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
146 func,
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
147 arg
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
148 #elif defined(PY_PTHREAD_STD)
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
149 (pthread_attr_t*)NULL,
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
150 (void* (*)(void *))func,
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
151 (void *)arg
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
152 #endif
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
153 );
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
154
10400
94ad90fd2712 Rob Riggs wrote:
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
155 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
156 #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
157 pthread_detach(&th);
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
158 #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
159 pthread_detach(th);
5493
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
160 #endif
ef93d51dab36 Support for various versions of the pthread draft.
Guido van Rossum <guido@python.org>
parents: 5395
diff changeset
161 }
10400
94ad90fd2712 Rob Riggs wrote:
Guido van Rossum <guido@python.org>
parents: 9679
diff changeset
162 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
163 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
164
14144
31cda87e9ff4 This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents: 13658
diff changeset
165 /* 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
166 hosed" because:
31cda87e9ff4 This patch partly (some stuff went in already) ports Python to Monterey.
Trent Mick <trentm@activestate.com>
parents: 13658
diff changeset
167 - 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
168 - 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
169 - 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
170 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
171 */
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
172 long
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
173 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
174 {
9055
5bc64efc65e0 Add a 'volatile' to the declaration of threadid in get_thread_ident().
Guido van Rossum <guido@python.org>
parents: 8343
diff changeset
175 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
176 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
177 PyThread_init_thread();
2097
e4588404fdff Alpha OSF/1 fix
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
178 /* Jump through some hoops for Alpha OSF/1 */
e4588404fdff Alpha OSF/1 fix
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
179 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
180 #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
181 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
182 #else
2097
e4588404fdff Alpha OSF/1 fix
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
183 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
184 #endif
1651
7e5f97bab1e6 ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents: 1629
diff changeset
185 }
7e5f97bab1e6 ceval.c: dict of local mapping is now a tuple
Guido van Rossum <guido@python.org>
parents: 1629
diff changeset
186
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
187 static void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
188 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
189 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
190 dprintf(("PyThread_exit_thread called\n"));
7982
a909a2869ac5 Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 5700
diff changeset
191 if (!initialized) {
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 if (no_cleanup)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 _exit(0);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 else
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 exit(0);
7982
a909a2869ac5 Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 5700
diff changeset
196 }
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
198
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
199 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
200 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
201 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
202 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
203 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
204
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
205 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
206 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
207 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
208 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
209 }
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 #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
212 static void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
213 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
214 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
215 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
216 if (!initialized)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 if (no_cleanup)
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 _exit(status);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 else
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
220 exit(status);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
222
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
223 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
224 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
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 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
227 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
228
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
229 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
230 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
231 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
232 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
233 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
234 #endif /* NO_EXIT_PROG */
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
235
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 /*
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 * Lock support.
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 */
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
239 PyThread_type_lock
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
240 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
241 {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
242 pthread_lock *lock;
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
243 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
244
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
245 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
246 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
247 PyThread_init_thread();
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
248
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 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
250 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
251 if (lock) {
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
252 lock->locked = 0;
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
253
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
254 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
255 pthread_mutexattr_default);
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
256 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
257
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
258 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
259 pthread_condattr_default);
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
260 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
261
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
262 if (error) {
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
263 free((void *)lock);
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
264 lock = 0;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
265 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
266 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
267
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 10400
diff changeset
268 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
269 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
270 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
271
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
272 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
273 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
274 {
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
275 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
276 int status, error = 0;
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
277
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 10400
diff changeset
278 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
279
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
280 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
281 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
282
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
283 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
284 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
285
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
286 free((void *)thelock);
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
287 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
288
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
289 int
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
290 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
291 {
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
292 int success;
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
293 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
294 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
295
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 10400
diff changeset
296 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
297
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
298 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
299 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
300 success = thelock->locked == 0;
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
301 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
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[1]");
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
304
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
305 if ( !success && waitflag ) {
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
306 /* 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
307
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
308 /* 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
309 * protocol */
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
310 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
311 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
312 while ( thelock->locked ) {
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
313 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
314 &thelock->mut);
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
315 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
316 }
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
317 thelock->locked = 1;
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
318 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
319 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
320 success = 1;
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
321 }
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
322 if (error) success = 0;
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 10400
diff changeset
323 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
324 return success;
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
325 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
326
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
327 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
328 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
329 {
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
330 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
331 int status, error = 0;
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
332
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 10400
diff changeset
333 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
334
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
335 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
336 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
337
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
338 thelock->locked = 0;
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
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 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
341 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
342
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
343 /* 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
344 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
345 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
346 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
347
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
348 /*
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
349 * Semaphore support.
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
350 */
4994
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
351
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
352 struct semaphore {
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
353 pthread_mutex_t mutex;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
354 pthread_cond_t cond;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
355 int value;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
356 };
1629
4121afd76d73 Tim's changes; removed some remaining non-functional ifdefs
Guido van Rossum <guido@python.org>
parents: 1628
diff changeset
357
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
358 PyThread_type_sema
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
359 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
360 {
4994
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
361 struct semaphore *sema;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
362 int status, error = 0;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
363
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9290
diff changeset
364 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
365 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
366 PyThread_init_thread();
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
367
4994
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
368 sema = (struct semaphore *) malloc(sizeof(struct semaphore));
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
369 if (sema != NULL) {
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
370 sema->value = value;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
371 status = pthread_mutex_init(&sema->mutex,
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
372 pthread_mutexattr_default);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
373 CHECK_STATUS("pthread_mutex_init");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
374 status = pthread_cond_init(&sema->cond,
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
375 pthread_condattr_default);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
376 CHECK_STATUS("pthread_cond_init");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
377 if (error) {
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
378 free((void *) sema);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
379 sema = NULL;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
380 }
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
381 }
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 10400
diff changeset
382 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
383 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
384 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
385
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
386 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
387 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
388 {
4994
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
389 int status, error = 0;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
390 struct semaphore *thesema = (struct semaphore *) sema;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
391
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 10400
diff changeset
392 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
393 status = pthread_cond_destroy(&thesema->cond);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
394 CHECK_STATUS("pthread_cond_destroy");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
395 status = pthread_mutex_destroy(&thesema->mutex);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
396 CHECK_STATUS("pthread_mutex_destroy");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
397 free((void *) thesema);
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
398 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
399
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
400 int
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
401 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
402 {
4994
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
403 int status, error = 0, success;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
404 struct semaphore *thesema = (struct semaphore *) sema;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
405
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 10400
diff changeset
406 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
407 status = pthread_mutex_lock(&thesema->mutex);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
408 CHECK_STATUS("pthread_mutex_lock");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
409 if (waitflag) {
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
410 while (!error && thesema->value <= 0) {
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
411 status = pthread_cond_wait(&thesema->cond,
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
412 &thesema->mutex);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
413 CHECK_STATUS("pthread_cond_wait");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
414 }
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
415 }
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
416 if (error)
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
417 success = 0;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
418 else if (thesema->value > 0) {
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
419 thesema->value--;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
420 success = 1;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
421 }
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
422 else
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
423 success = 0;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
424 status = pthread_mutex_unlock(&thesema->mutex);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
425 CHECK_STATUS("pthread_mutex_unlock");
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 10400
diff changeset
426 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
427 return success;
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
428 }
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
429
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
430 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13256
diff changeset
431 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
432 {
4994
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
433 int status, error = 0;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
434 struct semaphore *thesema = (struct semaphore *) sema;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
435
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 10400
diff changeset
436 dprintf(("PyThread_up_sema(%p)\n", sema));
4994
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
437 status = pthread_mutex_lock(&thesema->mutex);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
438 CHECK_STATUS("pthread_mutex_lock");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
439 thesema->value++;
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
440 status = pthread_cond_signal(&thesema->cond);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
441 CHECK_STATUS("pthread_cond_signal");
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
442 status = pthread_mutex_unlock(&thesema->mutex);
9bc652e9f2b4 Working semaphore implementation by Sjoerd.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
443 CHECK_STATUS("pthread_mutex_unlock");
1628
a9dd2e1ea5c9 Split thread.c into a number of system-specific files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
444 }