Skip to contentSkip to conversation

workqueues: lockdep annotations for flush_work()

PATCH In review Oleg Nesterov 2 participants 2 messages Jul 6, 2008 Workqueue

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 workqueues: lockdep annotations for flush_work()

Add lockdep annotations to flush_work() and update the comment.

kernel/workqueue.c renamed from kernel/workqueue.c~FW_LOCKDEP +5 -0
@@ -403,6 +403,8 @@ EXPORT_SYMBOL_GPL(flush_workqueue);
  * flush_work - block until a work_struct's callback has terminated
  * @work: the work which is to be flushed
  *
+ * Returns false if @work has already terminated.
+ *
  * It is expected that, prior to calling flush_work(), the caller has
  * arranged for the work to not be requeued, otherwise it doesn't make
  * sense to use this function.
@@ -418,6 +420,9 @@ int flush_work(struct work_struct *work)
 	if (!cwq)
 		return 0;
 
+	lock_acquire(&cwq->wq->lockdep_map, 0, 0, 0, 2, _THIS_IP_);
+	lock_release(&cwq->wq->lockdep_map, 1, _THIS_IP_);
+
 	prev = NULL;
 	spin_lock_irq(&cwq->lock);
 	if (!list_empty(&work->entry)) {
#1 lore raw
Quoted 3 lines · Oleg Nesterov

Add lockdep annotations to flush_work() and update the comment.

Looks OK to me. (But probably the comment on "true" would be easier (more precise).)

Regards,
Jarek P.

Quoted 23 lines
kernel/workqueue.c renamed from kernel/workqueue.c~FW_LOCKDEP +5 -0
@@ -403,6 +403,8 @@ EXPORT_SYMBOL_GPL(flush_workqueue);
  * flush_work - block until a work_struct's callback has terminated
  * @work: the work which is to be flushed
  *
+ * Returns false if @work has already terminated.
+ *
  * It is expected that, prior to calling flush_work(), the caller has
  * arranged for the work to not be requeued, otherwise it doesn't make
  * sense to use this function.
@@ -418,6 +420,9 @@ int flush_work(struct work_struct *work)
 	if (!cwq)
 		return 0;
 
+	lock_acquire(&cwq->wq->lockdep_map, 0, 0, 0, 2, _THIS_IP_);
+	lock_release(&cwq->wq->lockdep_map, 1, _THIS_IP_);
+
 	prev = NULL;
 	spin_lock_irq(&cwq->lock);
 	if (!list_empty(&work->entry)) {