From 1f269e7bfc916f2ae852e8a7faa591af74c59f05 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Mon, 6 Feb 2012 22:31:55 +1100 Subject: [PATCH 1/3] LOOP: fix the todo calculations. Signed-off-by: Angus Salkeld --- lib/loop.c | 22 ++++++++++++---------- lib/loop_job.c | 5 ++++- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/loop.c b/lib/loop.c index 142e7eb..45ceb3f 100644 --- a/lib/loop.c +++ b/lib/loop.c @@ -26,7 +26,7 @@ #include "loop_int.h" #include "util_int.h" -static int32_t +static void qb_loop_run_level(struct qb_loop_level *level) { struct qb_loop_item *job; @@ -44,13 +44,12 @@ Ill_have_another: level->todo--; processed++; if (level->l->stop_requested) { - return processed; + return; } if (processed < level->to_process) { goto Ill_have_another; } } - return processed; } void @@ -139,20 +138,23 @@ qb_loop_run(struct qb_loop *l) if (todo > 0) { ms_timeout = 0; } else { - todo = 0; if (l->timer_source) { ms_timeout = qb_loop_timer_msec_duration_to_expire(l->timer_source); } else { ms_timeout = -1; } } - todo += l->fd_source->poll(l->fd_source, ms_timeout); - - for (p = QB_LOOP_HIGH; p >= p_stop; p--) { - todo -= qb_loop_run_level(&l->level[p]); - if (l->stop_requested) { - return; + (void)l->fd_source->poll(l->fd_source, ms_timeout); + + todo = 0; + for (p = QB_LOOP_HIGH; p >= QB_LOOP_LOW; p--) { + if (p >= p_stop) { + qb_loop_run_level(&l->level[p]); + if (l->stop_requested) { + return; + } } + todo += l->level[p].todo; } } while (!l->stop_requested); } diff --git a/lib/loop_job.c b/lib/loop_job.c index c17663d..123d1af 100644 --- a/lib/loop_job.c +++ b/lib/loop_job.c @@ -48,16 +48,19 @@ get_more_jobs(struct qb_loop_source *s, int32_t ms_timeout) { int32_t p; int32_t new_jobs = 0; + int32_t level_jobs = 0; /* * this is simple, move jobs from wait_head to job_head */ for (p = QB_LOOP_LOW; p <= QB_LOOP_HIGH; p++) { if (!qb_list_empty(&s->l->level[p].wait_head)) { - new_jobs += qb_list_length(&s->l->level[p].wait_head); + level_jobs = qb_list_length(&s->l->level[p].wait_head); + new_jobs += level_jobs; qb_list_splice(&s->l->level[p].wait_head, &s->l->level[p].job_head); qb_list_init(&s->l->level[p].wait_head); + s->l->level[p].todo += level_jobs; } } return new_jobs; -- 1.7.7.6