Async working with connection handlers

This commit is contained in:
2022-12-29 01:49:00 +01:00
parent dfc659dec0
commit b90ed61e03
15 changed files with 505 additions and 50 deletions

View File

@@ -203,7 +203,7 @@ static void cache_process_entry(cache_entry_t *entry) {
static void *cache_thread(void *arg) {
logger_set_name("cache");
while (alive) {
while (server_alive) {
pthread_testcancel();
if (sem_wait(&sem_used) != 0) {
if (errno == EINTR) {
@@ -257,10 +257,14 @@ int cache_init(void) {
}
close(fd);
errno = 0;
}
// try to initialize all three semaphores
if (sem_init(&sem_lock, 0, 1) != 0|| sem_init(&sem_free, 0, 1) != 0 || sem_init(&sem_used, 0, 0) != 0) {
if (sem_init(&sem_lock, 0, 1) != 0 ||
sem_init(&sem_free, 0, 1) != 0 ||
sem_init(&sem_used, 0, 0) != 0)
{
critical("Unable to initialize semaphore");
return -1;
}