X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=src%2Fsem.c;h=ee03e0b1d0872392d3770851e5bcdd372d49750e;hb=b7ce41b809a3b3533d398c0da8fd9787c149434c;hp=3c911cde10ff820ca06247df2d91b3b18e93422e;hpb=d778944d0403b093d43d9cbd94bd298bfc3a8d42;p=tlsproxy%2Ftlsproxy.git diff --git a/src/sem.c b/src/sem.c index 3c911cd..ee03e0b 100644 --- a/src/sem.c +++ b/src/sem.c @@ -19,8 +19,8 @@ #include "sem.h" -#include #include +#include struct SEM { @@ -31,15 +31,15 @@ struct SEM { SEM *sem_init(int init_value) { SEM *sem = malloc(sizeof(*sem)); - if (NULL == sem) { + if (sem == NULL) { return NULL; } - if (0 != pthread_mutex_init(&sem->mutex, NULL)) { + if (pthread_mutex_init(&sem->mutex, NULL) != 0) { free(sem); return NULL; } - if (0 != pthread_cond_init(&sem->condition, NULL)) { + if (pthread_cond_init(&sem->condition, NULL) != 0) { pthread_mutex_destroy(&sem->mutex); free(sem); return NULL; @@ -50,15 +50,15 @@ SEM *sem_init(int init_value) { } int sem_del(SEM *sem) { - if (NULL == sem) { + if (sem == NULL) { return 0; } - if (0 != pthread_mutex_destroy(&sem->mutex)) { + if (pthread_mutex_destroy(&sem->mutex) != 0) { free(sem); return -1; } - if (0 != pthread_cond_destroy(&sem->condition)) { + if (pthread_cond_destroy(&sem->condition) != 0) { free(sem); return -1; } @@ -69,7 +69,7 @@ int sem_del(SEM *sem) { void P(SEM *sem) { pthread_mutex_lock(&sem->mutex); - while (0 == sem->value) { + while (sem->value <= 0) { pthread_cond_wait(&sem->condition, &sem->mutex); } sem->value--;