Lines Matching refs:sem

439 int uv_sem_init(uv_sem_t* sem, unsigned int value) {  in uv_sem_init()  argument
442 err = semaphore_create(mach_task_self(), sem, SYNC_POLICY_FIFO, value); in uv_sem_init()
455 void uv_sem_destroy(uv_sem_t* sem) { in uv_sem_destroy() argument
456 if (semaphore_destroy(mach_task_self(), *sem)) in uv_sem_destroy()
461 void uv_sem_post(uv_sem_t* sem) { in uv_sem_post() argument
462 if (semaphore_signal(*sem)) in uv_sem_post()
467 void uv_sem_wait(uv_sem_t* sem) { in uv_sem_wait() argument
471 r = semaphore_wait(*sem); in uv_sem_wait()
479 int uv_sem_trywait(uv_sem_t* sem) { in uv_sem_trywait() argument
486 err = semaphore_timedwait(*sem, interval); in uv_sem_trywait()
541 uv_semaphore_t* sem; in uv__custom_sem_init() local
543 sem = uv__malloc(sizeof(*sem)); in uv__custom_sem_init()
544 if (sem == NULL) in uv__custom_sem_init()
547 if ((err = uv_mutex_init(&sem->mutex)) != 0) { in uv__custom_sem_init()
548 uv__free(sem); in uv__custom_sem_init()
552 if ((err = uv_cond_init(&sem->cond)) != 0) { in uv__custom_sem_init()
553 uv_mutex_destroy(&sem->mutex); in uv__custom_sem_init()
554 uv__free(sem); in uv__custom_sem_init()
558 sem->value = value; in uv__custom_sem_init()
559 *(uv_semaphore_t**)sem_ = sem; in uv__custom_sem_init()
565 uv_semaphore_t* sem; in uv__custom_sem_destroy() local
567 sem = *(uv_semaphore_t**)sem_; in uv__custom_sem_destroy()
568 uv_cond_destroy(&sem->cond); in uv__custom_sem_destroy()
569 uv_mutex_destroy(&sem->mutex); in uv__custom_sem_destroy()
570 uv__free(sem); in uv__custom_sem_destroy()
575 uv_semaphore_t* sem; in uv__custom_sem_post() local
577 sem = *(uv_semaphore_t**)sem_; in uv__custom_sem_post()
578 uv_mutex_lock(&sem->mutex); in uv__custom_sem_post()
579 sem->value++; in uv__custom_sem_post()
580 if (sem->value == 1) in uv__custom_sem_post()
581 uv_cond_signal(&sem->cond); /* Release one to replace us. */ in uv__custom_sem_post()
582 uv_mutex_unlock(&sem->mutex); in uv__custom_sem_post()
587 uv_semaphore_t* sem; in uv__custom_sem_wait() local
589 sem = *(uv_semaphore_t**)sem_; in uv__custom_sem_wait()
590 uv_mutex_lock(&sem->mutex); in uv__custom_sem_wait()
591 while (sem->value == 0) in uv__custom_sem_wait()
592 uv_cond_wait(&sem->cond, &sem->mutex); in uv__custom_sem_wait()
593 sem->value--; in uv__custom_sem_wait()
594 uv_mutex_unlock(&sem->mutex); in uv__custom_sem_wait()
599 uv_semaphore_t* sem; in uv__custom_sem_trywait() local
601 sem = *(uv_semaphore_t**)sem_; in uv__custom_sem_trywait()
602 if (uv_mutex_trylock(&sem->mutex) != 0) in uv__custom_sem_trywait()
605 if (sem->value == 0) { in uv__custom_sem_trywait()
606 uv_mutex_unlock(&sem->mutex); in uv__custom_sem_trywait()
610 sem->value--; in uv__custom_sem_trywait()
611 uv_mutex_unlock(&sem->mutex); in uv__custom_sem_trywait()
616 static int uv__sem_init(uv_sem_t* sem, unsigned int value) { in uv__sem_init() argument
617 if (sem_init(sem, 0, value)) in uv__sem_init()
623 static void uv__sem_destroy(uv_sem_t* sem) { in uv__sem_destroy() argument
624 if (sem_destroy(sem)) in uv__sem_destroy()
629 static void uv__sem_post(uv_sem_t* sem) { in uv__sem_post() argument
630 if (sem_post(sem)) in uv__sem_post()
635 static void uv__sem_wait(uv_sem_t* sem) { in uv__sem_wait() argument
639 r = sem_wait(sem); in uv__sem_wait()
647 static int uv__sem_trywait(uv_sem_t* sem) { in uv__sem_trywait() argument
651 r = sem_trywait(sem); in uv__sem_trywait()
663 int uv_sem_init(uv_sem_t* sem, unsigned int value) { in uv_sem_init() argument
669 return uv__custom_sem_init(sem, value); in uv_sem_init()
671 return uv__sem_init(sem, value); in uv_sem_init()
675 void uv_sem_destroy(uv_sem_t* sem) { in uv_sem_destroy() argument
677 uv__custom_sem_destroy(sem); in uv_sem_destroy()
679 uv__sem_destroy(sem); in uv_sem_destroy()
683 void uv_sem_post(uv_sem_t* sem) { in uv_sem_post() argument
685 uv__custom_sem_post(sem); in uv_sem_post()
687 uv__sem_post(sem); in uv_sem_post()
691 void uv_sem_wait(uv_sem_t* sem) { in uv_sem_wait() argument
693 uv__custom_sem_wait(sem); in uv_sem_wait()
695 uv__sem_wait(sem); in uv_sem_wait()
699 int uv_sem_trywait(uv_sem_t* sem) { in uv_sem_trywait() argument
701 return uv__custom_sem_trywait(sem); in uv_sem_trywait()
703 return uv__sem_trywait(sem); in uv_sem_trywait()