Commit afa87ce8 authored by Tejun Heo's avatar Tejun Heo

workqueue: Factor out pwq_is_empty()

"!pwq->nr_active && list_empty(&pwq->inactive_works)" test is repeated
multiple times. Let's factor it out into pwq_is_empty().
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Reviewed-by: default avatarLai Jiangshan <jiangshanlai@gmail.com>
parent a045a272
...@@ -1460,6 +1460,11 @@ static void put_pwq_unlocked(struct pool_workqueue *pwq) ...@@ -1460,6 +1460,11 @@ static void put_pwq_unlocked(struct pool_workqueue *pwq)
} }
} }
static bool pwq_is_empty(struct pool_workqueue *pwq)
{
return !pwq->nr_active && list_empty(&pwq->inactive_works);
}
static void pwq_activate_inactive_work(struct work_struct *work) static void pwq_activate_inactive_work(struct work_struct *work)
{ {
struct pool_workqueue *pwq = get_work_pwq(work); struct pool_workqueue *pwq = get_work_pwq(work);
...@@ -3329,7 +3334,7 @@ void drain_workqueue(struct workqueue_struct *wq) ...@@ -3329,7 +3334,7 @@ void drain_workqueue(struct workqueue_struct *wq)
bool drained; bool drained;
raw_spin_lock_irq(&pwq->pool->lock); raw_spin_lock_irq(&pwq->pool->lock);
drained = !pwq->nr_active && list_empty(&pwq->inactive_works); drained = pwq_is_empty(pwq);
raw_spin_unlock_irq(&pwq->pool->lock); raw_spin_unlock_irq(&pwq->pool->lock);
if (drained) if (drained)
...@@ -4779,7 +4784,7 @@ static bool pwq_busy(struct pool_workqueue *pwq) ...@@ -4779,7 +4784,7 @@ static bool pwq_busy(struct pool_workqueue *pwq)
if ((pwq != pwq->wq->dfl_pwq) && (pwq->refcnt > 1)) if ((pwq != pwq->wq->dfl_pwq) && (pwq->refcnt > 1))
return true; return true;
if (pwq->nr_active || !list_empty(&pwq->inactive_works)) if (!pwq_is_empty(pwq))
return true; return true;
return false; return false;
...@@ -5217,7 +5222,7 @@ void show_one_workqueue(struct workqueue_struct *wq) ...@@ -5217,7 +5222,7 @@ void show_one_workqueue(struct workqueue_struct *wq)
unsigned long flags; unsigned long flags;
for_each_pwq(pwq, wq) { for_each_pwq(pwq, wq) {
if (pwq->nr_active || !list_empty(&pwq->inactive_works)) { if (!pwq_is_empty(pwq)) {
idle = false; idle = false;
break; break;
} }
...@@ -5229,7 +5234,7 @@ void show_one_workqueue(struct workqueue_struct *wq) ...@@ -5229,7 +5234,7 @@ void show_one_workqueue(struct workqueue_struct *wq)
for_each_pwq(pwq, wq) { for_each_pwq(pwq, wq) {
raw_spin_lock_irqsave(&pwq->pool->lock, flags); raw_spin_lock_irqsave(&pwq->pool->lock, flags);
if (pwq->nr_active || !list_empty(&pwq->inactive_works)) { if (!pwq_is_empty(pwq)) {
/* /*
* Defer printing to avoid deadlocks in console * Defer printing to avoid deadlocks in console
* drivers that queue work while holding locks * drivers that queue work while holding locks
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment