workqueue: reimplement is_chained_work() using current_wq_worker()
is_chained_work() was added before current_wq_worker() and implemented its own ham-fisted way of finding out whether %current is a workqueue worker - it iterates through all possible workers. Drop the custom implementation and reimplement using current_wq_worker(). Signed-off-by: Tejun Heo <tj@kernel.org>
This commit is contained in:
parent
1dd638149f
commit
8d03ecfe47
@ -1159,35 +1159,18 @@ static void insert_work(struct cpu_workqueue_struct *cwq,
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Test whether @work is being queued from another work executing on the
|
* Test whether @work is being queued from another work executing on the
|
||||||
* same workqueue. This is rather expensive and should only be used from
|
* same workqueue.
|
||||||
* cold paths.
|
|
||||||
*/
|
*/
|
||||||
static bool is_chained_work(struct workqueue_struct *wq)
|
static bool is_chained_work(struct workqueue_struct *wq)
|
||||||
{
|
{
|
||||||
unsigned long flags;
|
struct worker *worker;
|
||||||
unsigned int cpu;
|
|
||||||
|
|
||||||
for_each_cwq_cpu(cpu, wq) {
|
worker = current_wq_worker();
|
||||||
struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq);
|
/*
|
||||||
struct worker_pool *pool = cwq->pool;
|
* Return %true iff I'm a worker execuing a work item on @wq. If
|
||||||
struct worker *worker;
|
* I'm @worker, it's safe to dereference it without locking.
|
||||||
struct hlist_node *pos;
|
*/
|
||||||
int i;
|
return worker && worker->current_cwq->wq == wq;
|
||||||
|
|
||||||
spin_lock_irqsave(&pool->lock, flags);
|
|
||||||
for_each_busy_worker(worker, i, pos, pool) {
|
|
||||||
if (worker->task != current)
|
|
||||||
continue;
|
|
||||||
spin_unlock_irqrestore(&pool->lock, flags);
|
|
||||||
/*
|
|
||||||
* I'm @worker, no locking necessary. See if @work
|
|
||||||
* is headed to the same workqueue.
|
|
||||||
*/
|
|
||||||
return worker->current_cwq->wq == wq;
|
|
||||||
}
|
|
||||||
spin_unlock_irqrestore(&pool->lock, flags);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __queue_work(unsigned int cpu, struct workqueue_struct *wq,
|
static void __queue_work(unsigned int cpu, struct workqueue_struct *wq,
|
||||||
|
Loading…
Reference in New Issue
Block a user