From ed54bab9f775ea9744c8cd9057ce93187ad472af Mon Sep 17 00:00:00 2001 From: cs-moushuai Date: Fri, 5 May 2023 03:39:41 +0000 Subject: [PATCH] fix: cpp usage errors --- thpool.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/thpool.c b/thpool.c index 59e2e55..4248373 100644 --- a/thpool.c +++ b/thpool.c @@ -89,7 +89,7 @@ typedef struct thpool_{ volatile int num_threads_working; /* threads currently working */ pthread_mutex_t thcount_lock; /* used for thread count etc */ pthread_cond_t threads_all_idle; /* signal to thpool_wait */ - jobqueue jobqueue; /* job queue */ + jobqueue job_queue; /* job queue */ } thpool_; @@ -144,7 +144,7 @@ struct thpool_* thpool_init(int num_threads){ thpool_p->num_threads_working = 0; /* Initialise the job queue */ - if (jobqueue_init(&thpool_p->jobqueue) == -1){ + if (jobqueue_init(&thpool_p->job_queue) == -1){ err("thpool_init(): Could not allocate memory for job queue\n"); free(thpool_p); return NULL; @@ -154,7 +154,7 @@ struct thpool_* thpool_init(int num_threads){ thpool_p->threads = (struct thread**)malloc(num_threads * sizeof(struct thread *)); if (thpool_p->threads == NULL){ err("thpool_init(): Could not allocate memory for threads\n"); - jobqueue_destroy(&thpool_p->jobqueue); + jobqueue_destroy(&thpool_p->job_queue); free(thpool_p); return NULL; } @@ -193,7 +193,7 @@ int thpool_add_work(thpool_* thpool_p, void (*function_p)(void*), void* arg_p){ newjob->arg=arg_p; /* add job to queue */ - jobqueue_push(&thpool_p->jobqueue, newjob); + jobqueue_push(&thpool_p->job_queue, newjob); return 0; } @@ -202,7 +202,7 @@ int thpool_add_work(thpool_* thpool_p, void (*function_p)(void*), void* arg_p){ /* Wait until all jobs have finished */ void thpool_wait(thpool_* thpool_p){ pthread_mutex_lock(&thpool_p->thcount_lock); - while (thpool_p->jobqueue.len || thpool_p->num_threads_working) { + while (thpool_p->job_queue.len || thpool_p->num_threads_working) { pthread_cond_wait(&thpool_p->threads_all_idle, &thpool_p->thcount_lock); } pthread_mutex_unlock(&thpool_p->thcount_lock); @@ -225,19 +225,19 @@ void thpool_destroy(thpool_* thpool_p){ double tpassed = 0.0; time (&start); while (tpassed < TIMEOUT && thpool_p->num_threads_alive){ - bsem_post_all(thpool_p->jobqueue.has_jobs); + bsem_post_all(thpool_p->job_queue.has_jobs); time (&end); tpassed = difftime(end,start); } /* Poll remaining threads */ while (thpool_p->num_threads_alive){ - bsem_post_all(thpool_p->jobqueue.has_jobs); + bsem_post_all(thpool_p->job_queue.has_jobs); sleep(1); } /* Job queue cleanup */ - jobqueue_destroy(&thpool_p->jobqueue); + jobqueue_destroy(&thpool_p->job_queue); /* Deallocs */ int n; for (n=0; n < threads_total; n++){ @@ -354,7 +354,7 @@ static void* thread_do(struct thread* thread_p){ while(threads_keepalive){ - bsem_wait(thpool_p->jobqueue.has_jobs); + bsem_wait(thpool_p->job_queue.has_jobs); if (threads_keepalive){ @@ -365,7 +365,7 @@ static void* thread_do(struct thread* thread_p){ /* Read job from queue and execute it */ void (*func_buff)(void*); void* arg_buff; - job* job_p = jobqueue_pull(&thpool_p->jobqueue); + job* job_p = jobqueue_pull(&thpool_p->job_queue); if (job_p) { func_buff = job_p->function; arg_buff = job_p->arg;