Reset errno after EINTR

This commit is contained in:
2022-12-29 10:14:14 +01:00
parent b90ed61e03
commit cf3cff0746
3 changed files with 18 additions and 0 deletions

View File

@ -207,9 +207,11 @@ static void *cache_thread(void *arg) {
pthread_testcancel();
if (sem_wait(&sem_used) != 0) {
if (errno == EINTR) {
errno = 0;
continue;
} else {
error("Unable to lock semaphore");
errno = 0;
break;
}
}
@ -294,9 +296,11 @@ static void cache_mark_entry_dirty(cache_entry_t *entry) {
try_again_free:
if (sem_wait(&sem_free) != 0) {
if (errno == EINTR) {
errno = 0;
goto try_again_free;
} else {
error("Unable to lock semaphore");
errno = 0;
}
return;
}
@ -305,9 +309,11 @@ static void cache_mark_entry_dirty(cache_entry_t *entry) {
try_again_lock:
if (sem_wait(&sem_lock) != 0) {
if (errno == EINTR) {
errno = 0;
goto try_again_lock;
} else {
error("Unable to lock semaphore");
errno = 0;
}
return;
}

View File

@ -54,6 +54,7 @@ int mpmc_queue(mpmc_t *ctx, void *obj) {
try_again_1:
if (sem_wait(&ctx->free) != 0) {
if (errno == EINTR) {
errno = 0;
goto try_again_1;
} else {
return -1;
@ -64,6 +65,7 @@ int mpmc_queue(mpmc_t *ctx, void *obj) {
try_again_2:
if (sem_wait(&ctx->lck_rd) != 0) {
if (errno == EINTR) {
errno = 0;
goto try_again_2;
} else {
sem_post(&ctx->free);
@ -92,9 +94,11 @@ static void *mpmc_worker(void *arg) {
// wait for buffer to be filled
if (sem_wait(&ctx->used) != 0) {
if (errno == EINTR) {
errno = 0;
continue;
} else {
critical("Unable to lock semaphore");
errno = 0;
break;
}
}
@ -102,10 +106,12 @@ static void *mpmc_worker(void *arg) {
// lock wr field
if (sem_wait(&ctx->lck_wr) != 0) {
if (errno == EINTR) {
errno = 0;
sem_post(&ctx->used);
continue;
} else {
critical("Unable to lock semaphore");
errno = 0;
sem_post(&ctx->used);
break;
}

View File

@ -93,9 +93,11 @@ void logmsgf(log_lvl_t level, const char *restrict format, ...) {
try_again_free:
if (sem_wait(&sem_buf_free) != 0) {
if (errno == EINTR) {
errno = 0;
goto try_again_free;
} else {
err("Unable to lock semaphore");
errno = 0;
}
// cleanup
va_end(args);
@ -106,9 +108,11 @@ void logmsgf(log_lvl_t level, const char *restrict format, ...) {
try_again_buf:
if (sem_wait(&sem_buf) != 0) {
if (errno == EINTR) {
errno = 0;
goto try_again_buf;
} else {
err("Unable to lock semaphore");
errno = 0;
}
// cleanup
sem_post(&sem_buf_free);
@ -204,9 +208,11 @@ static void *logger_thread(void *arg) {
// wait for buffer to be filled
if (sem_wait(&sem_buf_used) != 0) {
if (errno == EINTR) {
errno = 0;
continue;
} else {
err("Unable to lock semaphore");
errno = 0;
break;
}
}