Skip to content

Commit fa5312d

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq: workqueue: change cancel_work_sync() to clear work->data workqueue: warn about flush_scheduled_work()
2 parents 9c688c1 + 4d707b9 commit fa5312d

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

‎kernel/workqueue.c‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,16 @@ static inline void set_wq_data(struct work_struct *work,
229229
atomic_long_set(&work->data, new);
230230
}
231231

232+
/*
233+
* Clear WORK_STRUCT_PENDING and the workqueue on which it was queued.
234+
*/
235+
static inline void clear_wq_data(struct work_struct *work)
236+
{
237+
unsigned long flags = *work_data_bits(work) &
238+
(1UL << WORK_STRUCT_STATIC);
239+
atomic_long_set(&work->data, flags);
240+
}
241+
232242
static inline
233243
struct cpu_workqueue_struct *get_wq_data(struct work_struct *work)
234244
{
@@ -671,7 +681,7 @@ static int __cancel_work_timer(struct work_struct *work,
671681
wait_on_work(work);
672682
} while (unlikely(ret < 0));
673683

674-
work_clear_pending(work);
684+
clear_wq_data(work);
675685
return ret;
676686
}
677687

@@ -845,6 +855,30 @@ int schedule_on_each_cpu(work_func_t func)
845855
return 0;
846856
}
847857

858+
/**
859+
* flush_scheduled_work - ensure that any scheduled work has run to completion.
860+
*
861+
* Forces execution of the kernel-global workqueue and blocks until its
862+
* completion.
863+
*
864+
* Think twice before calling this function! It's very easy to get into
865+
* trouble if you don't take great care. Either of the following situations
866+
* will lead to deadlock:
867+
*
868+
* One of the work items currently on the workqueue needs to acquire
869+
* a lock held by your code or its caller.
870+
*
871+
* Your code is running in the context of a work routine.
872+
*
873+
* They will be detected by lockdep when they occur, but the first might not
874+
* occur very often. It depends on what work items are on the workqueue and
875+
* what locks they need, which you have no control over.
876+
*
877+
* In most situations flushing the entire workqueue is overkill; you merely
878+
* need to know that a particular work item isn't queued and isn't running.
879+
* In such cases you should use cancel_delayed_work_sync() or
880+
* cancel_work_sync() instead.
881+
*/
848882
void flush_scheduled_work(void)
849883
{
850884
flush_workqueue(keventd_wq);

0 commit comments

Comments
 (0)