pthreadpool: consitently use unlock_res for pthread_mutex_unlock() in pthreadpool_add...
authorStefan Metzmacher <metze@samba.org>
Thu, 21 Jun 2018 22:27:39 +0000 (00:27 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 12 Jul 2018 12:25:18 +0000 (14:25 +0200)
This makes further restructuring easier to implement and understand.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
lib/pthreadpool/pthreadpool.c

index 0ab6f63dbf425f74e53f4918f3ba96e9c2581d3b..0f695bcd769ed07674080777fea3970fb3cf0d5a 100644 (file)
@@ -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,