Lines Matching refs:sem
460 int uv_sem_init(uv_sem_t* sem, unsigned int value) { in uv_sem_init() argument
463 err = semaphore_create(mach_task_self(), sem, SYNC_POLICY_FIFO, value); in uv_sem_init()
476 void uv_sem_destroy(uv_sem_t* sem) { in uv_sem_destroy() argument
477 if (semaphore_destroy(mach_task_self(), *sem)) in uv_sem_destroy()
482 void uv_sem_post(uv_sem_t* sem) { in uv_sem_post() argument
483 if (semaphore_signal(*sem)) in uv_sem_post()
488 void uv_sem_wait(uv_sem_t* sem) { in uv_sem_wait() argument
492 r = semaphore_wait(*sem); in uv_sem_wait()
500 int uv_sem_trywait(uv_sem_t* sem) { in uv_sem_trywait() argument
507 err = semaphore_timedwait(*sem, interval); in uv_sem_trywait()
562 uv_semaphore_t* sem; in uv__custom_sem_init() local
564 sem = uv__malloc(sizeof(*sem)); in uv__custom_sem_init()
565 if (sem == NULL) in uv__custom_sem_init()
568 if ((err = uv_mutex_init(&sem->mutex)) != 0) { in uv__custom_sem_init()
569 uv__free(sem); in uv__custom_sem_init()
573 if ((err = uv_cond_init(&sem->cond)) != 0) { in uv__custom_sem_init()
574 uv_mutex_destroy(&sem->mutex); in uv__custom_sem_init()
575 uv__free(sem); in uv__custom_sem_init()
579 sem->value = value; in uv__custom_sem_init()
580 *(uv_semaphore_t**)sem_ = sem; in uv__custom_sem_init()
586 uv_semaphore_t* sem; in uv__custom_sem_destroy() local
588 sem = *(uv_semaphore_t**)sem_; in uv__custom_sem_destroy()
589 uv_cond_destroy(&sem->cond); in uv__custom_sem_destroy()
590 uv_mutex_destroy(&sem->mutex); in uv__custom_sem_destroy()
591 uv__free(sem); in uv__custom_sem_destroy()
596 uv_semaphore_t* sem; in uv__custom_sem_post() local
598 sem = *(uv_semaphore_t**)sem_; in uv__custom_sem_post()
599 uv_mutex_lock(&sem->mutex); in uv__custom_sem_post()
600 sem->value++; in uv__custom_sem_post()
601 if (sem->value == 1) in uv__custom_sem_post()
602 uv_cond_signal(&sem->cond); /* Release one to replace us. */ in uv__custom_sem_post()
603 uv_mutex_unlock(&sem->mutex); in uv__custom_sem_post()
608 uv_semaphore_t* sem; in uv__custom_sem_wait() local
610 sem = *(uv_semaphore_t**)sem_; in uv__custom_sem_wait()
611 uv_mutex_lock(&sem->mutex); in uv__custom_sem_wait()
612 while (sem->value == 0) in uv__custom_sem_wait()
613 uv_cond_wait(&sem->cond, &sem->mutex); in uv__custom_sem_wait()
614 sem->value--; in uv__custom_sem_wait()
615 uv_mutex_unlock(&sem->mutex); in uv__custom_sem_wait()
620 uv_semaphore_t* sem; in uv__custom_sem_trywait() local
622 sem = *(uv_semaphore_t**)sem_; in uv__custom_sem_trywait()
623 if (uv_mutex_trylock(&sem->mutex) != 0) in uv__custom_sem_trywait()
626 if (sem->value == 0) { in uv__custom_sem_trywait()
627 uv_mutex_unlock(&sem->mutex); in uv__custom_sem_trywait()
631 sem->value--; in uv__custom_sem_trywait()
632 uv_mutex_unlock(&sem->mutex); in uv__custom_sem_trywait()
637 static int uv__sem_init(uv_sem_t* sem, unsigned int value) { in uv__sem_init() argument
638 if (sem_init(sem, 0, value)) in uv__sem_init()
644 static void uv__sem_destroy(uv_sem_t* sem) { in uv__sem_destroy() argument
645 if (sem_destroy(sem)) in uv__sem_destroy()
650 static void uv__sem_post(uv_sem_t* sem) { in uv__sem_post() argument
651 if (sem_post(sem)) in uv__sem_post()
656 static void uv__sem_wait(uv_sem_t* sem) { in uv__sem_wait() argument
660 r = sem_wait(sem); in uv__sem_wait()
668 static int uv__sem_trywait(uv_sem_t* sem) { in uv__sem_trywait() argument
672 r = sem_trywait(sem); in uv__sem_trywait()
684 int uv_sem_init(uv_sem_t* sem, unsigned int value) { in uv_sem_init() argument
690 return uv__custom_sem_init(sem, value); in uv_sem_init()
692 return uv__sem_init(sem, value); in uv_sem_init()
696 void uv_sem_destroy(uv_sem_t* sem) { in uv_sem_destroy() argument
698 uv__custom_sem_destroy(sem); in uv_sem_destroy()
700 uv__sem_destroy(sem); in uv_sem_destroy()
704 void uv_sem_post(uv_sem_t* sem) { in uv_sem_post() argument
706 uv__custom_sem_post(sem); in uv_sem_post()
708 uv__sem_post(sem); in uv_sem_post()
712 void uv_sem_wait(uv_sem_t* sem) { in uv_sem_wait() argument
714 uv__custom_sem_wait(sem); in uv_sem_wait()
716 uv__sem_wait(sem); in uv_sem_wait()
720 int uv_sem_trywait(uv_sem_t* sem) { in uv_sem_trywait() argument
722 return uv__custom_sem_trywait(sem); in uv_sem_trywait()
724 return uv__sem_trywait(sem); in uv_sem_trywait()