LOOP: fix the todo calculations.

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@redhat.com>
This commit is contained in:
Angus Salkeld 2012-02-06 22:31:55 +11:00
parent 9340221261
commit 48e7cff259
2 changed files with 15 additions and 10 deletions

View File

@ -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);
(void)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;
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);
}

View File

@ -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;