fixed spacing

This commit is contained in:
elvis
2022-06-08 12:33:03 +02:00
parent f228ee5462
commit 11879cf252

View File

@ -34,27 +34,27 @@ static void *workerpool_thread(void *threadpool) {
LOCK_RETURN(&(pool->lock), NULL); LOCK_RETURN(&(pool->lock), NULL);
for (;;) { for (;;) {
// in attesa di un messaggio, controllo spurious wakeups. // in attesa di un messaggio, controllo spurious wakeups.
while((pool->count == 0) && (!pool->exiting)) { while((pool->count == 0) && (!pool->exiting)) {
pthread_cond_wait(&(pool->cond), &(pool->lock)); pthread_cond_wait(&(pool->cond), &(pool->lock));
} }
if (pool->exiting > 1) break; // exit forzato, esco immediatamente if (pool->exiting > 1) break; // exit forzato, esco immediatamente
// devo uscire ma ci sono messaggi pendenti // devo uscire ma ci sono messaggi pendenti
if (pool->exiting == 1 && !pool->count) break; if (pool->exiting == 1 && !pool->count) break;
// nuovo task // nuovo task
task.fun = pool->pending_queue[pool->head].fun; task.fun = pool->pending_queue[pool->head].fun;
task.arg = pool->pending_queue[pool->head].arg; task.arg = pool->pending_queue[pool->head].arg;
pool->head++; pool->count--; pool->head++; pool->count--;
pool->head = (pool->head == abs(pool->queue_size)) ? 0 : pool->head; pool->head = (pool->head == abs(pool->queue_size)) ? 0 : pool->head;
pool->taskonthefly++; pool->taskonthefly++;
UNLOCK_RETURN(&(pool->lock), NULL); UNLOCK_RETURN(&(pool->lock), NULL);
// eseguo la funzione // eseguo la funzione
(*(task.fun))(task.arg); (*(task.fun))(task.arg);
LOCK_RETURN(&(pool->lock), NULL); LOCK_RETURN(&(pool->lock), NULL);
pool->taskonthefly--; pool->taskonthefly--;
@ -69,11 +69,11 @@ static void *workerpool_thread(void *threadpool) {
static int freePoolResources(threadpool_t *pool) { static int freePoolResources(threadpool_t *pool) {
if(pool->threads) { if(pool->threads) {
free(pool->threads); free(pool->threads);
free(pool->pending_queue); free(pool->pending_queue);
pthread_mutex_destroy(&(pool->lock)); pthread_mutex_destroy(&(pool->lock));
pthread_cond_destroy(&(pool->cond)); pthread_cond_destroy(&(pool->cond));
} }
free(pool); free(pool);
return 0; return 0;
@ -82,7 +82,7 @@ static int freePoolResources(threadpool_t *pool) {
threadpool_t *createThreadPool(int numthreads, int pending_size) { threadpool_t *createThreadPool(int numthreads, int pending_size) {
if(numthreads <= 0 || pending_size < 0) { if(numthreads <= 0 || pending_size < 0) {
errno = EINVAL; errno = EINVAL;
return NULL; return NULL;
} }
threadpool_t *pool = (threadpool_t *)malloc(sizeof(threadpool_t)); threadpool_t *pool = (threadpool_t *)malloc(sizeof(threadpool_t));
@ -115,14 +115,14 @@ threadpool_t *createThreadPool(int numthreads, int pending_size) {
return NULL; return NULL;
} }
for(int i = 0; i < numthreads; i++) { for(int i = 0; i < numthreads; i++) {
if(pthread_create(&(pool->threads[i]), NULL, if(pthread_create(&(pool->threads[i]), NULL,
workerpool_thread, (void*)pool) != 0) { workerpool_thread, (void*)pool) != 0) {
/* errore fatale, libero tutto forzando l'uscita dei threads */ /* errore fatale, libero tutto forzando l'uscita dei threads */
destroyThreadPool(pool, 1); destroyThreadPool(pool, 1);
errno = EFAULT; errno = EFAULT;
return NULL; return NULL;
} }
pool->numthreads++; pool->numthreads++;
} }
return pool; return pool;
} }