Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 165883
b: refs/heads/master
c: 4f878e8
h: refs/heads/master
i:
  165881: aa7e6a9
  165879: b2319e4
v: v3
  • Loading branch information
Chris Mason committed Sep 11, 2009
1 parent 1b4d2cf commit daefc84
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 15 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: 4e3f9c5042b43301d70781aee4a164a20878066b
refs/heads/master: 4f878e8475a465ddbd951e06a23317303f1b5b30
74 changes: 60 additions & 14 deletions trunk/fs/btrfs/async-thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,31 +196,73 @@ static int try_worker_shutdown(struct btrfs_worker_thread *worker)
return freeit;
}

static struct btrfs_work *get_next_work(struct btrfs_worker_thread *worker,
struct list_head *prio_head,
struct list_head *head)
{
struct btrfs_work *work = NULL;
struct list_head *cur = NULL;

if(!list_empty(prio_head))
cur = prio_head->next;

smp_mb();
if (!list_empty(&worker->prio_pending))
goto refill;

if (!list_empty(head))
cur = head->next;

if (cur)
goto out;

refill:
spin_lock_irq(&worker->lock);
list_splice_tail_init(&worker->prio_pending, prio_head);
list_splice_tail_init(&worker->pending, head);

if (!list_empty(prio_head))
cur = prio_head->next;
else if (!list_empty(head))
cur = head->next;
spin_unlock_irq(&worker->lock);

if (!cur)
goto out_fail;

out:
work = list_entry(cur, struct btrfs_work, list);

out_fail:
return work;
}

/*
* main loop for servicing work items
*/
static int worker_loop(void *arg)
{
struct btrfs_worker_thread *worker = arg;
struct list_head *cur;
struct list_head head;
struct list_head prio_head;
struct btrfs_work *work;

INIT_LIST_HEAD(&head);
INIT_LIST_HEAD(&prio_head);

do {
spin_lock_irq(&worker->lock);
again_locked:
again:
while (1) {
if (!list_empty(&worker->prio_pending))
cur = worker->prio_pending.next;
else if (!list_empty(&worker->pending))
cur = worker->pending.next;
else


work = get_next_work(worker, &prio_head, &head);
if (!work)
break;

work = list_entry(cur, struct btrfs_work, list);
list_del(&work->list);
clear_bit(WORK_QUEUED_BIT, &work->flags);

work->worker = worker;
spin_unlock_irq(&worker->lock);

work->func(work);

Expand All @@ -233,9 +275,11 @@ static int worker_loop(void *arg)

check_pending_worker_creates(worker);

spin_lock_irq(&worker->lock);
check_idle_worker(worker);
}

spin_lock_irq(&worker->lock);
check_idle_worker(worker);

if (freezing(current)) {
worker->working = 0;
spin_unlock_irq(&worker->lock);
Expand Down Expand Up @@ -274,8 +318,10 @@ static int worker_loop(void *arg)
spin_lock_irq(&worker->lock);
set_current_state(TASK_INTERRUPTIBLE);
if (!list_empty(&worker->pending) ||
!list_empty(&worker->prio_pending))
goto again_locked;
!list_empty(&worker->prio_pending)) {
spin_unlock_irq(&worker->lock);
goto again;
}

/*
* this makes sure we get a wakeup when someone
Expand Down

0 comments on commit daefc84

Please sign in to comment.