comparison Python/thread_pthread.h @ 21766:8b116a8449bd legacy-trunk

Remove the unused & broken PyThread_*_sema() functions and related constants. This closes SF patch #504215.
author Fred Drake <fdrake@acm.org>
date Sat, 19 Jan 2002 22:02:55 +0000
parents 884e57bf3ada
children 6c3e32357d91
comparison
equal deleted inserted replaced
21765:3685615d21b3 21766:8b116a8449bd
403 403
404 /* wake up someone (anyone, if any) waiting on the lock */ 404 /* wake up someone (anyone, if any) waiting on the lock */
405 status = pthread_cond_signal( &thelock->lock_released ); 405 status = pthread_cond_signal( &thelock->lock_released );
406 CHECK_STATUS("pthread_cond_signal"); 406 CHECK_STATUS("pthread_cond_signal");
407 } 407 }
408
409 /*
410 * Semaphore support.
411 */
412
413 struct semaphore {
414 pthread_mutex_t mutex;
415 pthread_cond_t cond;
416 int value;
417 };
418
419 PyThread_type_sema
420 PyThread_allocate_sema(int value)
421 {
422 struct semaphore *sema;
423 int status, error = 0;
424
425 dprintf(("PyThread_allocate_sema called\n"));
426 if (!initialized)
427 PyThread_init_thread();
428
429 sema = (struct semaphore *) malloc(sizeof(struct semaphore));
430 if (sema != NULL) {
431 sema->value = value;
432 status = pthread_mutex_init(&sema->mutex,
433 pthread_mutexattr_default);
434 CHECK_STATUS("pthread_mutex_init");
435 status = pthread_cond_init(&sema->cond,
436 pthread_condattr_default);
437 CHECK_STATUS("pthread_cond_init");
438 if (error) {
439 free((void *) sema);
440 sema = NULL;
441 }
442 }
443 dprintf(("PyThread_allocate_sema() -> %p\n", sema));
444 return (PyThread_type_sema) sema;
445 }
446
447 void
448 PyThread_free_sema(PyThread_type_sema sema)
449 {
450 int status, error = 0;
451 struct semaphore *thesema = (struct semaphore *) sema;
452
453 dprintf(("PyThread_free_sema(%p) called\n", sema));
454 status = pthread_cond_destroy(&thesema->cond);
455 CHECK_STATUS("pthread_cond_destroy");
456 status = pthread_mutex_destroy(&thesema->mutex);
457 CHECK_STATUS("pthread_mutex_destroy");
458 free((void *) thesema);
459 }
460
461 int
462 PyThread_down_sema(PyThread_type_sema sema, int waitflag)
463 {
464 int status, error = 0, success;
465 struct semaphore *thesema = (struct semaphore *) sema;
466
467 dprintf(("PyThread_down_sema(%p, %d) called\n", sema, waitflag));
468 status = pthread_mutex_lock(&thesema->mutex);
469 CHECK_STATUS("pthread_mutex_lock");
470 if (waitflag) {
471 while (!error && thesema->value <= 0) {
472 status = pthread_cond_wait(&thesema->cond,
473 &thesema->mutex);
474 CHECK_STATUS("pthread_cond_wait");
475 }
476 }
477 if (error)
478 success = 0;
479 else if (thesema->value > 0) {
480 thesema->value--;
481 success = 1;
482 }
483 else
484 success = 0;
485 status = pthread_mutex_unlock(&thesema->mutex);
486 CHECK_STATUS("pthread_mutex_unlock");
487 dprintf(("PyThread_down_sema(%p) return\n", sema));
488 return success;
489 }
490
491 void
492 PyThread_up_sema(PyThread_type_sema sema)
493 {
494 int status, error = 0;
495 struct semaphore *thesema = (struct semaphore *) sema;
496
497 dprintf(("PyThread_up_sema(%p)\n", sema));
498 status = pthread_mutex_lock(&thesema->mutex);
499 CHECK_STATUS("pthread_mutex_lock");
500 thesema->value++;
501 status = pthread_cond_signal(&thesema->cond);
502 CHECK_STATUS("pthread_cond_signal");
503 status = pthread_mutex_unlock(&thesema->mutex);
504 CHECK_STATUS("pthread_mutex_unlock");
505 }