Lines Matching refs:sem
103 static void sys_sem_free_internal(struct sys_sem *sem);
352 struct sys_sem *sem;
354 sem = (struct sys_sem *)malloc(sizeof(struct sys_sem));
355 if (sem != NULL) {
356 sem->c = count;
357 pthread_cond_init(&(sem->cond), NULL);
358 pthread_mutex_init(&(sem->mutex), NULL);
360 return sem;
364 sys_sem_new(struct sys_sem **sem, u8_t count)
366 SYS_STATS_INC_USED(sem);
367 *sem = sys_sem_new_internal(count);
368 if (*sem == NULL) {
419 struct sys_sem *sem;
420 LWIP_ASSERT("invalid sem", (s != NULL) && (*s != NULL));
421 sem = *s;
423 pthread_mutex_lock(&(sem->mutex));
424 while (sem->c <= 0) {
426 time_needed = cond_wait(&(sem->cond), &(sem->mutex), timeout);
429 pthread_mutex_unlock(&(sem->mutex));
432 /* pthread_mutex_unlock(&(sem->mutex));
435 cond_wait(&(sem->cond), &(sem->mutex), 0);
438 sem->c--;
439 pthread_mutex_unlock(&(sem->mutex));
446 struct sys_sem *sem;
447 LWIP_ASSERT("invalid sem", (s != NULL) && (*s != NULL));
448 sem = *s;
450 pthread_mutex_lock(&(sem->mutex));
451 sem->c++;
453 if (sem->c > 1) {
454 sem->c = 1;
457 pthread_cond_broadcast(&(sem->cond));
458 pthread_mutex_unlock(&(sem->mutex));
462 sys_sem_free_internal(struct sys_sem *sem)
464 pthread_cond_destroy(&(sem->cond));
465 pthread_mutex_destroy(&(sem->mutex));
466 free(sem);
470 sys_sem_free(struct sys_sem **sem)
472 if ((sem != NULL) && (*sem != SYS_SEM_NULL)) {
473 SYS_STATS_DEC(sem.used);
474 sys_sem_free_internal(*sem);