blob: d75400502340b1ba0e09f94a70f48c7e80e52600 [file] [log] [blame]
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +00001
Guido van Rossum66020991996-06-11 18:32:18 +00002/* Posix threads interface */
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +00003
Guido van Rossum66020991996-06-11 18:32:18 +00004#include <stdlib.h>
Guido van Rossum9e46e561998-10-07 16:39:47 +00005#include <string.h>
Martin v. Löwisa7a76d32002-10-04 07:21:24 +00006#if defined(__APPLE__) || defined(HAVE_PTHREAD_DESTRUCTOR)
Jack Jansen76689572002-01-15 20:36:14 +00007#define destructor xxdestructor
8#endif
Guido van Rossum66020991996-06-11 18:32:18 +00009#include <pthread.h>
Martin v. Löwisa7a76d32002-10-04 07:21:24 +000010#if defined(__APPLE__) || defined(HAVE_PTHREAD_DESTRUCTOR)
Jack Jansen76689572002-01-15 20:36:14 +000011#undef destructor
12#endif
Guido van Rossum80230992001-10-12 21:49:17 +000013#include <signal.h>
Martin v. Löwis42ab61e2002-03-17 17:19:00 +000014
15/* The POSIX spec says that implementations supporting the sem_*
16 family of functions must indicate this by defining
17 _POSIX_SEMAPHORES. */
Martin v. Löwiscc898662002-03-17 09:53:51 +000018#ifdef _POSIX_SEMAPHORES
Anthony Baxter19b23692005-03-16 04:15:07 +000019#if _POSIX_SEMAPHORES == -1
20#define HAVE_BROKEN_POSIX_SEMAPHORES
21#else
Martin v. Löwiscc898662002-03-17 09:53:51 +000022#include <semaphore.h>
23#include <errno.h>
24#endif
Anthony Baxter19b23692005-03-16 04:15:07 +000025#endif
Guido van Rossum66020991996-06-11 18:32:18 +000026
Martin v. Löwisb0233812002-12-11 13:12:30 +000027#if !defined(pthread_attr_default)
Guido van Rossumd6353e21997-05-13 17:51:13 +000028# define pthread_attr_default ((pthread_attr_t *)NULL)
Martin v. Löwisb0233812002-12-11 13:12:30 +000029#endif
30#if !defined(pthread_mutexattr_default)
Guido van Rossumd6353e21997-05-13 17:51:13 +000031# define pthread_mutexattr_default ((pthread_mutexattr_t *)NULL)
Martin v. Löwisb0233812002-12-11 13:12:30 +000032#endif
33#if !defined(pthread_condattr_default)
Guido van Rossumd6353e21997-05-13 17:51:13 +000034# define pthread_condattr_default ((pthread_condattr_t *)NULL)
Guido van Rossum1a623111996-08-08 18:53:41 +000035#endif
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000036
Guido van Rossumd6353e21997-05-13 17:51:13 +000037
Martin v. Löwiscc898662002-03-17 09:53:51 +000038/* Whether or not to use semaphores directly rather than emulating them with
39 * mutexes and condition variables:
40 */
Martin v. Löwisdfc33fd2003-01-21 10:14:41 +000041#if defined(_POSIX_SEMAPHORES) && !defined(HAVE_BROKEN_POSIX_SEMAPHORES)
Martin v. Löwiscc898662002-03-17 09:53:51 +000042# define USE_SEMAPHORES
43#else
44# undef USE_SEMAPHORES
45#endif
46
47
Guido van Rossum80230992001-10-12 21:49:17 +000048/* On platforms that don't use standard POSIX threads pthread_sigmask()
49 * isn't present. DEC threads uses sigprocmask() instead as do most
50 * other UNIX International compliant systems that don't have the full
51 * pthread implementation.
52 */
Jason Tishlerfac083d2003-07-22 15:20:49 +000053#if defined(HAVE_PTHREAD_SIGMASK) && !defined(HAVE_BROKEN_PTHREAD_SIGMASK)
Guido van Rossum80230992001-10-12 21:49:17 +000054# define SET_THREAD_SIGMASK pthread_sigmask
55#else
56# define SET_THREAD_SIGMASK sigprocmask
57#endif
58
59
Guido van Rossumb98b1b31994-05-11 08:42:04 +000060/* A pthread mutex isn't sufficient to model the Python lock type
61 * because, according to Draft 5 of the docs (P1003.4a/D5), both of the
62 * following are undefined:
63 * -> a thread tries to lock a mutex it already has locked
64 * -> a thread tries to unlock a mutex locked by a different thread
65 * pthread mutexes are designed for serializing threads over short pieces
66 * of code anyway, so wouldn't be an appropriate implementation of
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000067 * Python's locks regardless.
Guido van Rossumb98b1b31994-05-11 08:42:04 +000068 *
69 * The pthread_lock struct implements a Python lock as a "locked?" bit
70 * and a <condition, mutex> pair. In general, if the bit can be acquired
71 * instantly, it is, else the pair is used to block the thread until the
72 * bit is cleared. 9 May 1994 tim@ksr.com
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000073 */
Guido van Rossumb98b1b31994-05-11 08:42:04 +000074
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000075typedef struct {
Guido van Rossumb98b1b31994-05-11 08:42:04 +000076 char locked; /* 0=unlocked, 1=locked */
77 /* a <cond, mutex> pair to handle an acquire of a locked lock */
78 pthread_cond_t lock_released;
79 pthread_mutex_t mut;
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000080} pthread_lock;
81
Guido van Rossum9e46e561998-10-07 16:39:47 +000082#define CHECK_STATUS(name) if (status != 0) { perror(name); error = 1; }
Guido van Rossumb98b1b31994-05-11 08:42:04 +000083
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000084/*
85 * Initialization.
86 */
Guido van Rossum9e46e561998-10-07 16:39:47 +000087
88#ifdef _HAVE_BSDI
Thomas Woutersf70ef4f2000-07-22 18:47:25 +000089static
90void _noop(void)
Guido van Rossum9e46e561998-10-07 16:39:47 +000091{
92}
93
Thomas Woutersf70ef4f2000-07-22 18:47:25 +000094static void
95PyThread__init_thread(void)
Guido van Rossum9e46e561998-10-07 16:39:47 +000096{
97 /* DO AN INIT BY STARTING THE THREAD */
98 static int dummy = 0;
99 pthread_t thread1;
100 pthread_create(&thread1, NULL, (void *) _noop, &dummy);
101 pthread_join(thread1, NULL);
102}
103
104#else /* !_HAVE_BSDI */
105
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000106static void
107PyThread__init_thread(void)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000108{
Guido van Rossumd21744a1998-09-10 03:04:40 +0000109#if defined(_AIX) && defined(__GNUC__)
110 pthread_init();
111#endif
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000112}
113
Guido van Rossum9e46e561998-10-07 16:39:47 +0000114#endif /* !_HAVE_BSDI */
115
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000116/*
117 * Thread support.
118 */
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000119
120
Guido van Rossum3c288632001-10-16 21:13:49 +0000121long
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000122PyThread_start_new_thread(void (*func)(void *), void *arg)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000123{
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000124 pthread_t th;
Martin v. Löwis910ae622003-04-19 07:44:52 +0000125 int status;
Guido van Rossumd0b69ec2001-09-10 14:10:54 +0000126#if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
Jack Jansenc51395d2001-08-29 15:24:53 +0000127 pthread_attr_t attrs;
128#endif
Guido van Rossum65d5b571998-12-21 19:32:43 +0000129 dprintf(("PyThread_start_new_thread called\n"));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000130 if (!initialized)
Guido van Rossum65d5b571998-12-21 19:32:43 +0000131 PyThread_init_thread();
Guido van Rossumd6353e21997-05-13 17:51:13 +0000132
Guido van Rossumd0b69ec2001-09-10 14:10:54 +0000133#if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
Jack Jansenc51395d2001-08-29 15:24:53 +0000134 pthread_attr_init(&attrs);
Guido van Rossumd0b69ec2001-09-10 14:10:54 +0000135#endif
136#ifdef THREAD_STACK_SIZE
Jack Jansenc51395d2001-08-29 15:24:53 +0000137 pthread_attr_setstacksize(&attrs, THREAD_STACK_SIZE);
138#endif
Hye-Shik Chang30e97db2004-03-04 06:35:57 +0000139#if defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) && !defined(__FreeBSD__)
Guido van Rossumd0b69ec2001-09-10 14:10:54 +0000140 pthread_attr_setscope(&attrs, PTHREAD_SCOPE_SYSTEM);
141#endif
Guido van Rossum80230992001-10-12 21:49:17 +0000142
Martin v. Löwis910ae622003-04-19 07:44:52 +0000143 status = pthread_create(&th,
Guido van Rossumd0b69ec2001-09-10 14:10:54 +0000144#if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
Jack Jansenc51395d2001-08-29 15:24:53 +0000145 &attrs,
146#else
Guido van Rossumd6353e21997-05-13 17:51:13 +0000147 (pthread_attr_t*)NULL,
Jack Jansenc51395d2001-08-29 15:24:53 +0000148#endif
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000149 (void* (*)(void *))func,
Guido van Rossumd6353e21997-05-13 17:51:13 +0000150 (void *)arg
Guido van Rossumd6353e21997-05-13 17:51:13 +0000151 );
Guido van Rossum80230992001-10-12 21:49:17 +0000152
Fred Drake03459a52001-11-09 16:00:41 +0000153#if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
Jack Jansenc51395d2001-08-29 15:24:53 +0000154 pthread_attr_destroy(&attrs);
155#endif
Martin v. Löwis910ae622003-04-19 07:44:52 +0000156 if (status != 0)
157 return -1;
158
Martin v. Löwis910ae622003-04-19 07:44:52 +0000159 pthread_detach(th);
Martin v. Löwis910ae622003-04-19 07:44:52 +0000160
Guido van Rossum3c288632001-10-16 21:13:49 +0000161#if SIZEOF_PTHREAD_T <= SIZEOF_LONG
162 return (long) th;
163#else
164 return (long) *(long *) &th;
165#endif
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000166}
167
Trent Mick635f6fb2000-08-23 21:33:05 +0000168/* XXX This implementation is considered (to quote Tim Peters) "inherently
169 hosed" because:
Skip Montanaro6babcc22004-03-03 08:42:23 +0000170 - It does not guarantee the promise that a non-zero integer is returned.
Trent Mick635f6fb2000-08-23 21:33:05 +0000171 - The cast to long is inherently unsafe.
172 - It is not clear that the 'volatile' (for AIX?) and ugly casting in the
173 latter return statement (for Alpha OSF/1) are any longer necessary.
174*/
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000175long
176PyThread_get_thread_ident(void)
Guido van Rossume944da81994-05-23 12:43:41 +0000177{
Guido van Rossum44ee4791998-08-27 19:21:53 +0000178 volatile pthread_t threadid;
Guido van Rossume944da81994-05-23 12:43:41 +0000179 if (!initialized)
Guido van Rossum65d5b571998-12-21 19:32:43 +0000180 PyThread_init_thread();
Guido van Rossum2565bff1995-01-09 17:50:47 +0000181 /* Jump through some hoops for Alpha OSF/1 */
182 threadid = pthread_self();
Trent Mick635f6fb2000-08-23 21:33:05 +0000183#if SIZEOF_PTHREAD_T <= SIZEOF_LONG
184 return (long) threadid;
185#else
Guido van Rossum2565bff1995-01-09 17:50:47 +0000186 return (long) *(long *) &threadid;
Trent Mick635f6fb2000-08-23 21:33:05 +0000187#endif
Guido van Rossume944da81994-05-23 12:43:41 +0000188}
189
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000190static void
191do_PyThread_exit_thread(int no_cleanup)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000192{
Guido van Rossum65d5b571998-12-21 19:32:43 +0000193 dprintf(("PyThread_exit_thread called\n"));
Guido van Rossum730806d1998-04-10 22:27:42 +0000194 if (!initialized) {
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000195 if (no_cleanup)
196 _exit(0);
197 else
198 exit(0);
Guido van Rossum730806d1998-04-10 22:27:42 +0000199 }
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000200}
201
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000202void
203PyThread_exit_thread(void)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000204{
Guido van Rossum65d5b571998-12-21 19:32:43 +0000205 do_PyThread_exit_thread(0);
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000206}
207
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000208void
209PyThread__exit_thread(void)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000210{
Guido van Rossum65d5b571998-12-21 19:32:43 +0000211 do_PyThread_exit_thread(1);
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000212}
213
214#ifndef NO_EXIT_PROG
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000215static void
216do_PyThread_exit_prog(int status, int no_cleanup)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000217{
Guido van Rossum65d5b571998-12-21 19:32:43 +0000218 dprintf(("PyThread_exit_prog(%d) called\n", status));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000219 if (!initialized)
220 if (no_cleanup)
221 _exit(status);
222 else
223 exit(status);
224}
225
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000226void
227PyThread_exit_prog(int status)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000228{
Guido van Rossum65d5b571998-12-21 19:32:43 +0000229 do_PyThread_exit_prog(status, 0);
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000230}
231
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000232void
233PyThread__exit_prog(int status)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000234{
Guido van Rossum65d5b571998-12-21 19:32:43 +0000235 do_PyThread_exit_prog(status, 1);
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000236}
237#endif /* NO_EXIT_PROG */
238
Martin v. Löwiscc898662002-03-17 09:53:51 +0000239#ifdef USE_SEMAPHORES
240
241/*
242 * Lock support.
243 */
244
245PyThread_type_lock
246PyThread_allocate_lock(void)
247{
248 sem_t *lock;
249 int status, error = 0;
250
251 dprintf(("PyThread_allocate_lock called\n"));
252 if (!initialized)
253 PyThread_init_thread();
254
255 lock = (sem_t *)malloc(sizeof(sem_t));
256
257 if (lock) {
258 status = sem_init(lock,0,1);
259 CHECK_STATUS("sem_init");
260
261 if (error) {
262 free((void *)lock);
263 lock = NULL;
264 }
265 }
266
267 dprintf(("PyThread_allocate_lock() -> %p\n", lock));
268 return (PyThread_type_lock)lock;
269}
270
271void
272PyThread_free_lock(PyThread_type_lock lock)
273{
274 sem_t *thelock = (sem_t *)lock;
275 int status, error = 0;
276
277 dprintf(("PyThread_free_lock(%p) called\n", lock));
278
279 if (!thelock)
280 return;
281
282 status = sem_destroy(thelock);
283 CHECK_STATUS("sem_destroy");
284
285 free((void *)thelock);
286}
287
288/*
289 * As of February 2002, Cygwin thread implementations mistakenly report error
290 * codes in the return value of the sem_ calls (like the pthread_ functions).
291 * Correct implementations return -1 and put the code in errno. This supports
292 * either.
293 */
294static int
295fix_status(int status)
296{
297 return (status == -1) ? errno : status;
298}
299
300int
301PyThread_acquire_lock(PyThread_type_lock lock, int waitflag)
302{
303 int success;
304 sem_t *thelock = (sem_t *)lock;
305 int status, error = 0;
306
307 dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag));
308
309 do {
310 if (waitflag)
311 status = fix_status(sem_wait(thelock));
312 else
313 status = fix_status(sem_trywait(thelock));
314 } while (status == EINTR); /* Retry if interrupted by a signal */
315
316 if (waitflag) {
317 CHECK_STATUS("sem_wait");
318 } else if (status != EAGAIN) {
319 CHECK_STATUS("sem_trywait");
320 }
321
322 success = (status == 0) ? 1 : 0;
323
324 dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success));
325 return success;
326}
327
328void
329PyThread_release_lock(PyThread_type_lock lock)
330{
331 sem_t *thelock = (sem_t *)lock;
332 int status, error = 0;
333
334 dprintf(("PyThread_release_lock(%p) called\n", lock));
335
336 status = sem_post(thelock);
337 CHECK_STATUS("sem_post");
338}
339
340#else /* USE_SEMAPHORES */
341
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000342/*
343 * Lock support.
344 */
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000345PyThread_type_lock
346PyThread_allocate_lock(void)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000347{
348 pthread_lock *lock;
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000349 int status, error = 0;
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000350
Guido van Rossum65d5b571998-12-21 19:32:43 +0000351 dprintf(("PyThread_allocate_lock called\n"));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000352 if (!initialized)
Guido van Rossum65d5b571998-12-21 19:32:43 +0000353 PyThread_init_thread();
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000354
355 lock = (pthread_lock *) malloc(sizeof(pthread_lock));
Guido van Rossum9e46e561998-10-07 16:39:47 +0000356 memset((void *)lock, '\0', sizeof(pthread_lock));
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000357 if (lock) {
358 lock->locked = 0;
359
360 status = pthread_mutex_init(&lock->mut,
361 pthread_mutexattr_default);
362 CHECK_STATUS("pthread_mutex_init");
363
364 status = pthread_cond_init(&lock->lock_released,
365 pthread_condattr_default);
366 CHECK_STATUS("pthread_cond_init");
367
368 if (error) {
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000369 free((void *)lock);
370 lock = 0;
371 }
372 }
373
Fred Drakea44d3532000-06-30 15:01:00 +0000374 dprintf(("PyThread_allocate_lock() -> %p\n", lock));
Guido van Rossum65d5b571998-12-21 19:32:43 +0000375 return (PyThread_type_lock) lock;
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000376}
377
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000378void
379PyThread_free_lock(PyThread_type_lock lock)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000380{
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000381 pthread_lock *thelock = (pthread_lock *)lock;
382 int status, error = 0;
383
Fred Drakea44d3532000-06-30 15:01:00 +0000384 dprintf(("PyThread_free_lock(%p) called\n", lock));
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000385
386 status = pthread_mutex_destroy( &thelock->mut );
387 CHECK_STATUS("pthread_mutex_destroy");
388
389 status = pthread_cond_destroy( &thelock->lock_released );
390 CHECK_STATUS("pthread_cond_destroy");
391
392 free((void *)thelock);
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000393}
394
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000395int
396PyThread_acquire_lock(PyThread_type_lock lock, int waitflag)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000397{
398 int success;
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000399 pthread_lock *thelock = (pthread_lock *)lock;
400 int status, error = 0;
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000401
Fred Drakea44d3532000-06-30 15:01:00 +0000402 dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000403
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000404 status = pthread_mutex_lock( &thelock->mut );
405 CHECK_STATUS("pthread_mutex_lock[1]");
406 success = thelock->locked == 0;
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000407
408 if ( !success && waitflag ) {
409 /* continue trying until we get the lock */
410
411 /* mut must be locked by me -- part of the condition
412 * protocol */
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000413 while ( thelock->locked ) {
414 status = pthread_cond_wait(&thelock->lock_released,
415 &thelock->mut);
416 CHECK_STATUS("pthread_cond_wait");
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000417 }
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000418 success = 1;
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000419 }
Martin v. Löwis1509a152003-04-18 11:11:09 +0000420 if (success) thelock->locked = 1;
421 status = pthread_mutex_unlock( &thelock->mut );
422 CHECK_STATUS("pthread_mutex_unlock[1]");
423
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000424 if (error) success = 0;
Fred Drakea44d3532000-06-30 15:01:00 +0000425 dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000426 return success;
427}
428
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000429void
430PyThread_release_lock(PyThread_type_lock lock)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000431{
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000432 pthread_lock *thelock = (pthread_lock *)lock;
433 int status, error = 0;
434
Fred Drakea44d3532000-06-30 15:01:00 +0000435 dprintf(("PyThread_release_lock(%p) called\n", lock));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000436
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000437 status = pthread_mutex_lock( &thelock->mut );
438 CHECK_STATUS("pthread_mutex_lock[3]");
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000439
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000440 thelock->locked = 0;
441
442 status = pthread_mutex_unlock( &thelock->mut );
443 CHECK_STATUS("pthread_mutex_unlock[3]");
444
445 /* wake up someone (anyone, if any) waiting on the lock */
446 status = pthread_cond_signal( &thelock->lock_released );
447 CHECK_STATUS("pthread_cond_signal");
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000448}
Martin v. Löwiscc898662002-03-17 09:53:51 +0000449
450#endif /* USE_SEMAPHORES */