proper state, handling of fans

This commit is contained in:
veclavtalica
2025-02-07 13:42:01 +03:00
parent 990135105a
commit 559ff9fedc
4 changed files with 104 additions and 33 deletions

View File

@ -4,10 +4,10 @@
SDL_sem *workers_job_semaphore;
static SDL_Thread *workers_pool[MAX_WORKERS];
static size_t workers_pool_size;
static SDL_mutex *workers_mutex;
static bool workers_should_exit;
static SDL_sem *workers_exit_semaphore; /* should come to count of `workers_pool_size` */
/* logic is such that when job is posted, worker threads attempt to grab it from any possible entry point */
/* if it did something, which is signaled by `true` return, go back to waiting on semaphore, so that it's decremented properly */
@ -31,6 +31,9 @@ static int worker_thread(void *udata) {
continue;
}
/* let the main thread collect it */
SDL_SemPost(workers_exit_semaphore);
return 0;
}
@ -52,6 +55,7 @@ bool workers_init(size_t worker_count) {
workers_pool_size = worker_count;
workers_job_semaphore = SDL_CreateSemaphore(0);
workers_exit_semaphore = SDL_CreateSemaphore(0);
workers_mutex = SDL_CreateMutex();
return true;
}
@ -62,8 +66,12 @@ void workers_deinit(void) {
workers_should_exit = true;
SDL_UnlockMutex(workers_mutex);
/* TODO: that's not correct */
for (size_t i = 0; i < workers_pool_size; ++i) {
SDL_SemWait(workers_exit_semaphore);
}
SDL_DestroyMutex(workers_mutex);
SDL_DestroySemaphore(workers_job_semaphore);
SDL_DestroySemaphore(workers_exit_semaphore);
workers_pool_size = 0;
}