From 03830a3226d43f13e58dcf68874d50e19793144d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 22 Jun 2018 00:27:39 +0200 Subject: [PATCH] pthreadpool: consitently use unlock_res for pthread_mutex_unlock() in pthreadpool_add_job() This makes further restructuring easier to implement and understand. Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme --- lib/pthreadpool/pthreadpool.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/pthreadpool/pthreadpool.c b/lib/pthreadpool/pthreadpool.c index 0ab6f63dbf4..0f695bcd769 100644 --- a/lib/pthreadpool/pthreadpool.c +++ b/lib/pthreadpool/pthreadpool.c @@ -632,6 +632,7 @@ int pthreadpool_add_job(struct pthreadpool *pool, int job_id, void (*fn)(void *private_data), void *private_data) { int res; + int unlock_res; res = pthread_mutex_lock(&pool->mutex); if (res != 0) { @@ -643,8 +644,8 @@ int pthreadpool_add_job(struct pthreadpool *pool, int job_id, * Protect against the pool being shut down while * trying to add a job */ - res = pthread_mutex_unlock(&pool->mutex); - assert(res == 0); + unlock_res = pthread_mutex_unlock(&pool->mutex); + assert(unlock_res == 0); return EINVAL; } @@ -652,13 +653,12 @@ int pthreadpool_add_job(struct pthreadpool *pool, int job_id, * Add job to the end of the queue */ if (!pthreadpool_put_job(pool, job_id, fn, private_data)) { - res = pthread_mutex_unlock(&pool->mutex); - assert(res == 0); + unlock_res = pthread_mutex_unlock(&pool->mutex); + assert(unlock_res == 0); return ENOMEM; } if (pool->num_idle > 0) { - int unlock_res; /* * We have idle threads, wake one. */ @@ -676,15 +676,15 @@ int pthreadpool_add_job(struct pthreadpool *pool, int job_id, /* * No more new threads, we just queue the request */ - res = pthread_mutex_unlock(&pool->mutex); - assert(res == 0); + unlock_res = pthread_mutex_unlock(&pool->mutex); + assert(unlock_res == 0); return 0; } res = pthreadpool_create_thread(pool); if (res == 0) { - res = pthread_mutex_unlock(&pool->mutex); - assert(res == 0); + unlock_res = pthread_mutex_unlock(&pool->mutex); + assert(unlock_res == 0); return 0; } @@ -693,8 +693,8 @@ int pthreadpool_add_job(struct pthreadpool *pool, int job_id, * At least one thread is still available, let * that one run the queued job. */ - res = pthread_mutex_unlock(&pool->mutex); - assert(res == 0); + unlock_res = pthread_mutex_unlock(&pool->mutex); + assert(unlock_res == 0); return 0; } @@ -704,8 +704,8 @@ int pthreadpool_add_job(struct pthreadpool *pool, int job_id, */ pthreadpool_undo_put_job(pool); - res = pthread_mutex_unlock(&pool->mutex); - assert(res == 0); + unlock_res = pthread_mutex_unlock(&pool->mutex); + assert(unlock_res == 0); fn(private_data); res = pool->signal_fn(job_id, fn, private_data, -- 2.47.3