Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 206224
b: refs/heads/master
c: 18aa9ef
h: refs/heads/master
v: v3
  • Loading branch information
Tejun Heo committed Jun 29, 2010
1 parent bea4476 commit 2bd64f7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 7a22ad757ec75186ad43a5b4670fa7423ee8f480
refs/heads/master: 18aa9effad4adb2c1efe123af4eb24fec9f59b30
1 change: 1 addition & 0 deletions trunk/include/linux/workqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ static inline unsigned int work_static(struct work_struct *work) { return 0; }
enum {
WQ_FREEZEABLE = 1 << 0, /* freeze during suspend */
WQ_SINGLE_CPU = 1 << 1, /* only single cpu at a time */
WQ_NON_REENTRANT = 1 << 2, /* guarantee non-reentrance */
};

extern struct workqueue_struct *
Expand Down
32 changes: 29 additions & 3 deletions trunk/kernel/workqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,37 @@ static void __queue_work(unsigned int cpu, struct workqueue_struct *wq,

debug_work_activate(work);

/* determine gcwq to use */
/*
* Determine gcwq to use. SINGLE_CPU is inherently
* NON_REENTRANT, so test it first.
*/
if (!(wq->flags & WQ_SINGLE_CPU)) {
/* just use the requested cpu for multicpu workqueues */
struct global_cwq *last_gcwq;

/*
* It's multi cpu. If @wq is non-reentrant and @work
* was previously on a different cpu, it might still
* be running there, in which case the work needs to
* be queued on that cpu to guarantee non-reentrance.
*/
gcwq = get_gcwq(cpu);
spin_lock_irqsave(&gcwq->lock, flags);
if (wq->flags & WQ_NON_REENTRANT &&
(last_gcwq = get_work_gcwq(work)) && last_gcwq != gcwq) {
struct worker *worker;

spin_lock_irqsave(&last_gcwq->lock, flags);

worker = find_worker_executing_work(last_gcwq, work);

if (worker && worker->current_cwq->wq == wq)
gcwq = last_gcwq;
else {
/* meh... not running there, queue here */
spin_unlock_irqrestore(&last_gcwq->lock, flags);
spin_lock_irqsave(&gcwq->lock, flags);
}
} else
spin_lock_irqsave(&gcwq->lock, flags);
} else {
unsigned int req_cpu = cpu;

Expand Down

0 comments on commit 2bd64f7

Please sign in to comment.