Mercurial > cpython-lru_cache-weakref
comparison Python/thread_pthread.h @ 9290:2340f615da8f legacy-trunk
BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Also (non-BSDI specific):
- Change the CHECK_STATUS() macro so it tests for nonzero error codes
instead of negative error codes only (this was needed for BSDI, but
appears to be correct according to the PTHREADS spec).
- use memset() to zero out the allocated lock structure. Again, this
was needed for BSDI, but can't hurt elsewhere either.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 07 Oct 1998 16:39:47 +0000 |
| parents | 4d2cb212c8d1 |
| children | 877d23bd5bdc |
comparison
equal
deleted
inserted
replaced
| 9289:5d344710fcc3 | 9290:2340f615da8f |
|---|---|
| 30 ******************************************************************/ | 30 ******************************************************************/ |
| 31 | 31 |
| 32 /* Posix threads interface */ | 32 /* Posix threads interface */ |
| 33 | 33 |
| 34 #include <stdlib.h> | 34 #include <stdlib.h> |
| 35 #include <string.h> | |
| 35 #include <pthread.h> | 36 #include <pthread.h> |
| 36 | 37 |
| 37 | 38 |
| 38 /* try to determine what version of the Pthread Standard is installed. | 39 /* try to determine what version of the Pthread Standard is installed. |
| 39 * this is important, since all sorts of parameter types changed from | 40 * this is important, since all sorts of parameter types changed from |
| 111 /* a <cond, mutex> pair to handle an acquire of a locked lock */ | 112 /* a <cond, mutex> pair to handle an acquire of a locked lock */ |
| 112 pthread_cond_t lock_released; | 113 pthread_cond_t lock_released; |
| 113 pthread_mutex_t mut; | 114 pthread_mutex_t mut; |
| 114 } pthread_lock; | 115 } pthread_lock; |
| 115 | 116 |
| 116 #define CHECK_STATUS(name) if (status < 0) { perror(name); error=1; } | 117 #define CHECK_STATUS(name) if (status != 0) { perror(name); error = 1; } |
| 117 | 118 |
| 118 /* | 119 /* |
| 119 * Initialization. | 120 * Initialization. |
| 120 */ | 121 */ |
| 122 | |
| 123 #ifdef _HAVE_BSDI | |
| 124 static void _noop() | |
| 125 { | |
| 126 } | |
| 127 | |
| 128 static void _init_thread _P0() | |
| 129 { | |
| 130 /* DO AN INIT BY STARTING THE THREAD */ | |
| 131 static int dummy = 0; | |
| 132 pthread_t thread1; | |
| 133 pthread_create(&thread1, NULL, (void *) _noop, &dummy); | |
| 134 pthread_join(thread1, NULL); | |
| 135 } | |
| 136 | |
| 137 #else /* !_HAVE_BSDI */ | |
| 138 | |
| 121 static void _init_thread _P0() | 139 static void _init_thread _P0() |
| 122 { | 140 { |
| 123 #if defined(_AIX) && defined(__GNUC__) | 141 #if defined(_AIX) && defined(__GNUC__) |
| 124 pthread_init(); | 142 pthread_init(); |
| 125 #endif | 143 #endif |
| 126 } | 144 } |
| 145 | |
| 146 #endif /* !_HAVE_BSDI */ | |
| 127 | 147 |
| 128 /* | 148 /* |
| 129 * Thread support. | 149 * Thread support. |
| 130 */ | 150 */ |
| 131 | 151 |
| 232 dprintf(("allocate_lock called\n")); | 252 dprintf(("allocate_lock called\n")); |
| 233 if (!initialized) | 253 if (!initialized) |
| 234 init_thread(); | 254 init_thread(); |
| 235 | 255 |
| 236 lock = (pthread_lock *) malloc(sizeof(pthread_lock)); | 256 lock = (pthread_lock *) malloc(sizeof(pthread_lock)); |
| 257 memset((void *)lock, '\0', sizeof(pthread_lock)); | |
| 237 if (lock) { | 258 if (lock) { |
| 238 lock->locked = 0; | 259 lock->locked = 0; |
| 239 | 260 |
| 240 status = pthread_mutex_init(&lock->mut, | 261 status = pthread_mutex_init(&lock->mut, |
| 241 pthread_mutexattr_default); | 262 pthread_mutexattr_default); |
