Skip to content

Commit afa87ce

Browse files
committed
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: Tejun Heo <tj@kernel.org> Reviewed-by: Lai Jiangshan <jiangshanlai@gmail.com>
1 parent a045a27 commit afa87ce

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

kernel/workqueue.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,11 @@ static void put_pwq_unlocked(struct pool_workqueue *pwq)
14601460
}
14611461
}
14621462

1463+
static bool pwq_is_empty(struct pool_workqueue *pwq)
1464+
{
1465+
return !pwq->nr_active && list_empty(&pwq->inactive_works);
1466+
}
1467+
14631468
static void pwq_activate_inactive_work(struct work_struct *work)
14641469
{
14651470
struct pool_workqueue *pwq = get_work_pwq(work);
@@ -3329,7 +3334,7 @@ void drain_workqueue(struct workqueue_struct *wq)
33293334
bool drained;
33303335

33313336
raw_spin_lock_irq(&pwq->pool->lock);
3332-
drained = !pwq->nr_active && list_empty(&pwq->inactive_works);
3337+
drained = pwq_is_empty(pwq);
33333338
raw_spin_unlock_irq(&pwq->pool->lock);
33343339

33353340
if (drained)
@@ -4779,7 +4784,7 @@ static bool pwq_busy(struct pool_workqueue *pwq)
47794784

47804785
if ((pwq != pwq->wq->dfl_pwq) && (pwq->refcnt > 1))
47814786
return true;
4782-
if (pwq->nr_active || !list_empty(&pwq->inactive_works))
4787+
if (!pwq_is_empty(pwq))
47834788
return true;
47844789

47854790
return false;
@@ -5217,7 +5222,7 @@ void show_one_workqueue(struct workqueue_struct *wq)
52175222
unsigned long flags;
52185223

52195224
for_each_pwq(pwq, wq) {
5220-
if (pwq->nr_active || !list_empty(&pwq->inactive_works)) {
5225+
if (!pwq_is_empty(pwq)) {
52215226
idle = false;
52225227
break;
52235228
}
@@ -5229,7 +5234,7 @@ void show_one_workqueue(struct workqueue_struct *wq)
52295234

52305235
for_each_pwq(pwq, wq) {
52315236
raw_spin_lock_irqsave(&pwq->pool->lock, flags);
5232-
if (pwq->nr_active || !list_empty(&pwq->inactive_works)) {
5237+
if (!pwq_is_empty(pwq)) {
52335238
/*
52345239
* Defer printing to avoid deadlocks in console
52355240
* drivers that queue work while holding locks

0 commit comments

Comments
 (0)