Lines Matching refs:sem
446 int uv_sem_init(uv_sem_t* sem, unsigned int value) { in uv_sem_init() argument
449 err = semaphore_create(mach_task_self(), sem, SYNC_POLICY_FIFO, value); in uv_sem_init()
462 void uv_sem_destroy(uv_sem_t* sem) { in uv_sem_destroy() argument
463 if (semaphore_destroy(mach_task_self(), *sem)) in uv_sem_destroy()
468 void uv_sem_post(uv_sem_t* sem) { in uv_sem_post() argument
469 if (semaphore_signal(*sem)) in uv_sem_post()
474 void uv_sem_wait(uv_sem_t* sem) { in uv_sem_wait() argument
478 r = semaphore_wait(*sem); in uv_sem_wait()
486 int uv_sem_trywait(uv_sem_t* sem) { in uv_sem_trywait() argument
493 err = semaphore_timedwait(*sem, interval); in uv_sem_trywait()
548 uv_semaphore_t* sem; in uv__custom_sem_init() local
550 sem = uv__malloc(sizeof(*sem)); in uv__custom_sem_init()
551 if (sem == NULL) in uv__custom_sem_init()
554 if ((err = uv_mutex_init(&sem->mutex)) != 0) { in uv__custom_sem_init()
555 uv__free(sem); in uv__custom_sem_init()
559 if ((err = uv_cond_init(&sem->cond)) != 0) { in uv__custom_sem_init()
560 uv_mutex_destroy(&sem->mutex); in uv__custom_sem_init()
561 uv__free(sem); in uv__custom_sem_init()
565 sem->value = value; in uv__custom_sem_init()
566 *(uv_semaphore_t**)sem_ = sem; in uv__custom_sem_init()
572 uv_semaphore_t* sem; in uv__custom_sem_destroy() local
574 sem = *(uv_semaphore_t**)sem_; in uv__custom_sem_destroy()
575 uv_cond_destroy(&sem->cond); in uv__custom_sem_destroy()
576 uv_mutex_destroy(&sem->mutex); in uv__custom_sem_destroy()
577 uv__free(sem); in uv__custom_sem_destroy()
582 uv_semaphore_t* sem; in uv__custom_sem_post() local
584 sem = *(uv_semaphore_t**)sem_; in uv__custom_sem_post()
585 uv_mutex_lock(&sem->mutex); in uv__custom_sem_post()
586 sem->value++; in uv__custom_sem_post()
587 if (sem->value == 1) in uv__custom_sem_post()
588 uv_cond_signal(&sem->cond); in uv__custom_sem_post()
589 uv_mutex_unlock(&sem->mutex); in uv__custom_sem_post()
594 uv_semaphore_t* sem; in uv__custom_sem_wait() local
596 sem = *(uv_semaphore_t**)sem_; in uv__custom_sem_wait()
597 uv_mutex_lock(&sem->mutex); in uv__custom_sem_wait()
598 while (sem->value == 0) in uv__custom_sem_wait()
599 uv_cond_wait(&sem->cond, &sem->mutex); in uv__custom_sem_wait()
600 sem->value--; in uv__custom_sem_wait()
601 uv_mutex_unlock(&sem->mutex); in uv__custom_sem_wait()
606 uv_semaphore_t* sem; in uv__custom_sem_trywait() local
608 sem = *(uv_semaphore_t**)sem_; in uv__custom_sem_trywait()
609 if (uv_mutex_trylock(&sem->mutex) != 0) in uv__custom_sem_trywait()
612 if (sem->value == 0) { in uv__custom_sem_trywait()
613 uv_mutex_unlock(&sem->mutex); in uv__custom_sem_trywait()
617 sem->value--; in uv__custom_sem_trywait()
618 uv_mutex_unlock(&sem->mutex); in uv__custom_sem_trywait()
623 static int uv__sem_init(uv_sem_t* sem, unsigned int value) { in uv__sem_init() argument
624 if (sem_init(sem, 0, value)) in uv__sem_init()
630 static void uv__sem_destroy(uv_sem_t* sem) { in uv__sem_destroy() argument
631 if (sem_destroy(sem)) in uv__sem_destroy()
636 static void uv__sem_post(uv_sem_t* sem) { in uv__sem_post() argument
637 if (sem_post(sem)) in uv__sem_post()
642 static void uv__sem_wait(uv_sem_t* sem) { in uv__sem_wait() argument
646 r = sem_wait(sem); in uv__sem_wait()
654 static int uv__sem_trywait(uv_sem_t* sem) { in uv__sem_trywait() argument
658 r = sem_trywait(sem); in uv__sem_trywait()
670 int uv_sem_init(uv_sem_t* sem, unsigned int value) { in uv_sem_init() argument
676 return uv__custom_sem_init(sem, value); in uv_sem_init()
678 return uv__sem_init(sem, value); in uv_sem_init()
682 void uv_sem_destroy(uv_sem_t* sem) { in uv_sem_destroy() argument
684 uv__custom_sem_destroy(sem); in uv_sem_destroy()
686 uv__sem_destroy(sem); in uv_sem_destroy()
690 void uv_sem_post(uv_sem_t* sem) { in uv_sem_post() argument
692 uv__custom_sem_post(sem); in uv_sem_post()
694 uv__sem_post(sem); in uv_sem_post()
698 void uv_sem_wait(uv_sem_t* sem) { in uv_sem_wait() argument
700 uv__custom_sem_wait(sem); in uv_sem_wait()
702 uv__sem_wait(sem); in uv_sem_wait()
706 int uv_sem_trywait(uv_sem_t* sem) { in uv_sem_trywait() argument
708 return uv__custom_sem_trywait(sem); in uv_sem_trywait()
710 return uv__sem_trywait(sem); in uv_sem_trywait()