pthreadpool: Simplify the logic in add_job a bit
authorVolker Lendecke <vl@samba.org>
Tue, 12 Dec 2017 12:52:56 +0000 (13:52 +0100)
committerJeremy Allison <jra@samba.org>
Tue, 12 Dec 2017 19:37:08 +0000 (20:37 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/pthreadpool/pthreadpool.c

index b70694a6a1b71121bc2921a996275e5e783ab201..2dfda38f144326a5b7dc89ebcc181dc4cb2112de 100644 (file)
@@ -678,27 +678,33 @@ int pthreadpool_add_job(struct pthreadpool *pool, int job_id,
        }
 
        res = pthreadpool_create_thread(pool);
-       if (res != 0) {
-               if (pool->num_threads == 0) {
-                       /*
-                        * No thread could be created to run job,
-                        * fallback to sync call.
-                        */
-                       pthreadpool_undo_put_job(pool);
-                       pthread_mutex_unlock(&pool->mutex);
-
-                       fn(private_data);
-                       return pool->signal_fn(job_id, fn, private_data,
-                                              pool->signal_fn_private_data);
-               }
+       if (res == 0) {
+               res = pthread_mutex_unlock(&pool->mutex);
+               assert(res == 0);
+               return 0;
+       }
 
+       if (pool->num_threads != 0) {
                /*
                 * At least one thread is still available, let
                 * that one run the queued job.
                 */
-               res = 0;
+               res = pthread_mutex_unlock(&pool->mutex);
+               assert(res == 0);
+               return 0;
        }
 
-       pthread_mutex_unlock(&pool->mutex);
+       /*
+        * No thread could be created to run job, fallback to sync
+        * call.
+        */
+       pthreadpool_undo_put_job(pool);
+
+       res = pthread_mutex_unlock(&pool->mutex);
+       assert(res == 0);
+
+       fn(private_data);
+       res = pool->signal_fn(job_id, fn, private_data,
+                             pool->signal_fn_private_data);
        return res;
 }