blob: dd1616c71642e9f74d1329d042256affb411ec64 [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
19#include <semaphore.h>
20#include <errno.h>
21#endif
Guido van Rossum66020991996-06-11 18:32:18 +000022
Martin v. Löwisb0233812002-12-11 13:12:30 +000023#if !defined(pthread_attr_default)
Guido van Rossumd6353e21997-05-13 17:51:13 +000024# define pthread_attr_default ((pthread_attr_t *)NULL)
Martin v. Löwisb0233812002-12-11 13:12:30 +000025#endif
26#if !defined(pthread_mutexattr_default)
Guido van Rossumd6353e21997-05-13 17:51:13 +000027# define pthread_mutexattr_default ((pthread_mutexattr_t *)NULL)
Martin v. Löwisb0233812002-12-11 13:12:30 +000028#endif
29#if !defined(pthread_condattr_default)
Guido van Rossumd6353e21997-05-13 17:51:13 +000030# define pthread_condattr_default ((pthread_condattr_t *)NULL)
Guido van Rossum1a623111996-08-08 18:53:41 +000031#endif
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000032
Guido van Rossumd6353e21997-05-13 17:51:13 +000033
Martin v. Löwiscc898662002-03-17 09:53:51 +000034/* Whether or not to use semaphores directly rather than emulating them with
35 * mutexes and condition variables:
36 */
Martin v. Löwisdfc33fd2003-01-21 10:14:41 +000037#if defined(_POSIX_SEMAPHORES) && !defined(HAVE_BROKEN_POSIX_SEMAPHORES)
Martin v. Löwiscc898662002-03-17 09:53:51 +000038# define USE_SEMAPHORES
39#else
40# undef USE_SEMAPHORES
41#endif
42
43
Guido van Rossum80230992001-10-12 21:49:17 +000044/* On platforms that don't use standard POSIX threads pthread_sigmask()
45 * isn't present. DEC threads uses sigprocmask() instead as do most
46 * other UNIX International compliant systems that don't have the full
47 * pthread implementation.
48 */
Jason Tishlerfac083d2003-07-22 15:20:49 +000049#if defined(HAVE_PTHREAD_SIGMASK) && !defined(HAVE_BROKEN_PTHREAD_SIGMASK)
Guido van Rossum80230992001-10-12 21:49:17 +000050# define SET_THREAD_SIGMASK pthread_sigmask
51#else
52# define SET_THREAD_SIGMASK sigprocmask
53#endif
54
55
Guido van Rossumb98b1b31994-05-11 08:42:04 +000056/* A pthread mutex isn't sufficient to model the Python lock type
57 * because, according to Draft 5 of the docs (P1003.4a/D5), both of the
58 * following are undefined:
59 * -> a thread tries to lock a mutex it already has locked
60 * -> a thread tries to unlock a mutex locked by a different thread
61 * pthread mutexes are designed for serializing threads over short pieces
62 * of code anyway, so wouldn't be an appropriate implementation of
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000063 * Python's locks regardless.
Guido van Rossumb98b1b31994-05-11 08:42:04 +000064 *
65 * The pthread_lock struct implements a Python lock as a "locked?" bit
66 * and a <condition, mutex> pair. In general, if the bit can be acquired
67 * instantly, it is, else the pair is used to block the thread until the
68 * bit is cleared. 9 May 1994 tim@ksr.com
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000069 */
Guido van Rossumb98b1b31994-05-11 08:42:04 +000070
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000071typedef struct {
Guido van Rossumb98b1b31994-05-11 08:42:04 +000072 char locked; /* 0=unlocked, 1=locked */
73 /* a <cond, mutex> pair to handle an acquire of a locked lock */
74 pthread_cond_t lock_released;
75 pthread_mutex_t mut;
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000076} pthread_lock;
77
Guido van Rossum9e46e561998-10-07 16:39:47 +000078#define CHECK_STATUS(name) if (status != 0) { perror(name); error = 1; }
Guido van Rossumb98b1b31994-05-11 08:42:04 +000079
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +000080/*
81 * Initialization.
82 */
Guido van Rossum9e46e561998-10-07 16:39:47 +000083
84#ifdef _HAVE_BSDI
Thomas Woutersf70ef4f2000-07-22 18:47:25 +000085static
86void _noop(void)
Guido van Rossum9e46e561998-10-07 16:39:47 +000087{
88}
89
Thomas Woutersf70ef4f2000-07-22 18:47:25 +000090static void
91PyThread__init_thread(void)
Guido van Rossum9e46e561998-10-07 16:39:47 +000092{
93 /* DO AN INIT BY STARTING THE THREAD */
94 static int dummy = 0;
95 pthread_t thread1;
96 pthread_create(&thread1, NULL, (void *) _noop, &dummy);
97 pthread_join(thread1, NULL);
98}
99
100#else /* !_HAVE_BSDI */
101
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000102static void
103PyThread__init_thread(void)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000104{
Guido van Rossumd21744a1998-09-10 03:04:40 +0000105#if defined(_AIX) && defined(__GNUC__)
106 pthread_init();
107#endif
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000108}
109
Guido van Rossum9e46e561998-10-07 16:39:47 +0000110#endif /* !_HAVE_BSDI */
111
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000112/*
113 * Thread support.
114 */
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000115
116
Guido van Rossum3c288632001-10-16 21:13:49 +0000117long
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000118PyThread_start_new_thread(void (*func)(void *), void *arg)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000119{
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000120 pthread_t th;
Martin v. Löwis910ae622003-04-19 07:44:52 +0000121 int status;
Guido van Rossumd0b69ec2001-09-10 14:10:54 +0000122#if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
Jack Jansenc51395d2001-08-29 15:24:53 +0000123 pthread_attr_t attrs;
124#endif
Guido van Rossum65d5b571998-12-21 19:32:43 +0000125 dprintf(("PyThread_start_new_thread called\n"));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000126 if (!initialized)
Guido van Rossum65d5b571998-12-21 19:32:43 +0000127 PyThread_init_thread();
Guido van Rossumd6353e21997-05-13 17:51:13 +0000128
Guido van Rossumd0b69ec2001-09-10 14:10:54 +0000129#if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
Jack Jansenc51395d2001-08-29 15:24:53 +0000130 pthread_attr_init(&attrs);
Guido van Rossumd0b69ec2001-09-10 14:10:54 +0000131#endif
132#ifdef THREAD_STACK_SIZE
Jack Jansenc51395d2001-08-29 15:24:53 +0000133 pthread_attr_setstacksize(&attrs, THREAD_STACK_SIZE);
134#endif
Hye-Shik Chang30e97db2004-03-04 06:35:57 +0000135#if defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) && !defined(__FreeBSD__)
Guido van Rossumd0b69ec2001-09-10 14:10:54 +0000136 pthread_attr_setscope(&attrs, PTHREAD_SCOPE_SYSTEM);
137#endif
Guido van Rossum80230992001-10-12 21:49:17 +0000138
Martin v. Löwis910ae622003-04-19 07:44:52 +0000139 status = pthread_create(&th,
Guido van Rossumd0b69ec2001-09-10 14:10:54 +0000140#if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
Jack Jansenc51395d2001-08-29 15:24:53 +0000141 &attrs,
142#else
Guido van Rossumd6353e21997-05-13 17:51:13 +0000143 (pthread_attr_t*)NULL,
Jack Jansenc51395d2001-08-29 15:24:53 +0000144#endif
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000145 (void* (*)(void *))func,
Guido van Rossumd6353e21997-05-13 17:51:13 +0000146 (void *)arg
Guido van Rossumd6353e21997-05-13 17:51:13 +0000147 );
Guido van Rossum80230992001-10-12 21:49:17 +0000148
Fred Drake03459a52001-11-09 16:00:41 +0000149#if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
Jack Jansenc51395d2001-08-29 15:24:53 +0000150 pthread_attr_destroy(&attrs);
151#endif
Martin v. Löwis910ae622003-04-19 07:44:52 +0000152 if (status != 0)
153 return -1;
154
Martin v. Löwis910ae622003-04-19 07:44:52 +0000155 pthread_detach(th);
Martin v. Löwis910ae622003-04-19 07:44:52 +0000156
Guido van Rossum3c288632001-10-16 21:13:49 +0000157#if SIZEOF_PTHREAD_T <= SIZEOF_LONG
158 return (long) th;
159#else
160 return (long) *(long *) &th;
161#endif
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000162}
163
Trent Mick635f6fb2000-08-23 21:33:05 +0000164/* XXX This implementation is considered (to quote Tim Peters) "inherently
165 hosed" because:
Skip Montanaro6babcc22004-03-03 08:42:23 +0000166 - It does not guarantee the promise that a non-zero integer is returned.
Trent Mick635f6fb2000-08-23 21:33:05 +0000167 - The cast to long is inherently unsafe.
168 - It is not clear that the 'volatile' (for AIX?) and ugly casting in the
169 latter return statement (for Alpha OSF/1) are any longer necessary.
170*/
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000171long
172PyThread_get_thread_ident(void)
Guido van Rossume944da81994-05-23 12:43:41 +0000173{
Guido van Rossum44ee4791998-08-27 19:21:53 +0000174 volatile pthread_t threadid;
Guido van Rossume944da81994-05-23 12:43:41 +0000175 if (!initialized)
Guido van Rossum65d5b571998-12-21 19:32:43 +0000176 PyThread_init_thread();
Guido van Rossum2565bff1995-01-09 17:50:47 +0000177 /* Jump through some hoops for Alpha OSF/1 */
178 threadid = pthread_self();
Trent Mick635f6fb2000-08-23 21:33:05 +0000179#if SIZEOF_PTHREAD_T <= SIZEOF_LONG
180 return (long) threadid;
181#else
Guido van Rossum2565bff1995-01-09 17:50:47 +0000182 return (long) *(long *) &threadid;
Trent Mick635f6fb2000-08-23 21:33:05 +0000183#endif
Guido van Rossume944da81994-05-23 12:43:41 +0000184}
185
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000186static void
187do_PyThread_exit_thread(int no_cleanup)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000188{
Guido van Rossum65d5b571998-12-21 19:32:43 +0000189 dprintf(("PyThread_exit_thread called\n"));
Guido van Rossum730806d1998-04-10 22:27:42 +0000190 if (!initialized) {
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000191 if (no_cleanup)
192 _exit(0);
193 else
194 exit(0);
Guido van Rossum730806d1998-04-10 22:27:42 +0000195 }
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000196}
197
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000198void
199PyThread_exit_thread(void)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000200{
Guido van Rossum65d5b571998-12-21 19:32:43 +0000201 do_PyThread_exit_thread(0);
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000202}
203
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000204void
205PyThread__exit_thread(void)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000206{
Guido van Rossum65d5b571998-12-21 19:32:43 +0000207 do_PyThread_exit_thread(1);
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000208}
209
210#ifndef NO_EXIT_PROG
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000211static void
212do_PyThread_exit_prog(int status, int no_cleanup)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000213{
Guido van Rossum65d5b571998-12-21 19:32:43 +0000214 dprintf(("PyThread_exit_prog(%d) called\n", status));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000215 if (!initialized)
216 if (no_cleanup)
217 _exit(status);
218 else
219 exit(status);
220}
221
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000222void
223PyThread_exit_prog(int status)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000224{
Guido van Rossum65d5b571998-12-21 19:32:43 +0000225 do_PyThread_exit_prog(status, 0);
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000226}
227
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000228void
229PyThread__exit_prog(int status)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000230{
Guido van Rossum65d5b571998-12-21 19:32:43 +0000231 do_PyThread_exit_prog(status, 1);
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000232}
233#endif /* NO_EXIT_PROG */
234
Martin v. Löwiscc898662002-03-17 09:53:51 +0000235#ifdef USE_SEMAPHORES
236
237/*
238 * Lock support.
239 */
240
241PyThread_type_lock
242PyThread_allocate_lock(void)
243{
244 sem_t *lock;
245 int status, error = 0;
246
247 dprintf(("PyThread_allocate_lock called\n"));
248 if (!initialized)
249 PyThread_init_thread();
250
251 lock = (sem_t *)malloc(sizeof(sem_t));
252
253 if (lock) {
254 status = sem_init(lock,0,1);
255 CHECK_STATUS("sem_init");
256
257 if (error) {
258 free((void *)lock);
259 lock = NULL;
260 }
261 }
262
263 dprintf(("PyThread_allocate_lock() -> %p\n", lock));
264 return (PyThread_type_lock)lock;
265}
266
267void
268PyThread_free_lock(PyThread_type_lock lock)
269{
270 sem_t *thelock = (sem_t *)lock;
271 int status, error = 0;
272
273 dprintf(("PyThread_free_lock(%p) called\n", lock));
274
275 if (!thelock)
276 return;
277
278 status = sem_destroy(thelock);
279 CHECK_STATUS("sem_destroy");
280
281 free((void *)thelock);
282}
283
284/*
285 * As of February 2002, Cygwin thread implementations mistakenly report error
286 * codes in the return value of the sem_ calls (like the pthread_ functions).
287 * Correct implementations return -1 and put the code in errno. This supports
288 * either.
289 */
290static int
291fix_status(int status)
292{
293 return (status == -1) ? errno : status;
294}
295
296int
297PyThread_acquire_lock(PyThread_type_lock lock, int waitflag)
298{
299 int success;
300 sem_t *thelock = (sem_t *)lock;
301 int status, error = 0;
302
303 dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag));
304
305 do {
306 if (waitflag)
307 status = fix_status(sem_wait(thelock));
308 else
309 status = fix_status(sem_trywait(thelock));
310 } while (status == EINTR); /* Retry if interrupted by a signal */
311
312 if (waitflag) {
313 CHECK_STATUS("sem_wait");
314 } else if (status != EAGAIN) {
315 CHECK_STATUS("sem_trywait");
316 }
317
318 success = (status == 0) ? 1 : 0;
319
320 dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success));
321 return success;
322}
323
324void
325PyThread_release_lock(PyThread_type_lock lock)
326{
327 sem_t *thelock = (sem_t *)lock;
328 int status, error = 0;
329
330 dprintf(("PyThread_release_lock(%p) called\n", lock));
331
332 status = sem_post(thelock);
333 CHECK_STATUS("sem_post");
334}
335
336#else /* USE_SEMAPHORES */
337
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000338/*
339 * Lock support.
340 */
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000341PyThread_type_lock
342PyThread_allocate_lock(void)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000343{
344 pthread_lock *lock;
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000345 int status, error = 0;
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000346
Guido van Rossum65d5b571998-12-21 19:32:43 +0000347 dprintf(("PyThread_allocate_lock called\n"));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000348 if (!initialized)
Guido van Rossum65d5b571998-12-21 19:32:43 +0000349 PyThread_init_thread();
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000350
351 lock = (pthread_lock *) malloc(sizeof(pthread_lock));
Guido van Rossum9e46e561998-10-07 16:39:47 +0000352 memset((void *)lock, '\0', sizeof(pthread_lock));
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000353 if (lock) {
354 lock->locked = 0;
355
356 status = pthread_mutex_init(&lock->mut,
357 pthread_mutexattr_default);
358 CHECK_STATUS("pthread_mutex_init");
359
360 status = pthread_cond_init(&lock->lock_released,
361 pthread_condattr_default);
362 CHECK_STATUS("pthread_cond_init");
363
364 if (error) {
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000365 free((void *)lock);
366 lock = 0;
367 }
368 }
369
Fred Drakea44d3532000-06-30 15:01:00 +0000370 dprintf(("PyThread_allocate_lock() -> %p\n", lock));
Guido van Rossum65d5b571998-12-21 19:32:43 +0000371 return (PyThread_type_lock) lock;
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000372}
373
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000374void
375PyThread_free_lock(PyThread_type_lock lock)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000376{
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000377 pthread_lock *thelock = (pthread_lock *)lock;
378 int status, error = 0;
379
Fred Drakea44d3532000-06-30 15:01:00 +0000380 dprintf(("PyThread_free_lock(%p) called\n", lock));
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000381
382 status = pthread_mutex_destroy( &thelock->mut );
383 CHECK_STATUS("pthread_mutex_destroy");
384
385 status = pthread_cond_destroy( &thelock->lock_released );
386 CHECK_STATUS("pthread_cond_destroy");
387
388 free((void *)thelock);
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000389}
390
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000391int
392PyThread_acquire_lock(PyThread_type_lock lock, int waitflag)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000393{
394 int success;
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000395 pthread_lock *thelock = (pthread_lock *)lock;
396 int status, error = 0;
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000397
Fred Drakea44d3532000-06-30 15:01:00 +0000398 dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000399
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000400 status = pthread_mutex_lock( &thelock->mut );
401 CHECK_STATUS("pthread_mutex_lock[1]");
402 success = thelock->locked == 0;
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000403
404 if ( !success && waitflag ) {
405 /* continue trying until we get the lock */
406
407 /* mut must be locked by me -- part of the condition
408 * protocol */
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000409 while ( thelock->locked ) {
410 status = pthread_cond_wait(&thelock->lock_released,
411 &thelock->mut);
412 CHECK_STATUS("pthread_cond_wait");
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000413 }
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000414 success = 1;
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000415 }
Martin v. Löwis1509a152003-04-18 11:11:09 +0000416 if (success) thelock->locked = 1;
417 status = pthread_mutex_unlock( &thelock->mut );
418 CHECK_STATUS("pthread_mutex_unlock[1]");
419
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000420 if (error) success = 0;
Fred Drakea44d3532000-06-30 15:01:00 +0000421 dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000422 return success;
423}
424
Thomas Woutersf70ef4f2000-07-22 18:47:25 +0000425void
426PyThread_release_lock(PyThread_type_lock lock)
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000427{
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000428 pthread_lock *thelock = (pthread_lock *)lock;
429 int status, error = 0;
430
Fred Drakea44d3532000-06-30 15:01:00 +0000431 dprintf(("PyThread_release_lock(%p) called\n", lock));
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000432
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000433 status = pthread_mutex_lock( &thelock->mut );
434 CHECK_STATUS("pthread_mutex_lock[3]");
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000435
Guido van Rossumb98b1b31994-05-11 08:42:04 +0000436 thelock->locked = 0;
437
438 status = pthread_mutex_unlock( &thelock->mut );
439 CHECK_STATUS("pthread_mutex_unlock[3]");
440
441 /* wake up someone (anyone, if any) waiting on the lock */
442 status = pthread_cond_signal( &thelock->lock_released );
443 CHECK_STATUS("pthread_cond_signal");
Guido van Rossum2c8cb9f1994-05-09 15:12:46 +0000444}
Martin v. Löwiscc898662002-03-17 09:53:51 +0000445
446#endif /* USE_SEMAPHORES */