pthreadpool: don't process further jobs when shutting down
authorStefan Metzmacher <metze@samba.org>
Fri, 20 Apr 2018 15:12:07 +0000 (17:12 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 12 Jul 2018 12:25:19 +0000 (14:25 +0200)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
lib/pthreadpool/pthreadpool.c

index 55ea36ed0234cce231cd9908ff6482f67460e17e..1ef6dccee6214133cb7d91e47763ddf778d3cc2e 100644 (file)
@@ -444,6 +444,10 @@ static void pthreadpool_server_exit(struct pthreadpool *pool)
 static bool pthreadpool_get_job(struct pthreadpool *p,
                                struct pthreadpool_job *job)
 {
+       if (p->shutdown) {
+               return false;
+       }
+
        if (p->num_jobs == 0) {
                return false;
        }
@@ -601,10 +605,9 @@ static void *pthreadpool_server(void *arg)
                        }
                }
 
-               if ((pool->num_jobs == 0) && pool->shutdown) {
+               if (pool->shutdown) {
                        /*
-                        * No more work to do and we're asked to shut down, so
-                        * exit
+                        * we're asked to shut down, so exit
                         */
                        pthreadpool_server_exit(pool);
                        return NULL;