The todo system was sucky as it was calculated in different
places in the mainloop and at each level. This was exposed by
calls to qb_loop_level_item_del() which decremented the level->todo
but not the mainloop one. So now we re-calculate it each time.
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
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 c0f6f33..3e10b89 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
@@ -156,20 +155,23 @@ qb_loop_run(struct qb_loop *l)
*/
ms_timeout = 50;
} 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