fixed spacing
This commit is contained in:
@ -34,27 +34,27 @@ static void *workerpool_thread(void *threadpool) {
|
||||
|
||||
LOCK_RETURN(&(pool->lock), NULL);
|
||||
for (;;) {
|
||||
// in attesa di un messaggio, controllo spurious wakeups.
|
||||
while((pool->count == 0) && (!pool->exiting)) {
|
||||
pthread_cond_wait(&(pool->cond), &(pool->lock));
|
||||
// in attesa di un messaggio, controllo spurious wakeups.
|
||||
while((pool->count == 0) && (!pool->exiting)) {
|
||||
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
|
||||
if (pool->exiting == 1 && !pool->count) break;
|
||||
|
||||
// nuovo task
|
||||
task.fun = pool->pending_queue[pool->head].fun;
|
||||
task.arg = pool->pending_queue[pool->head].arg;
|
||||
task.fun = pool->pending_queue[pool->head].fun;
|
||||
task.arg = pool->pending_queue[pool->head].arg;
|
||||
|
||||
pool->head++; pool->count--;
|
||||
pool->head = (pool->head == abs(pool->queue_size)) ? 0 : pool->head;
|
||||
pool->head++; pool->count--;
|
||||
pool->head = (pool->head == abs(pool->queue_size)) ? 0 : pool->head;
|
||||
|
||||
pool->taskonthefly++;
|
||||
UNLOCK_RETURN(&(pool->lock), NULL);
|
||||
UNLOCK_RETURN(&(pool->lock), NULL);
|
||||
|
||||
// eseguo la funzione
|
||||
(*(task.fun))(task.arg);
|
||||
// eseguo la funzione
|
||||
(*(task.fun))(task.arg);
|
||||
|
||||
LOCK_RETURN(&(pool->lock), NULL);
|
||||
pool->taskonthefly--;
|
||||
@ -69,11 +69,11 @@ static void *workerpool_thread(void *threadpool) {
|
||||
|
||||
static int freePoolResources(threadpool_t *pool) {
|
||||
if(pool->threads) {
|
||||
free(pool->threads);
|
||||
free(pool->pending_queue);
|
||||
free(pool->threads);
|
||||
free(pool->pending_queue);
|
||||
|
||||
pthread_mutex_destroy(&(pool->lock));
|
||||
pthread_cond_destroy(&(pool->cond));
|
||||
pthread_mutex_destroy(&(pool->lock));
|
||||
pthread_cond_destroy(&(pool->cond));
|
||||
}
|
||||
free(pool);
|
||||
return 0;
|
||||
@ -82,7 +82,7 @@ static int freePoolResources(threadpool_t *pool) {
|
||||
threadpool_t *createThreadPool(int numthreads, int pending_size) {
|
||||
if(numthreads <= 0 || pending_size < 0) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
threadpool_t *pool = (threadpool_t *)malloc(sizeof(threadpool_t));
|
||||
@ -115,14 +115,14 @@ threadpool_t *createThreadPool(int numthreads, int pending_size) {
|
||||
return NULL;
|
||||
}
|
||||
for(int i = 0; i < numthreads; i++) {
|
||||
if(pthread_create(&(pool->threads[i]), NULL,
|
||||
workerpool_thread, (void*)pool) != 0) {
|
||||
if(pthread_create(&(pool->threads[i]), NULL,
|
||||
workerpool_thread, (void*)pool) != 0) {
|
||||
/* errore fatale, libero tutto forzando l'uscita dei threads */
|
||||
destroyThreadPool(pool, 1);
|
||||
destroyThreadPool(pool, 1);
|
||||
errno = EFAULT;
|
||||
return NULL;
|
||||
}
|
||||
pool->numthreads++;
|
||||
return NULL;
|
||||
}
|
||||
pool->numthreads++;
|
||||
}
|
||||
return pool;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user