Permalink
Browse files

iv_task: Implement fairness by list splicing.

When iv_run_tasks() is called, we want it to only process tasks that
were registered before the function was called.  This is currently
done by inserting a sentinel element, but it's easier to just move
all tasks to a local list on entry to the function and then work off
the local list.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
  • Loading branch information...
1 parent 6682057 commit c82b287ed10e362b7cd4cdc91ad2f1bab28d2929 @buytenh buytenh committed Jun 11, 2012
Showing with 4 additions and 8 deletions.
  1. +4 −8 lib/iv_task.c
View
@@ -34,21 +34,17 @@ int iv_pending_tasks(struct iv_state *st)
void iv_run_tasks(struct iv_state *st)
{
- struct iv_list_head last;
+ struct iv_list_head tasks;
- if (iv_list_empty(&st->tasks))
- return;
-
- iv_list_add_tail(&last, &st->tasks);
- while (st->tasks.next != &last) {
+ __iv_list_steal_elements(&st->tasks, &tasks);
+ while (!iv_list_empty(&tasks)) {
struct iv_task_ *t;
- t = iv_list_entry(st->tasks.next, struct iv_task_, list);
+ t = iv_list_entry(tasks.next, struct iv_task_, list);
iv_list_del_init(&t->list);
t->handler(t->cookie);
}
- iv_list_del(&last);
}
void IV_TASK_INIT(struct iv_task *_t)

0 comments on commit c82b287

Please sign in to comment.