Print this page
9017 Introduce taskq_empty()
Reviewed by: Bryan Cantrill <bryan@joyent.com>
Reviewed by: Dan McDonald <danmcd@joyent.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Yuri Pankov <yuripv@yuripv.net>
        
*** 24,33 ****
--- 24,34 ----
   */
  
  /*
   * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
   * Copyright (c) 2017 by Delphix. All rights reserved.
+  * Copyright 2018, Joyent, Inc.
   */
  
  /*
   * Kernel task queues: general-purpose asynchronous task scheduling.
   *
*** 198,207 ****
--- 199,212 ----
   *      taskqs.  The memory for the tqent must not be modified or used
   *      until the function (func) is called.  (However, func itself
   *      may safely modify or free this memory, once it is called.)
   *      Note that the taskq framework will NOT free this memory.
   *
+  * boolean_t taskq_empty(tq)
+  *
+  *      Queries if there are tasks pending on the queue.
+  *
   * void taskq_wait(tq):
   *
   *      Waits for all previously scheduled tasks to complete.
   *
   *      NOTE: It does not stop any new task dispatches.
*** 1317,1326 ****
--- 1322,1347 ----
                  TQ_ENQUEUE(tq, tqe, func, arg);
          }
          mutex_exit(&tq->tq_lock);
  }
  
+ /*
+  * Allow our caller to ask if there are tasks pending on the queue.
+  */
+ boolean_t
+ taskq_empty(taskq_t *tq)
+ {
+         boolean_t rv;
+ 
+         ASSERT3P(tq, !=, curthread->t_taskq);
+         mutex_enter(&tq->tq_lock);
+         rv = (tq->tq_task.tqent_next == &tq->tq_task) && (tq->tq_active == 0);
+         mutex_exit(&tq->tq_lock);
+ 
+         return (rv);
+ }
+ 
  /*
   * Wait for all pending tasks to complete.
   * Calling taskq_wait from a task will cause deadlock.
   */
  void