Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 105947
b: refs/heads/master
c: db70089
h: refs/heads/master
i:
  105945: de03745
  105943: f7deec4
v: v3
  • Loading branch information
Oleg Nesterov authored and Linus Torvalds committed Jul 25, 2008
1 parent 347eb70 commit 98e7a69
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1a4d9b0aa0d3c50314e57525a5e5ec2cfc48b4c8
refs/heads/master: db700897224b5ebdf852f2d38920ce428940d059
2 changes: 2 additions & 0 deletions trunk/include/linux/workqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ extern int keventd_up(void);
extern void init_workqueues(void);
int execute_in_process_context(work_func_t fn, struct execute_work *);

extern int flush_work(struct work_struct *work);

extern int cancel_work_sync(struct work_struct *work);

/*
Expand Down
46 changes: 46 additions & 0 deletions trunk/kernel/workqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,52 @@ void flush_workqueue(struct workqueue_struct *wq)
}
EXPORT_SYMBOL_GPL(flush_workqueue);

/**
* flush_work - block until a work_struct's callback has terminated
* @work: the work which is to be flushed
*
* 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.
*/
int flush_work(struct work_struct *work)
{
struct cpu_workqueue_struct *cwq;
struct list_head *prev;
struct wq_barrier barr;

might_sleep();
cwq = get_wq_data(work);
if (!cwq)
return 0;

prev = NULL;
spin_lock_irq(&cwq->lock);
if (!list_empty(&work->entry)) {
/*
* See the comment near try_to_grab_pending()->smp_rmb().
* If it was re-queued under us we are not going to wait.
*/
smp_rmb();
if (unlikely(cwq != get_wq_data(work)))
goto out;
prev = &work->entry;
} else {
if (cwq->current_work != work)
goto out;
prev = &cwq->worklist;
}
insert_wq_barrier(cwq, &barr, prev->next);
out:
spin_unlock_irq(&cwq->lock);
if (!prev)
return 0;

wait_for_completion(&barr.done);
return 1;
}
EXPORT_SYMBOL_GPL(flush_work);

/*
* Upon a successful return (>= 0), the caller "owns" WORK_STRUCT_PENDING bit,
* so this work can't be re-armed in any way.
Expand Down

0 comments on commit 98e7a69

Please sign in to comment.